Overview
BERA Balance
BERA Value
$0.00More Info
Private Name Tags
ContractCreator
Loading...
Loading
Contract Name:
KodiakIslandWithRouter
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 100 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0 pragma solidity =0.8.19; import {SwapData} from "./interfaces/IKodiakIslandWithRouter.sol"; import "./KodiakIsland.sol"; contract KodiakIslandWithRouter is KodiakIsland { using FullMath for uint256; using SafeERC20 for IERC20; using TickMath for int24; mapping(address => bool) public swapRouter; event RouterSet(address indexed router, bool status); // ******************************************** Manager Functions ******************************************************* /// @notice allows manager to add / remove routers, can do while paused /// @param _router address that can be used for rebalance /// @param _status true to add, false to remove function setRouter(address _router, bool _status) external onlyManager { require(_router != address(0), "Zero address"); swapRouter[_router] = _status; emit RouterSet(_router, _status); } /// @notice Similar to executiveRebalance, but uses whitelisted router to facilitate swaps /// @param newLowerTick The new lower bound of the position's range /// @param newUpperTick The new upper bound of the position's range /// @param swapData swap information including: router address, amountIn, amountOutMin, zeroForOne, routeData function executiveRebalanceWithRouter(int24 newLowerTick, int24 newUpperTick, SwapData calldata swapData) external whenNotPaused onlyManager { require(swapRouter[swapData.router], "Unauthorized router"); { uint256 worstOut = worstAmountOut(swapData.amountIn, compounderSlippageBPS, getAvgPrice(compounderSlippageInterval), swapData.zeroForOne); require(swapData.minAmountOut > worstOut, "Set reasonable minAmountOut"); } uint128 liquidity; uint128 newLiquidity; if (totalSupply() > 0) { (liquidity,,,,) = pool.positions(_getPositionID()); if (liquidity > 0) { (,, uint256 fee0, uint256 fee1) = _withdraw(lowerTick, upperTick, liquidity); _applyFees(fee0, fee1); } lowerTick = newLowerTick; upperTick = newUpperTick; uint256 reinvest0 = token0.balanceOf(address(this)) - managerBalance0; uint256 reinvest1 = token1.balanceOf(address(this)) - managerBalance1; _depositWithRouter(newLowerTick, newUpperTick, reinvest0, reinvest1, swapData); (newLiquidity,,,,) = pool.positions(_getPositionID()); require(newLiquidity > 0, "new position 0"); } else { lowerTick = newLowerTick; upperTick = newUpperTick; } emit Rebalance(msg.sender, newLowerTick, newUpperTick, liquidity, newLiquidity); } // ******************************************** View Functions ******************************************************* function worstAmountOut(uint256 amountIn, uint16 slippageBPS, uint160 avgSqrtPriceX96, bool zeroForOne) public pure returns (uint256) { require(slippageBPS <= 10000, "Invalid slippage"); // Calculate slippage adjustment to the sqrtPriceX96 uint256 slippage = uint256(avgSqrtPriceX96) * slippageBPS / 10000; uint256 sqrtX96 = zeroForOne ? avgSqrtPriceX96 - slippage : avgSqrtPriceX96 + slippage; if (sqrtX96 == 0) { return 0; } //Somewhat hacky to avoid overflow issues if (zeroForOne) { if (sqrtX96 < 2 ** 128 - 1) { return amountIn.mulDiv(sqrtX96 ** 2, Q96 ** 2); } else { return amountIn.mulDiv(sqrtX96, Q96).mulDiv(sqrtX96, Q96); } } else { if (sqrtX96 < 2 ** 128 - 1) { return amountIn.mulDiv(Q96 ** 2, sqrtX96 ** 2); } else { return amountIn.mulDiv(Q96, 1e18).mulDiv(Q96, sqrtX96).mulDiv(1e18, sqrtX96); } } } /// @notice get the twap price of the underlying for the specified interval (in seconds) function getAvgPrice(uint32 interval) public view returns (uint160 avgSqrtPriceX96) { require(interval > 0, "Invalid interval"); uint32[] memory secondsAgo = new uint32[](2); secondsAgo[0] = interval; secondsAgo[1] = 0; (int56[] memory tickCumulatives,) = pool.observe(secondsAgo); require(tickCumulatives.length == 2, "array len"); unchecked { int24 avgTick = int24((tickCumulatives[1] - tickCumulatives[0]) / int56(uint56(interval))); avgSqrtPriceX96 = avgTick.getSqrtRatioAtTick(); } } // ******************************************** Internal Functions ******************************************************* function _depositWithRouter(int24 lowerTick_, int24 upperTick_, uint256 amount0, uint256 amount1, SwapData calldata swapData) private { // First, deposit as much as we can (amount0, amount1) = _mintMaxLiquidity(lowerTick_, upperTick_, amount0, amount1); if (swapData.amountIn > 0) { require(swapData.amountIn <= (swapData.zeroForOne ? amount0 : amount1), "Swap amount too big"); (amount0, amount1) = _swapWithRouter(amount0, amount1, swapData); //Add liquidity a second time _mintMaxLiquidity(lowerTick_, upperTick_, amount0, amount1); } } /// @dev assumes that the router whitelist check has already passed. /// Swap using one of the approved routers. /// Returns the new token0 and token1 amounts in possession after the swap. function _swapWithRouter(uint256 amount0, uint256 amount1, SwapData calldata swapData) internal returns (uint256 finalAmount0, uint256 finalAmount1) { IERC20 tokenIn = swapData.zeroForOne ? token0 : token1; IERC20 tokenOut = swapData.zeroForOne ? token1 : token0; // Capture initial balances uint256 balanceIn = tokenIn.balanceOf(address(this)); uint256 balanceOut = tokenOut.balanceOf(address(this)); // Approve and perform swap tokenIn.safeIncreaseAllowance(swapData.router, swapData.amountIn); (bool success,) = swapData.router.call(swapData.routeData); require(success, "swap failed"); // Calculate balance changes and ensure minimum output uint256 deltaIn = balanceIn - tokenIn.balanceOf(address(this)); uint256 deltaOut = tokenOut.balanceOf(address(this)) - balanceOut; require(deltaOut >= swapData.minAmountOut, "insufficient tokenOut"); // Set final amounts based on swap direction if (swapData.zeroForOne) { finalAmount0 = amount0 - deltaIn; finalAmount1 = amount1 + deltaOut; } else { finalAmount0 = amount0 + deltaOut; finalAmount1 = amount1 - deltaIn; } } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity =0.8.19; import {IKodiakIsland} from "./IKodiakIsland.sol"; struct SwapData { address router; uint256 amountIn; uint256 minAmountOut; bool zeroForOne; bytes routeData; } interface IKodiakIslandWithRouter is IKodiakIsland { // Manager Functions function setRouter(address swapRouter, bool enabled) external; function executiveRebalanceWithRouter(int24 newLowerTick, int24 newUpperTick, SwapData calldata swapData) external; // View Functions function swapRouter(address router) external view returns (bool); function worstAmountOut(uint256 amountIn, uint16 slippageBPS, uint160 avgSqrtPriceX96, bool zeroForOne) external pure returns (uint256); function getAvgPrice(uint32 interval) external view returns (uint160 avgSqrtPriceX96); }
// SPDX-License-Identifier: GPL-3.0 // // =========================== Kodiak Island ============================= // ======================================================================= // Modified from Arrakis (https://github.com/ArrakisFinance/vault-v1-core) // Built for the Beras // ======================================================================= pragma solidity =0.8.19; import {IUniswapV3MintCallback} from "./interfaces/IUniswapV3MintCallback.sol"; import {IUniswapV3SwapCallback} from "./interfaces/IUniswapV3SwapCallback.sol"; import {KodiakIslandStorage} from "./abstract/KodiakIslandStorage.sol"; import {TickMath} from "./vendor/uniswap/TickMath.sol"; import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import {FullMath, LiquidityAmounts} from "./vendor/uniswap/LiquidityAmounts.sol"; abstract contract KodiakIsland is IUniswapV3MintCallback, IUniswapV3SwapCallback, KodiakIslandStorage { using SafeERC20 for IERC20; using TickMath for int24; 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(address indexed compounder, int24 lowerTick_, int24 upperTick_, uint128 liquidityBefore, uint128 liquidityAfter); event FeesEarned(uint256 feesEarned0, uint256 feesEarned1); /// @notice Uniswap V3 callback fn, called back on pool.mint function uniswapV3MintCallback(uint256 amount0Owed, uint256 amount1Owed, bytes calldata /*_data*/ ) external override { require(msg.sender == address(pool), "callback caller"); if (amount0Owed > 0) token0.safeTransfer(msg.sender, amount0Owed); if (amount1Owed > 0) token1.safeTransfer(msg.sender, amount1Owed); } /// @notice Uniswap v3 callback fn, called back on pool.swap function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata /*data*/ ) external override { require(msg.sender == address(pool), "callback caller"); if (amount0Delta > 0) { token0.safeTransfer(msg.sender, uint256(amount0Delta)); } else if (amount1Delta > 0) { token1.safeTransfer(msg.sender, uint256(amount1Delta)); } } // User functions => Should be called via a Router /// @notice mint KodiakIsland tokens, fractional shares of a Uniswap V3 position/strategy /// @dev to compute the amouint of tokens necessary to mint `mintAmount` see getMintAmounts /// @param mintAmount The number of shares to mint /// @param receiver The account to receive the minted shares /// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount` /// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount` /// @return liquidityMinted amount of liquidity added to the underlying Uniswap V3 position function mint(uint256 mintAmount, address receiver) external whenNotPaused nonReentrant returns (uint256 amount0, uint256 amount1, uint128 liquidityMinted) { require(!restrictedMint || msg.sender == _manager || !isManaged(), "restricted"); uint256 totalSupply = totalSupply(); (uint160 sqrtRatioX96,,,,,,) = pool.slot0(); if (totalSupply > 0) { require(mintAmount > 0, "mint 0"); (uint256 amount0Current, uint256 amount1Current) = getUnderlyingBalances(); amount0 = FullMath.mulDivRoundingUp(amount0Current, mintAmount, totalSupply); amount1 = FullMath.mulDivRoundingUp(amount1Current, mintAmount, totalSupply); } else { // if supply is 0 mintAmount == liquidity to deposit (amount0, amount1) = LiquidityAmounts.getAmountsForLiquidity(sqrtRatioX96, lowerTick.getSqrtRatioAtTick(), upperTick.getSqrtRatioAtTick(), SafeCast.toUint128(mintAmount)); _mint(address(0), INITIAL_MINT); // Solution to this issue: https://github.com/transmissions11/solmate/issues/178 mintAmount = mintAmount - INITIAL_MINT; } // transfer amounts owed to contract if (amount0 > 0) { token0.safeTransferFrom(msg.sender, address(this), amount0); } if (amount1 > 0) { token1.safeTransferFrom(msg.sender, address(this), amount1); } // deposit as much new liquidity as possible liquidityMinted = LiquidityAmounts.getLiquidityForAmounts(sqrtRatioX96, lowerTick.getSqrtRatioAtTick(), upperTick.getSqrtRatioAtTick(), amount0, amount1); pool.mint(address(this), lowerTick, upperTick, liquidityMinted, ""); _mint(receiver, mintAmount); emit Minted(receiver, mintAmount, amount0, amount1, liquidityMinted); } /// @notice burn KodiakIsland tokens (shares of a Uniswap V3 position) and receive underlying /// @param burnAmount The number of shares to burn /// @param receiver The account to receive the underlying amounts of token0 and token1 /// @return amount0 amount of token0 transferred to receiver for burning `burnAmount` /// @return amount1 amount of token1 transferred to receiver for burning `burnAmount` /// @return liquidityBurned amount of liquidity removed from the underlying Uniswap V3 position function burn(uint256 burnAmount, address receiver) external whenNotPaused nonReentrant returns (uint256 amount0, uint256 amount1, uint128 liquidityBurned) { require(burnAmount > 0, "burn 0"); uint256 totalSupply = totalSupply(); (uint128 liquidity,,,,) = pool.positions(_getPositionID()); _burn(msg.sender, burnAmount); uint256 liquidityBurned_ = FullMath.mulDiv(burnAmount, liquidity, totalSupply); liquidityBurned = SafeCast.toUint128(liquidityBurned_); (uint256 burn0, uint256 burn1, uint256 fee0, uint256 fee1) = _withdraw(lowerTick, upperTick, liquidityBurned); _applyFees(fee0, fee1); amount0 = burn0 + FullMath.mulDiv(token0.balanceOf(address(this)) - burn0 - managerBalance0, burnAmount, totalSupply); amount1 = burn1 + FullMath.mulDiv(token1.balanceOf(address(this)) - burn1 - managerBalance1, burnAmount, totalSupply); if (amount0 > 0) { token0.safeTransfer(receiver, amount0); } if (amount1 > 0) { token1.safeTransfer(receiver, amount1); } emit Burned(receiver, burnAmount, amount0, amount1, liquidityBurned); } // Manager Functions => Called by Island Manager /// @notice Change the range of underlying UniswapV3 position, only manager can call /// @dev When changing the range the inventory of token0 and token1 may be rebalanced /// with a swap to deposit as much liquidity as possible into the new position. Swap parameters /// can be computed by simulating the whole operation: remove all liquidity, deposit as much /// as possible into new position, then observe how much of token0 or token1 is leftover. /// Swap a proportion of this leftover to deposit more liquidity into the position, since /// any leftover will be unused and sit idle until the next rebalance. /// @param newLowerTick The new lower bound of the position's range /// @param newUpperTick The new upper bound of the position's range /// @param swapThresholdPrice slippage parameter on the swap as a max or min sqrtPriceX96 /// @param swapAmountBPS amount of token to swap as proportion of total. Pass 0 to ignore swap. /// @param zeroForOne Which token to input into the swap (true = token0, false = token1) function executiveRebalance(int24 newLowerTick, int24 newUpperTick, uint160 swapThresholdPrice, uint256 swapAmountBPS, bool zeroForOne) external whenNotPaused onlyManager { uint128 liquidity; uint128 newLiquidity; if (totalSupply() > 0) { (liquidity,,,,) = pool.positions(_getPositionID()); if (liquidity > 0) { (,, uint256 fee0, uint256 fee1) = _withdraw(lowerTick, upperTick, liquidity); _applyFees(fee0, fee1); } lowerTick = newLowerTick; upperTick = newUpperTick; uint256 reinvest0 = token0.balanceOf(address(this)) - managerBalance0; uint256 reinvest1 = token1.balanceOf(address(this)) - managerBalance1; _deposit(newLowerTick, newUpperTick, reinvest0, reinvest1, swapThresholdPrice, swapAmountBPS, zeroForOne); (newLiquidity,,,,) = pool.positions(_getPositionID()); require(newLiquidity > 0, "new position 0"); } else { lowerTick = newLowerTick; upperTick = newUpperTick; } emit Rebalance(msg.sender, newLowerTick, newUpperTick, liquidity, newLiquidity); } // CompounderOrAbove functions => Limited-scope automated functions /// @notice Reinvest fees earned into underlying position, anyone call /// Position bounds CANNOT be altered, and no swaps occur (fee balance can remain idle) function rebalance() external whenNotPaused { (uint128 liquidity,,,,) = pool.positions(_getPositionID()); _rebalance(); (uint128 newLiquidity,,,,) = pool.positions(_getPositionID()); require(newLiquidity > liquidity, "liquidity must increase"); emit Rebalance(msg.sender, lowerTick, upperTick, liquidity, newLiquidity); } /// @notice withdraw manager fees accrued function withdrawManagerBalance() external { uint256 amount0 = managerBalance0; uint256 amount1 = managerBalance1; managerBalance0 = 0; managerBalance1 = 0; if (amount0 > 0) { token0.safeTransfer(managerTreasury, amount0); } if (amount1 > 0) { token1.safeTransfer(managerTreasury, amount1); } } // View functions /// @notice compute maximum shares that can be minted from `amount0Max` and `amount1Max` /// @param amount0Max The maximum amount of token0 to forward on mint /// @param amount0Max The maximum amount of token1 to forward on mint /// @return amount0 actual amount of token0 to forward when minting `mintAmount` /// @return amount1 actual amount of token1 to forward when minting `mintAmount` /// @return mintAmount maximum number of shares mintable function getMintAmounts(uint256 amount0Max, uint256 amount1Max) external view returns (uint256 amount0, uint256 amount1, uint256 mintAmount) { uint256 totalSupply = totalSupply(); if (totalSupply > 0) { (amount0, amount1, mintAmount) = _computeMintAmounts(totalSupply, amount0Max, amount1Max); } else { (uint160 sqrtRatioX96,,,,,,) = pool.slot0(); uint128 newLiquidity = LiquidityAmounts.getLiquidityForAmounts(sqrtRatioX96, lowerTick.getSqrtRatioAtTick(), upperTick.getSqrtRatioAtTick(), amount0Max, amount1Max); mintAmount = uint256(newLiquidity); (amount0, amount1) = LiquidityAmounts.getAmountsForLiquidity(sqrtRatioX96, lowerTick.getSqrtRatioAtTick(), upperTick.getSqrtRatioAtTick(), newLiquidity); } } /// @notice compute total underlying holdings of the island token supply /// includes current liquidity invested in uniswap position, current fees earned /// and any uninvested leftover (but does not include manager fees accrued) /// @return amount0Current current total underlying balance of token0 /// @return amount1Current current total underlying balance of token1 function getUnderlyingBalances() public view returns (uint256 amount0Current, uint256 amount1Current) { (uint160 sqrtRatioX96, int24 tick,,,,,) = pool.slot0(); return _getUnderlyingBalances(sqrtRatioX96, tick); } function getUnderlyingBalancesAtPrice(uint160 sqrtRatioX96) external view returns (uint256 amount0Current, uint256 amount1Current) { (, int24 tick,,,,,) = pool.slot0(); return _getUnderlyingBalances(sqrtRatioX96, tick); } function _getUnderlyingBalances(uint160 sqrtRatioX96, int24 tick) internal view returns (uint256 amount0Current, uint256 amount1Current) { (uint128 liquidity, uint256 feeGrowthInside0Last, uint256 feeGrowthInside1Last, uint128 tokensOwed0, uint128 tokensOwed1) = pool.positions(_getPositionID()); // compute current holdings from liquidity (amount0Current, amount1Current) = LiquidityAmounts.getAmountsForLiquidity(sqrtRatioX96, lowerTick.getSqrtRatioAtTick(), upperTick.getSqrtRatioAtTick(), liquidity); // compute current fees earned uint256 fee0 = _computeFeesEarned(true, feeGrowthInside0Last, tick, liquidity) + uint256(tokensOwed0); uint256 fee1 = _computeFeesEarned(false, feeGrowthInside1Last, tick, liquidity) + uint256(tokensOwed1); (fee0, fee1) = _subtractManagerFee(fee0, fee1, managerFeeBPS); // add any leftover in contract to current holdings amount0Current += fee0 + token0.balanceOf(address(this)) - managerBalance0; amount1Current += fee1 + token1.balanceOf(address(this)) - managerBalance1; } // Private functions function _rebalance() private { (int24 _lowerTick, int24 _upperTick) = (lowerTick, upperTick); (,, uint256 fee0, uint256 fee1) = _withdraw(_lowerTick, _upperTick, 0); //withdraw of 0 since range is the same _applyFees(fee0, fee1); uint256 reinvest0 = token0.balanceOf(address(this)) - managerBalance0; uint256 reinvest1 = token1.balanceOf(address(this)) - managerBalance1; _mintMaxLiquidity(_lowerTick, _upperTick, reinvest0, reinvest1); } function _withdraw(int24 lowerTick_, int24 upperTick_, uint128 liquidity) internal returns (uint256 burn0, uint256 burn1, uint256 fee0, uint256 fee1) { (burn0, burn1) = pool.burn(lowerTick_, upperTick_, liquidity); (uint128 collected0, uint128 collected1) = pool.collect(address(this), lowerTick_, upperTick_, type(uint128).max, type(uint128).max); fee0 = uint256(collected0) - burn0; fee1 = uint256(collected1) - burn1; } function _deposit(int24 lowerTick_, int24 upperTick_, uint256 amount0, uint256 amount1, uint160 swapThresholdPrice, uint256 swapAmountBPS, bool zeroForOne) private { // First, deposit as much as we can (amount0, amount1) = _mintMaxLiquidity(lowerTick_, upperTick_, amount0, amount1); int256 swapAmount = SafeCast.toInt256(((zeroForOne ? amount0 : amount1) * swapAmountBPS) / 10000); if (swapAmount > 0) { (amount0, amount1) = _swap(amount0, amount1, swapAmount, swapThresholdPrice, zeroForOne); //Add liquidity a second time _mintMaxLiquidity(lowerTick_, upperTick_, amount0, amount1); } } function _swap(uint256 amount0, uint256 amount1, int256 swapAmount, uint160 swapThresholdPrice, bool zeroForOne) private returns (uint256 finalAmount0, uint256 finalAmount1) { (int256 amount0Delta, int256 amount1Delta) = pool.swap(address(this), zeroForOne, swapAmount, swapThresholdPrice, ""); finalAmount0 = uint256(SafeCast.toInt256(amount0) - amount0Delta); finalAmount1 = uint256(SafeCast.toInt256(amount1) - amount1Delta); } function _mintMaxLiquidity(int24 lowerTick_, int24 upperTick_, uint256 maxAmount0, uint256 maxAmount1) internal returns (uint256 amount0, uint256 amount1) { (uint160 sqrtRatioX96,,,,,,) = pool.slot0(); uint128 liquidityMinted = LiquidityAmounts.getLiquidityForAmounts(sqrtRatioX96, lowerTick_.getSqrtRatioAtTick(), upperTick_.getSqrtRatioAtTick(), maxAmount0, maxAmount1); if (liquidityMinted > 0) { (uint256 deposited0, uint256 deposited1) = pool.mint(address(this), lowerTick_, upperTick_, liquidityMinted, ""); amount0 = maxAmount0 - deposited0; amount1 = maxAmount1 - deposited1; } } function _computeMintAmounts(uint256 totalSupply, uint256 amount0Max, uint256 amount1Max) private view returns (uint256 amount0, uint256 amount1, uint256 mintAmount) { (uint256 amount0Current, uint256 amount1Current) = getUnderlyingBalances(); // compute proportional amount of tokens to mint if (amount0Current == 0 && amount1Current > 0) { mintAmount = FullMath.mulDiv(amount1Max, totalSupply, amount1Current); } else if (amount1Current == 0 && amount0Current > 0) { mintAmount = FullMath.mulDiv(amount0Max, totalSupply, amount0Current); } else if (amount0Current == 0 && amount1Current == 0) { revert(""); } else { // only if both are non-zero uint256 amount0Mint = FullMath.mulDiv(amount0Max, totalSupply, amount0Current); uint256 amount1Mint = FullMath.mulDiv(amount1Max, totalSupply, amount1Current); require(amount0Mint > 0 && amount1Mint > 0, "mint 0"); mintAmount = amount0Mint < amount1Mint ? amount0Mint : amount1Mint; } // compute amounts owed to contract amount0 = FullMath.mulDivRoundingUp(mintAmount, amount0Current, totalSupply); amount1 = FullMath.mulDivRoundingUp(mintAmount, amount1Current, totalSupply); } function _computeFeesEarned(bool isZero, uint256 feeGrowthInsideLast, int24 tick, uint128 liquidity) private view returns (uint256 fee) { uint256 feeGrowthOutsideLower; uint256 feeGrowthOutsideUpper; uint256 feeGrowthGlobal; if (isZero) { feeGrowthGlobal = pool.feeGrowthGlobal0X128(); (,, feeGrowthOutsideLower,,,,,) = pool.ticks(lowerTick); (,, feeGrowthOutsideUpper,,,,,) = pool.ticks(upperTick); } else { feeGrowthGlobal = pool.feeGrowthGlobal1X128(); (,,, feeGrowthOutsideLower,,,,) = pool.ticks(lowerTick); (,,, feeGrowthOutsideUpper,,,,) = pool.ticks(upperTick); } unchecked { // calculate fee growth below uint256 feeGrowthBelow; if (tick >= lowerTick) { feeGrowthBelow = feeGrowthOutsideLower; } else { feeGrowthBelow = feeGrowthGlobal - feeGrowthOutsideLower; } // calculate fee growth above uint256 feeGrowthAbove; if (tick < upperTick) { feeGrowthAbove = feeGrowthOutsideUpper; } else { feeGrowthAbove = feeGrowthGlobal - feeGrowthOutsideUpper; } uint256 feeGrowthInside = feeGrowthGlobal - feeGrowthBelow - feeGrowthAbove; fee = FullMath.mulDiv(liquidity, feeGrowthInside - feeGrowthInsideLast, 0x100000000000000000000000000000000); } } function _applyFees(uint256 _fee0, uint256 _fee1) internal { uint16 _managerFeeBPS = managerFeeBPS; if (managerFeeBPS > 0) { managerBalance0 += _fee0 * _managerFeeBPS / 10000; managerBalance1 += _fee1 * _managerFeeBPS / 10000; (uint256 fee0, uint256 fee1) = _subtractManagerFee(_fee0, _fee1, _managerFeeBPS); emit FeesEarned(fee0, fee1); } else { emit FeesEarned(_fee0, _fee1); } } function _subtractManagerFee(uint256 _fee0, uint256 _fee1, uint16 _managerFeeBPS) internal pure returns (uint256 fee0, uint256 fee1) { fee0 = _fee0 - _fee0 * _managerFeeBPS / 10000; fee1 = _fee1 - _fee1 * _managerFeeBPS / 10000; } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity =0.8.19; import {IUniswapV3MintCallback} from "./IUniswapV3MintCallback.sol"; import {IUniswapV3SwapCallback} from "./IUniswapV3SwapCallback.sol"; import {IUniswapV3Pool} from "./IUniswapV3Pool.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IKodiakIsland is IUniswapV3MintCallback, IUniswapV3SwapCallback { 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(address indexed compounder, int24 lowerTick_, int24 upperTick_, uint128 liquidityBefore, uint128 liquidityAfter); event FeesEarned(uint256 feesEarned0, uint256 feesEarned1); // User functions function mint(uint256 mintAmount, address receiver) external returns (uint256 amount0, uint256 amount1, uint128 liquidityMinted); event UpdateManagerParams(uint16 managerFeeBPS, address managerTreasury, uint16 compounderSlippageBPS, uint32 compounderSlippageInterval); event PauserSet(address indexed pauser, bool status); event RestrictedMintSet(bool status); function burn(uint256 burnAmount, address receiver) external returns (uint256 amount0, uint256 amount1, uint128 liquidityBurned); function updateManagerParams(int16 newManagerFeeBPS, address newManagerTreasury, int16 newSlippageBPS, int32 newSlippageInterval) external; function setRestrictedMint(bool enabled) external; function setPauser(address _pauser, bool enabled) external; function pause() external; function unpause() external; function renounceOwnership() external; function transferOwnership(address newOwner) external; // Additional view functions that might be useful to expose: function managerBalance0() external view returns (uint256); function managerBalance1() external view returns (uint256); function managerTreasury() external view returns (address); function getUnderlyingBalancesAtPrice(uint160 sqrtRatioX96) external view returns (uint256 amount0Current, uint256 amount1Current); function manager() external view returns (address); function getMintAmounts(uint256 amount0Max, uint256 amount1Max) external view returns (uint256 amount0, uint256 amount1, uint256 mintAmount); function getUnderlyingBalances() external view returns (uint256 amount0, uint256 amount1); function getPositionID() external view returns (bytes32 positionID); function token0() external view returns (IERC20); function token1() external view returns (IERC20); function upperTick() external view returns (int24); function lowerTick() external view returns (int24); function pool() external view returns (IUniswapV3Pool); function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function managerFeeBPS() external view returns (uint16); function withdrawManagerBalance() external; function executiveRebalance(int24 newLowerTick, int24 newUpperTick, uint160 swapThresholdPrice, uint256 swapAmountBPS, bool zeroForOne) external; function rebalance() external; function initialize(string memory _name, string memory _symbol, address _pool, uint16 _managerFeeBPS, int24 _lowerTick, int24 _upperTick, address _manager_) external; function compounderSlippageInterval() external view returns (uint32); function compounderSlippageBPS() external view returns (uint16); function restrictedMint() external view returns (bool); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.8.19; /// @title Callback for IUniswapV3PoolActions#mint /// @notice Any contract that calls IUniswapV3PoolActions#mint must implement this interface interface IUniswapV3MintCallback { /// @notice Called to `msg.sender` after minting liquidity to a position from IUniswapV3Pool#mint. /// @dev In the implementation you must pay the pool tokens owed for the minted liquidity. /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory. /// @param amount0Owed The amount of token0 due to the pool for the minted liquidity /// @param amount1Owed The amount of token1 due to the pool for the minted liquidity /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#mint call function uniswapV3MintCallback( uint256 amount0Owed, uint256 amount1Owed, bytes calldata data ) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.8.19; /// @title Callback for IUniswapV3PoolActions#swap /// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface interface IUniswapV3SwapCallback { /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap. /// @dev In the implementation you must pay the pool tokens owed for the swap. /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory. /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped. /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token0 to the pool. /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token1 to the pool. /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call function uniswapV3SwapCallback( int256 amount0Delta, int256 amount1Delta, bytes calldata data ) external; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity =0.8.19; import {OwnableUninitialized} from "./OwnableUninitialized.sol"; import {ERC20} from "lib/solady/src/tokens/ERC20.sol"; import {IUniswapV3Pool} from "../interfaces/IUniswapV3Pool.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {ReentrancyGuard} from "lib/solady/src/utils/ReentrancyGuard.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; import {IKodiakIslandFactory} from "../interfaces/IKodiakIslandFactory.sol"; abstract contract KodiakIslandStorage is ERC20, ReentrancyGuard, OwnableUninitialized, Pausable { string public constant version = "1.0.0"; uint256 internal constant Q96 = 1 << 96; uint256 internal constant INITIAL_MINT = 1e3; string private _islandName; string private _islandSymbol; bool public restrictedMint; int24 public lowerTick; int24 public upperTick; uint16 public compounderSlippageBPS; uint32 public compounderSlippageInterval; uint16 public managerFeeBPS; address public managerTreasury; IKodiakIslandFactory public islandFactory; uint256 public managerBalance0; uint256 public managerBalance1; IUniswapV3Pool public pool; IERC20 public token0; IERC20 public token1; mapping(address => bool) public pauser; event UpdateManagerParams(uint16 managerFeeBPS, address managerTreasury, uint16 compounderSlippageBPS, uint32 compounderSlippageInterval); event PauserSet(address indexed pauser, bool status); event RestrictedMintSet(bool status); modifier onlyPauserOrAbove() { require(pauser[msg.sender] || msg.sender == _manager, "Ownable: caller is not the pauser"); _; } function name() public view override returns (string memory) { return _islandName; } function symbol() public view override returns (string memory) { return _islandSymbol; } /// @notice initialize storage variables on a new pool, only called once /// @param _name name of Vault (immutable) /// @param _symbol symbol of Vault (immutable) /// @param _pool address of Uniswap V3 pool (immutable) /// @param _managerFeeBPS proportion of fees earned that go to manager treasury /// @param _lowerTick initial lowerTick (only changeable with executiveRebalance) /// @param _lowerTick initial upperTick (only changeable with executiveRebalance) /// @param _manager_ address of manager (ownership can be transferred) function initialize( string memory _name, string memory _symbol, address _pool, uint16 _managerFeeBPS, int24 _lowerTick, int24 _upperTick, address _manager_, address _managerTreasury ) external { require(address(pool) == address(0), "KodiakIslandStorage: already initialized"); require(_managerFeeBPS <= 10000, "managerFeeBps over max"); // these variables are immutable after initialization islandFactory = IKodiakIslandFactory(msg.sender); pool = IUniswapV3Pool(_pool); token0 = IERC20(pool.token0()); token1 = IERC20(pool.token1()); // these variables can be updated by the manager, // If manager is address(0), these are immutable _manager = _manager_; managerTreasury = _managerTreasury; managerFeeBPS = _managerFeeBPS; compounderSlippageInterval = 5 minutes; // default: last five minutes; compounderSlippageBPS = 500; // default: 5% slippage lowerTick = _lowerTick; upperTick = _upperTick; _islandName = _name; _islandSymbol = _symbol; syncToFactory(); } /// @notice change configurable gelato parameters, only manager can call /// @param newManagerFeeBPS Basis Points of fees earned credited to manager (negative to ignore) /// @param newManagerTreasury address that collects manager fees (Zero address to ignore) /// @param newSlippageBPS frontrun protection parameter (negative to ignore) /// @param newSlippageInterval frontrun protection parameter (negative to ignore) function updateManagerParams(int16 newManagerFeeBPS, address newManagerTreasury, int16 newSlippageBPS, int32 newSlippageInterval) external onlyManager { require(newSlippageBPS <= 10000, "BPS"); require(newManagerFeeBPS <= 10000, "managerFeeBps over max"); if (newManagerFeeBPS >= 0) managerFeeBPS = uint16(newManagerFeeBPS); if (address(0) != newManagerTreasury) managerTreasury = newManagerTreasury; if (newSlippageBPS >= 0) compounderSlippageBPS = uint16(newSlippageBPS); if (newSlippageInterval >= 0) compounderSlippageInterval = uint32(newSlippageInterval); emit UpdateManagerParams(managerFeeBPS, managerTreasury, compounderSlippageBPS, compounderSlippageInterval); } /// @notice returns whether the island has a manager function isManaged() public view returns (bool) { return _manager != address(0); } /// @notice allows manager to restrict minting to only the manager /// @param _status true to allow only manager, false to allow everyone function setRestrictedMint(bool _status) external onlyManager { restrictedMint = _status; emit RestrictedMintSet(_status); } /// @notice Triggers paused state. function pause() external onlyPauserOrAbove { require(address(_manager) != address(0), "Pausable: cannot pause without a valid manager"); _pause(); } /// @notice Returns to normal state. function unpause() external onlyManager { _unpause(); } /// @notice allows manager to add / remove pausers, can do while paused /// @param _pauser address that can pause the vault (but not unpause) /// @param _status true to add, false to remove function setPauser(address _pauser, bool _status) external onlyManager { require(_pauser != address(0), "Zero address"); pauser[_pauser] = _status; emit PauserSet(_pauser, _status); } /// @notice Can only renounce when not paused (otherwise can't unpause) /// @dev Leaves the contract without manager. function renounceOwnership() external whenNotPaused onlyManager { managerTreasury = islandFactory.treasury(); managerFeeBPS = islandFactory.islandFee(); managerBalance0 = 0; managerBalance1 = 0; _manager = address(0); emit OwnershipTransferred(_manager, address(0)); } /// @notice sync to factory settings for non managed islands function syncToFactory() public { if(!isManaged()) { managerTreasury = islandFactory.treasury(); managerFeeBPS = islandFactory.islandFee(); emit UpdateManagerParams(managerFeeBPS, managerTreasury, compounderSlippageBPS, compounderSlippageInterval); } } function getPositionID() external view returns (bytes32 positionID) { return _getPositionID(); } function _getPositionID() internal view returns (bytes32 positionID) { return keccak256(abi.encodePacked(address(this), lowerTick, upperTick)); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity =0.8.19; /// @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)); // EDIT: 0.8 compatibility require(absTick <= uint256(int256(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: MIT // OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/IERC20Permit.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; /** * @dev 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.encodeWithSelector(token.transfer.selector, 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.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 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); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value)); } /** * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value)); } } /** * @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.encodeWithSelector(token.approve.selector, spender, value); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0)); _callOptionalReturn(token, approvalCall); } } /** * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`. * Revert on invalid signature. */ function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @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, "SafeERC20: low-level call failed"); require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } /** * @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.isContract(address(token)); } }
// 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: GPL-3.0 pragma solidity =0.8.19; import {FullMath} from "./FullMath.sol"; import {FixedPoint96} from "./FixedPoint96.sol"; /// @title Liquidity amount functions /// @notice Provides functions for computing liquidity amounts from token amounts and prices library LiquidityAmounts { function toUint128(uint256 x) private pure returns (uint128 y) { require((y = uint128(x)) == x); } /// @notice Computes the amount of liquidity received for a given amount of token0 and price range /// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower)). /// @param sqrtRatioAX96 A sqrt price /// @param sqrtRatioBX96 Another sqrt price /// @param amount0 The amount0 being sent in /// @return liquidity The amount of returned liquidity function getLiquidityForAmount0( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); uint256 intermediate = FullMath.mulDiv( sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96 ); return toUint128( FullMath.mulDiv( amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96 ) ); } /// @notice Computes the amount of liquidity received for a given amount of token1 and price range /// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)). /// @param sqrtRatioAX96 A sqrt price /// @param sqrtRatioBX96 Another sqrt price /// @param amount1 The amount1 being sent in /// @return liquidity The amount of returned liquidity function getLiquidityForAmount1( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount1 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return toUint128( FullMath.mulDiv( amount1, FixedPoint96.Q96, sqrtRatioBX96 - sqrtRatioAX96 ) ); } /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current /// pool prices and the prices at the tick boundaries function getLiquidityForAmounts( uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); if (sqrtRatioX96 < sqrtRatioAX96) { liquidity = getLiquidityForAmount0( sqrtRatioAX96, sqrtRatioBX96, amount0 ); } else if (sqrtRatioX96 < sqrtRatioBX96) { uint128 liquidity0 = getLiquidityForAmount0( sqrtRatioX96, sqrtRatioBX96, amount0 ); uint128 liquidity1 = getLiquidityForAmount1( sqrtRatioAX96, sqrtRatioX96, amount1 ); liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1; } else { liquidity = getLiquidityForAmount1( sqrtRatioAX96, sqrtRatioBX96, amount1 ); } } /// @notice Computes the amount of token0 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price /// @param sqrtRatioBX96 Another sqrt price /// @param liquidity The liquidity being valued /// @return amount0 The amount0 function getAmount0ForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return FullMath.mulDiv( uint256(liquidity) << FixedPoint96.RESOLUTION, sqrtRatioBX96 - sqrtRatioAX96, sqrtRatioBX96 ) / sqrtRatioAX96; } /// @notice Computes the amount of token1 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price /// @param sqrtRatioBX96 Another sqrt price /// @param liquidity The liquidity being valued /// @return amount1 The amount1 function getAmount1ForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return FullMath.mulDiv( liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96 ); } /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current /// pool prices and the prices at the tick boundaries function getAmountsForLiquidity( uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0, uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); if (sqrtRatioX96 < sqrtRatioAX96) { amount0 = getAmount0ForLiquidity( sqrtRatioAX96, sqrtRatioBX96, liquidity ); } else if (sqrtRatioX96 < sqrtRatioBX96) { amount0 = getAmount0ForLiquidity( sqrtRatioX96, sqrtRatioBX96, liquidity ); amount1 = getAmount1ForLiquidity( sqrtRatioAX96, sqrtRatioX96, liquidity ); } else { amount1 = getAmount1ForLiquidity( sqrtRatioAX96, sqrtRatioBX96, liquidity ); } } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity =0.8.19; interface IUniswapV3Pool { function initialize(uint160 sqrtPriceX96) external; function mint( address recipient, int24 tickLower, int24 tickUpper, uint128 amount, bytes calldata data ) external returns (uint256 amount0, uint256 amount1); function positions(bytes32 key) external view returns ( uint128 _liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1 ); function swap( address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data ) external returns (int256 amount0, int256 amount1); function burn( int24 tickLower, int24 tickUpper, uint128 amount ) external returns (uint256 amount0, uint256 amount1); function collect( address recipient, int24 tickLower, int24 tickUpper, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); function slot0() external view returns ( uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint32 feeProtocol, bool unlocked ); function feeGrowthGlobal0X128() external view returns (uint256); function feeGrowthGlobal1X128() external view returns (uint256); function ticks(int24 tick) external view returns ( uint128 liquidityGross, int128 liquidityNet, uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128, int56 tickCumulativeOutside, uint160 secondsPerLiquidityOutsideX128, uint32 secondsOutside, bool initialized ); function observe(uint32[] calldata secondsAgos) external view returns ( int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s ); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function fee() external view returns (uint24); function tickSpacing() external view returns (int24); function maxLiquidityPerTick() external view returns (uint128); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 amount) external returns (bool); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity =0.8.19; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an manager) that can be granted exclusive access to * specific functions. * * By default, the manager account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyManager`, which can be applied to your functions to restrict their use to * the manager. */ abstract contract OwnableUninitialized { address internal _manager; event OwnershipTransferred( address indexed previousManager, address indexed newManager ); /// @dev Initializes the contract setting the deployer as the initial manager. /// CONSTRUCTOR EMPTY - USE initialize() INSTEAD constructor() {} /** * @dev Returns the address of the current manager. */ function manager() external view returns (address) { return _manager; } /** * @dev Throws if called by any account other than the manager. */ modifier onlyManager() { require(msg.sender == _manager, "Ownable: caller is not the manager"); _; } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current manager. */ function transferOwnership(address newOwner) external onlyManager { require( newOwner != address(0), "Ownable: call renounceOwnership to set zero address" ); emit OwnershipTransferred(_manager, newOwner); _manager = newOwner; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Simple ERC20 + EIP-2612 implementation. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/tokens/ERC20.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol) /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol) /// /// @dev Note: /// - The ERC20 standard allows minting and transferring to and from the zero address, /// minting and transferring zero tokens, as well as self-approvals. /// For performance, this implementation WILL NOT revert for such actions. /// Please add any checks with overrides if desired. /// - The `permit` function uses the ecrecover precompile (0x1). /// /// If you are overriding: /// - NEVER violate the ERC20 invariant: /// the total sum of all balances must be equal to `totalSupply()`. /// - Check that the overridden function is actually used in the function you want to /// change the behavior of. Much of the code has been manually inlined for performance. abstract contract ERC20 { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The total supply has overflowed. error TotalSupplyOverflow(); /// @dev The allowance has overflowed. error AllowanceOverflow(); /// @dev The allowance has underflowed. error AllowanceUnderflow(); /// @dev Insufficient balance. error InsufficientBalance(); /// @dev Insufficient allowance. error InsufficientAllowance(); /// @dev The permit is invalid. error InvalidPermit(); /// @dev The permit has expired. error PermitExpired(); /// @dev The allowance of Permit2 is fixed at infinity. error Permit2AllowanceIsFixedAtInfinity(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Emitted when `amount` tokens is transferred from `from` to `to`. event Transfer(address indexed from, address indexed to, uint256 amount); /// @dev Emitted when `amount` tokens is approved by `owner` to be used by `spender`. event Approval(address indexed owner, address indexed spender, uint256 amount); /// @dev `keccak256(bytes("Transfer(address,address,uint256)"))`. uint256 private constant _TRANSFER_EVENT_SIGNATURE = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef; /// @dev `keccak256(bytes("Approval(address,address,uint256)"))`. uint256 private constant _APPROVAL_EVENT_SIGNATURE = 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STORAGE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The storage slot for the total supply. uint256 private constant _TOTAL_SUPPLY_SLOT = 0x05345cdf77eb68f44c; /// @dev The balance slot of `owner` is given by: /// ``` /// mstore(0x0c, _BALANCE_SLOT_SEED) /// mstore(0x00, owner) /// let balanceSlot := keccak256(0x0c, 0x20) /// ``` uint256 private constant _BALANCE_SLOT_SEED = 0x87a211a2; /// @dev The allowance slot of (`owner`, `spender`) is given by: /// ``` /// mstore(0x20, spender) /// mstore(0x0c, _ALLOWANCE_SLOT_SEED) /// mstore(0x00, owner) /// let allowanceSlot := keccak256(0x0c, 0x34) /// ``` uint256 private constant _ALLOWANCE_SLOT_SEED = 0x7f5e9f20; /// @dev The nonce slot of `owner` is given by: /// ``` /// mstore(0x0c, _NONCES_SLOT_SEED) /// mstore(0x00, owner) /// let nonceSlot := keccak256(0x0c, 0x20) /// ``` uint256 private constant _NONCES_SLOT_SEED = 0x38377508; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev `(_NONCES_SLOT_SEED << 16) | 0x1901`. uint256 private constant _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX = 0x383775081901; /// @dev `keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")`. bytes32 private constant _DOMAIN_TYPEHASH = 0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f; /// @dev `keccak256("1")`. /// If you need to use a different version, override `_versionHash`. bytes32 private constant _DEFAULT_VERSION_HASH = 0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6; /// @dev `keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")`. bytes32 private constant _PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9; /// @dev The canonical Permit2 address. /// For signature-based allowance granting for single transaction ERC20 `transferFrom`. /// To enable, override `_givePermit2InfiniteAllowance()`. /// [Github](https://github.com/Uniswap/permit2) /// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3) address internal constant _PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERC20 METADATA */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the name of the token. function name() public view virtual returns (string memory); /// @dev Returns the symbol of the token. function symbol() public view virtual returns (string memory); /// @dev Returns the decimals places of the token. function decimals() public view virtual returns (uint8) { return 18; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERC20 */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the amount of tokens in existence. function totalSupply() public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { result := sload(_TOTAL_SUPPLY_SLOT) } } /// @dev Returns the amount of tokens owned by `owner`. function balanceOf(address owner) public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { mstore(0x0c, _BALANCE_SLOT_SEED) mstore(0x00, owner) result := sload(keccak256(0x0c, 0x20)) } } /// @dev Returns the amount of tokens that `spender` can spend on behalf of `owner`. function allowance(address owner, address spender) public view virtual returns (uint256 result) { if (_givePermit2InfiniteAllowance()) { if (spender == _PERMIT2) return type(uint256).max; } /// @solidity memory-safe-assembly assembly { mstore(0x20, spender) mstore(0x0c, _ALLOWANCE_SLOT_SEED) mstore(0x00, owner) result := sload(keccak256(0x0c, 0x34)) } } /// @dev Sets `amount` as the allowance of `spender` over the caller's tokens. /// /// Emits a {Approval} event. function approve(address spender, uint256 amount) public virtual returns (bool) { if (_givePermit2InfiniteAllowance()) { /// @solidity memory-safe-assembly assembly { // If `spender == _PERMIT2 && amount != type(uint256).max`. if iszero(or(xor(shr(96, shl(96, spender)), _PERMIT2), iszero(not(amount)))) { mstore(0x00, 0x3f68539a) // `Permit2AllowanceIsFixedAtInfinity()`. revert(0x1c, 0x04) } } } /// @solidity memory-safe-assembly assembly { // Compute the allowance slot and store the amount. mstore(0x20, spender) mstore(0x0c, _ALLOWANCE_SLOT_SEED) mstore(0x00, caller()) sstore(keccak256(0x0c, 0x34), amount) // Emit the {Approval} event. mstore(0x00, amount) log3(0x00, 0x20, _APPROVAL_EVENT_SIGNATURE, caller(), shr(96, mload(0x2c))) } return true; } /// @dev Transfer `amount` tokens from the caller to `to`. /// /// Requirements: /// - `from` must at least have `amount`. /// /// Emits a {Transfer} event. function transfer(address to, uint256 amount) public virtual returns (bool) { _beforeTokenTransfer(msg.sender, to, amount); /// @solidity memory-safe-assembly assembly { // Compute the balance slot and load its value. mstore(0x0c, _BALANCE_SLOT_SEED) mstore(0x00, caller()) let fromBalanceSlot := keccak256(0x0c, 0x20) let fromBalance := sload(fromBalanceSlot) // Revert if insufficient balance. if gt(amount, fromBalance) { mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`. revert(0x1c, 0x04) } // Subtract and store the updated balance. sstore(fromBalanceSlot, sub(fromBalance, amount)) // Compute the balance slot of `to`. mstore(0x00, to) let toBalanceSlot := keccak256(0x0c, 0x20) // Add and store the updated balance of `to`. // Will not overflow because the sum of all user balances // cannot exceed the maximum uint256 value. sstore(toBalanceSlot, add(sload(toBalanceSlot), amount)) // Emit the {Transfer} event. mstore(0x20, amount) log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, caller(), shr(96, mload(0x0c))) } _afterTokenTransfer(msg.sender, to, amount); return true; } /// @dev Transfers `amount` tokens from `from` to `to`. /// /// Note: Does not update the allowance if it is the maximum uint256 value. /// /// Requirements: /// - `from` must at least have `amount`. /// - The caller must have at least `amount` of allowance to transfer the tokens of `from`. /// /// Emits a {Transfer} event. function transferFrom(address from, address to, uint256 amount) public virtual returns (bool) { _beforeTokenTransfer(from, to, amount); // Code duplication is for zero-cost abstraction if possible. if (_givePermit2InfiniteAllowance()) { /// @solidity memory-safe-assembly assembly { let from_ := shl(96, from) if iszero(eq(caller(), _PERMIT2)) { // Compute the allowance slot and load its value. mstore(0x20, caller()) mstore(0x0c, or(from_, _ALLOWANCE_SLOT_SEED)) let allowanceSlot := keccak256(0x0c, 0x34) let allowance_ := sload(allowanceSlot) // If the allowance is not the maximum uint256 value. if not(allowance_) { // Revert if the amount to be transferred exceeds the allowance. if gt(amount, allowance_) { mstore(0x00, 0x13be252b) // `InsufficientAllowance()`. revert(0x1c, 0x04) } // Subtract and store the updated allowance. sstore(allowanceSlot, sub(allowance_, amount)) } } // Compute the balance slot and load its value. mstore(0x0c, or(from_, _BALANCE_SLOT_SEED)) let fromBalanceSlot := keccak256(0x0c, 0x20) let fromBalance := sload(fromBalanceSlot) // Revert if insufficient balance. if gt(amount, fromBalance) { mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`. revert(0x1c, 0x04) } // Subtract and store the updated balance. sstore(fromBalanceSlot, sub(fromBalance, amount)) // Compute the balance slot of `to`. mstore(0x00, to) let toBalanceSlot := keccak256(0x0c, 0x20) // Add and store the updated balance of `to`. // Will not overflow because the sum of all user balances // cannot exceed the maximum uint256 value. sstore(toBalanceSlot, add(sload(toBalanceSlot), amount)) // Emit the {Transfer} event. mstore(0x20, amount) log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c))) } } else { /// @solidity memory-safe-assembly assembly { let from_ := shl(96, from) // Compute the allowance slot and load its value. mstore(0x20, caller()) mstore(0x0c, or(from_, _ALLOWANCE_SLOT_SEED)) let allowanceSlot := keccak256(0x0c, 0x34) let allowance_ := sload(allowanceSlot) // If the allowance is not the maximum uint256 value. if not(allowance_) { // Revert if the amount to be transferred exceeds the allowance. if gt(amount, allowance_) { mstore(0x00, 0x13be252b) // `InsufficientAllowance()`. revert(0x1c, 0x04) } // Subtract and store the updated allowance. sstore(allowanceSlot, sub(allowance_, amount)) } // Compute the balance slot and load its value. mstore(0x0c, or(from_, _BALANCE_SLOT_SEED)) let fromBalanceSlot := keccak256(0x0c, 0x20) let fromBalance := sload(fromBalanceSlot) // Revert if insufficient balance. if gt(amount, fromBalance) { mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`. revert(0x1c, 0x04) } // Subtract and store the updated balance. sstore(fromBalanceSlot, sub(fromBalance, amount)) // Compute the balance slot of `to`. mstore(0x00, to) let toBalanceSlot := keccak256(0x0c, 0x20) // Add and store the updated balance of `to`. // Will not overflow because the sum of all user balances // cannot exceed the maximum uint256 value. sstore(toBalanceSlot, add(sload(toBalanceSlot), amount)) // Emit the {Transfer} event. mstore(0x20, amount) log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c))) } } _afterTokenTransfer(from, to, amount); return true; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EIP-2612 */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev For more performance, override to return the constant value /// of `keccak256(bytes(name()))` if `name()` will never change. function _constantNameHash() internal view virtual returns (bytes32 result) {} /// @dev If you need a different value, override this function. function _versionHash() internal view virtual returns (bytes32 result) { result = _DEFAULT_VERSION_HASH; } /// @dev For inheriting contracts to increment the nonce. function _incrementNonce(address owner) internal virtual { /// @solidity memory-safe-assembly assembly { mstore(0x0c, _NONCES_SLOT_SEED) mstore(0x00, owner) let nonceSlot := keccak256(0x0c, 0x20) sstore(nonceSlot, add(1, sload(nonceSlot))) } } /// @dev Returns the current nonce for `owner`. /// This value is used to compute the signature for EIP-2612 permit. function nonces(address owner) public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { // Compute the nonce slot and load its value. mstore(0x0c, _NONCES_SLOT_SEED) mstore(0x00, owner) result := sload(keccak256(0x0c, 0x20)) } } /// @dev Sets `value` as the allowance of `spender` over the tokens of `owner`, /// authorized by a signed approval by `owner`. /// /// Emits a {Approval} event. function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) public virtual { if (_givePermit2InfiniteAllowance()) { /// @solidity memory-safe-assembly assembly { // If `spender == _PERMIT2 && value != type(uint256).max`. if iszero(or(xor(shr(96, shl(96, spender)), _PERMIT2), iszero(not(value)))) { mstore(0x00, 0x3f68539a) // `Permit2AllowanceIsFixedAtInfinity()`. revert(0x1c, 0x04) } } } bytes32 nameHash = _constantNameHash(); // We simply calculate it on-the-fly to allow for cases where the `name` may change. if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name())); bytes32 versionHash = _versionHash(); /// @solidity memory-safe-assembly assembly { // Revert if the block timestamp is greater than `deadline`. if gt(timestamp(), deadline) { mstore(0x00, 0x1a15a3cc) // `PermitExpired()`. revert(0x1c, 0x04) } let m := mload(0x40) // Grab the free memory pointer. // Clean the upper 96 bits. owner := shr(96, shl(96, owner)) spender := shr(96, shl(96, spender)) // Compute the nonce slot and load its value. mstore(0x0e, _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX) mstore(0x00, owner) let nonceSlot := keccak256(0x0c, 0x20) let nonceValue := sload(nonceSlot) // Prepare the domain separator. mstore(m, _DOMAIN_TYPEHASH) mstore(add(m, 0x20), nameHash) mstore(add(m, 0x40), versionHash) mstore(add(m, 0x60), chainid()) mstore(add(m, 0x80), address()) mstore(0x2e, keccak256(m, 0xa0)) // Prepare the struct hash. mstore(m, _PERMIT_TYPEHASH) mstore(add(m, 0x20), owner) mstore(add(m, 0x40), spender) mstore(add(m, 0x60), value) mstore(add(m, 0x80), nonceValue) mstore(add(m, 0xa0), deadline) mstore(0x4e, keccak256(m, 0xc0)) // Prepare the ecrecover calldata. mstore(0x00, keccak256(0x2c, 0x42)) mstore(0x20, and(0xff, v)) mstore(0x40, r) mstore(0x60, s) let t := staticcall(gas(), 1, 0x00, 0x80, 0x20, 0x20) // If the ecrecover fails, the returndatasize will be 0x00, // `owner` will be checked if it equals the hash at 0x00, // which evaluates to false (i.e. 0), and we will revert. // If the ecrecover succeeds, the returndatasize will be 0x20, // `owner` will be compared against the returned address at 0x20. if iszero(eq(mload(returndatasize()), owner)) { mstore(0x00, 0xddafbaef) // `InvalidPermit()`. revert(0x1c, 0x04) } // Increment and store the updated nonce. sstore(nonceSlot, add(nonceValue, t)) // `t` is 1 if ecrecover succeeds. // Compute the allowance slot and store the value. // The `owner` is already at slot 0x20. mstore(0x40, or(shl(160, _ALLOWANCE_SLOT_SEED), spender)) sstore(keccak256(0x2c, 0x34), value) // Emit the {Approval} event. log3(add(m, 0x60), 0x20, _APPROVAL_EVENT_SIGNATURE, owner, spender) mstore(0x40, m) // Restore the free memory pointer. mstore(0x60, 0) // Restore the zero pointer. } } /// @dev Returns the EIP-712 domain separator for the EIP-2612 permit. function DOMAIN_SEPARATOR() public view virtual returns (bytes32 result) { bytes32 nameHash = _constantNameHash(); // We simply calculate it on-the-fly to allow for cases where the `name` may change. if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name())); bytes32 versionHash = _versionHash(); /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Grab the free memory pointer. mstore(m, _DOMAIN_TYPEHASH) mstore(add(m, 0x20), nameHash) mstore(add(m, 0x40), versionHash) mstore(add(m, 0x60), chainid()) mstore(add(m, 0x80), address()) result := keccak256(m, 0xa0) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL MINT FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Mints `amount` tokens to `to`, increasing the total supply. /// /// Emits a {Transfer} event. function _mint(address to, uint256 amount) internal virtual { _beforeTokenTransfer(address(0), to, amount); /// @solidity memory-safe-assembly assembly { let totalSupplyBefore := sload(_TOTAL_SUPPLY_SLOT) let totalSupplyAfter := add(totalSupplyBefore, amount) // Revert if the total supply overflows. if lt(totalSupplyAfter, totalSupplyBefore) { mstore(0x00, 0xe5cfe957) // `TotalSupplyOverflow()`. revert(0x1c, 0x04) } // Store the updated total supply. sstore(_TOTAL_SUPPLY_SLOT, totalSupplyAfter) // Compute the balance slot and load its value. mstore(0x0c, _BALANCE_SLOT_SEED) mstore(0x00, to) let toBalanceSlot := keccak256(0x0c, 0x20) // Add and store the updated balance. sstore(toBalanceSlot, add(sload(toBalanceSlot), amount)) // Emit the {Transfer} event. mstore(0x20, amount) log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, 0, shr(96, mload(0x0c))) } _afterTokenTransfer(address(0), to, amount); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL BURN FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Burns `amount` tokens from `from`, reducing the total supply. /// /// Emits a {Transfer} event. function _burn(address from, uint256 amount) internal virtual { _beforeTokenTransfer(from, address(0), amount); /// @solidity memory-safe-assembly assembly { // Compute the balance slot and load its value. mstore(0x0c, _BALANCE_SLOT_SEED) mstore(0x00, from) let fromBalanceSlot := keccak256(0x0c, 0x20) let fromBalance := sload(fromBalanceSlot) // Revert if insufficient balance. if gt(amount, fromBalance) { mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`. revert(0x1c, 0x04) } // Subtract and store the updated balance. sstore(fromBalanceSlot, sub(fromBalance, amount)) // Subtract and store the updated total supply. sstore(_TOTAL_SUPPLY_SLOT, sub(sload(_TOTAL_SUPPLY_SLOT), amount)) // Emit the {Transfer} event. mstore(0x00, amount) log3(0x00, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, shl(96, from)), 0) } _afterTokenTransfer(from, address(0), amount); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL TRANSFER FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Moves `amount` of tokens from `from` to `to`. function _transfer(address from, address to, uint256 amount) internal virtual { _beforeTokenTransfer(from, to, amount); /// @solidity memory-safe-assembly assembly { let from_ := shl(96, from) // Compute the balance slot and load its value. mstore(0x0c, or(from_, _BALANCE_SLOT_SEED)) let fromBalanceSlot := keccak256(0x0c, 0x20) let fromBalance := sload(fromBalanceSlot) // Revert if insufficient balance. if gt(amount, fromBalance) { mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`. revert(0x1c, 0x04) } // Subtract and store the updated balance. sstore(fromBalanceSlot, sub(fromBalance, amount)) // Compute the balance slot of `to`. mstore(0x00, to) let toBalanceSlot := keccak256(0x0c, 0x20) // Add and store the updated balance of `to`. // Will not overflow because the sum of all user balances // cannot exceed the maximum uint256 value. sstore(toBalanceSlot, add(sload(toBalanceSlot), amount)) // Emit the {Transfer} event. mstore(0x20, amount) log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c))) } _afterTokenTransfer(from, to, amount); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL ALLOWANCE FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Updates the allowance of `owner` for `spender` based on spent `amount`. function _spendAllowance(address owner, address spender, uint256 amount) internal virtual { if (_givePermit2InfiniteAllowance()) { if (spender == _PERMIT2) return; // Do nothing, as allowance is infinite. } /// @solidity memory-safe-assembly assembly { // Compute the allowance slot and load its value. mstore(0x20, spender) mstore(0x0c, _ALLOWANCE_SLOT_SEED) mstore(0x00, owner) let allowanceSlot := keccak256(0x0c, 0x34) let allowance_ := sload(allowanceSlot) // If the allowance is not the maximum uint256 value. if not(allowance_) { // Revert if the amount to be transferred exceeds the allowance. if gt(amount, allowance_) { mstore(0x00, 0x13be252b) // `InsufficientAllowance()`. revert(0x1c, 0x04) } // Subtract and store the updated allowance. sstore(allowanceSlot, sub(allowance_, amount)) } } } /// @dev Sets `amount` as the allowance of `spender` over the tokens of `owner`. /// /// Emits a {Approval} event. function _approve(address owner, address spender, uint256 amount) internal virtual { if (_givePermit2InfiniteAllowance()) { /// @solidity memory-safe-assembly assembly { // If `spender == _PERMIT2 && amount != type(uint256).max`. if iszero(or(xor(shr(96, shl(96, spender)), _PERMIT2), iszero(not(amount)))) { mstore(0x00, 0x3f68539a) // `Permit2AllowanceIsFixedAtInfinity()`. revert(0x1c, 0x04) } } } /// @solidity memory-safe-assembly assembly { let owner_ := shl(96, owner) // Compute the allowance slot and store the amount. mstore(0x20, spender) mstore(0x0c, or(owner_, _ALLOWANCE_SLOT_SEED)) sstore(keccak256(0x0c, 0x34), amount) // Emit the {Approval} event. mstore(0x00, amount) log3(0x00, 0x20, _APPROVAL_EVENT_SIGNATURE, shr(96, owner_), shr(96, mload(0x2c))) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* HOOKS TO OVERRIDE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Hook that is called before any transfer of tokens. /// This includes minting and burning. function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {} /// @dev Hook that is called after any transfer of tokens. /// This includes minting and burning. function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {} /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PERMIT2 */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns whether to fix the Permit2 contract's allowance at infinity. /// /// This value should be kept constant after contract initialization, /// or else the actual allowance values may not match with the {Approval} events. /// For best performance, return a compile-time constant for zero-cost abstraction. function _givePermit2InfiniteAllowance() internal view virtual returns (bool) { return false; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Reentrancy guard mixin. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ReentrancyGuard.sol) abstract contract ReentrancyGuard { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Unauthorized reentrant call. error Reentrancy(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STORAGE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Equivalent to: `uint72(bytes9(keccak256("_REENTRANCY_GUARD_SLOT")))`. /// 9 bytes is large enough to avoid collisions with lower slots, /// but not too large to result in excessive bytecode bloat. uint256 private constant _REENTRANCY_GUARD_SLOT = 0x929eee149b4bd21268; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* REENTRANCY GUARD */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Guards a function from reentrancy. modifier nonReentrant() virtual { /// @solidity memory-safe-assembly assembly { if eq(sload(_REENTRANCY_GUARD_SLOT), address()) { mstore(0x00, 0xab143c06) // `Reentrancy()`. revert(0x1c, 0x04) } sstore(_REENTRANCY_GUARD_SLOT, address()) } _; /// @solidity memory-safe-assembly assembly { sstore(_REENTRANCY_GUARD_SLOT, codesize()) } } /// @dev Guards a view function from read-only reentrancy. modifier nonReadReentrant() virtual { /// @solidity memory-safe-assembly assembly { if eq(sload(_REENTRANCY_GUARD_SLOT), address()) { mstore(0x00, 0xab143c06) // `Reentrancy()`. revert(0x1c, 0x04) } } _; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract Pausable is Context { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ constructor() { _paused = false; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { require(!paused(), "Pausable: paused"); } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { require(paused(), "Pausable: not paused"); } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } }
//SPDX-License-Identifier: MIT pragma solidity =0.8.19; interface IKodiakIslandFactory { event IslandCreated(address indexed uniPool, address indexed manager, address indexed island, address implementation); event TreasurySet(address indexed treasury); event IslandFeeSet(uint16 fee); event UpdateIslandImplementation(address newImplementation); function deployVault( address tokenA, address tokenB, uint24 uniFee, address manager, address managerTreasury, uint16 managerFee, int24 lowerTick, int24 upperTick ) external returns (address island); function setIslandImplementation(address newImplementation) external; function islandImplementation() external view returns (address); function treasury() external view returns (address); function islandFee() external view returns (uint16); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. * * ==== Security Considerations * * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be * considered as an intention to spend the allowance in any specific way. The second is that because permits have * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be * generally recommended is: * * ```solidity * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public { * try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {} * doThing(..., value); * } * * function doThing(..., uint256 value) public { * token.safeTransferFrom(msg.sender, address(this), value); * ... * } * ``` * * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also * {SafeERC20-safeTransferFrom}). * * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so * contracts should have entry points that don't rely on permit. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. * * CAUTION: See Security Considerations above. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.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 * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [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://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.0/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: GPL-3.0 pragma solidity =0.8.19; /// @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. // EDIT for 0.8 compatibility: // see: https://ethereum.stackexchange.com/questions/96642/unary-operator-cannot-be-applied-to-type-uint256 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++; } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.8.19; /// @title FixedPoint96 /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) /// @dev Used in SqrtPriceMath.sol library FixedPoint96 { uint8 internal constant RESOLUTION = 96; uint256 internal constant Q96 = 0x1000000000000000000000000; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.4) (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; } function _contextSuffixLength() internal view virtual returns (uint256) { return 0; } }
{ "remappings": [ "forge-std/=lib/forge-std/src/", "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/" ], "optimizer": { "enabled": true, "runs": 100 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "paris", "viaIR": false, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"name":"AllowanceOverflow","type":"error"},{"inputs":[],"name":"AllowanceUnderflow","type":"error"},{"inputs":[],"name":"InsufficientAllowance","type":"error"},{"inputs":[],"name":"InsufficientBalance","type":"error"},{"inputs":[],"name":"InvalidPermit","type":"error"},{"inputs":[],"name":"Permit2AllowanceIsFixedAtInfinity","type":"error"},{"inputs":[],"name":"PermitExpired","type":"error"},{"inputs":[],"name":"Reentrancy","type":"error"},{"inputs":[],"name":"TotalSupplyOverflow","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"burnAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0Out","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1Out","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidityBurned","type":"uint128"}],"name":"Burned","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"feesEarned0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feesEarned1","type":"uint256"}],"name":"FeesEarned","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"mintAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0In","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1In","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidityMinted","type":"uint128"}],"name":"Minted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousManager","type":"address"},{"indexed":true,"internalType":"address","name":"newManager","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pauser","type":"address"},{"indexed":false,"internalType":"bool","name":"status","type":"bool"}],"name":"PauserSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"compounder","type":"address"},{"indexed":false,"internalType":"int24","name":"lowerTick_","type":"int24"},{"indexed":false,"internalType":"int24","name":"upperTick_","type":"int24"},{"indexed":false,"internalType":"uint128","name":"liquidityBefore","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"liquidityAfter","type":"uint128"}],"name":"Rebalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"status","type":"bool"}],"name":"RestrictedMintSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"router","type":"address"},{"indexed":false,"internalType":"bool","name":"status","type":"bool"}],"name":"RouterSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"managerFeeBPS","type":"uint16"},{"indexed":false,"internalType":"address","name":"managerTreasury","type":"address"},{"indexed":false,"internalType":"uint16","name":"compounderSlippageBPS","type":"uint16"},{"indexed":false,"internalType":"uint32","name":"compounderSlippageInterval","type":"uint32"}],"name":"UpdateManagerParams","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"result","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"burnAmount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"burn","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint128","name":"liquidityBurned","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"compounderSlippageBPS","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"compounderSlippageInterval","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int24","name":"newLowerTick","type":"int24"},{"internalType":"int24","name":"newUpperTick","type":"int24"},{"internalType":"uint160","name":"swapThresholdPrice","type":"uint160"},{"internalType":"uint256","name":"swapAmountBPS","type":"uint256"},{"internalType":"bool","name":"zeroForOne","type":"bool"}],"name":"executiveRebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int24","name":"newLowerTick","type":"int24"},{"internalType":"int24","name":"newUpperTick","type":"int24"},{"components":[{"internalType":"address","name":"router","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"bool","name":"zeroForOne","type":"bool"},{"internalType":"bytes","name":"routeData","type":"bytes"}],"internalType":"struct SwapData","name":"swapData","type":"tuple"}],"name":"executiveRebalanceWithRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"interval","type":"uint32"}],"name":"getAvgPrice","outputs":[{"internalType":"uint160","name":"avgSqrtPriceX96","type":"uint160"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0Max","type":"uint256"},{"internalType":"uint256","name":"amount1Max","type":"uint256"}],"name":"getMintAmounts","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"mintAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPositionID","outputs":[{"internalType":"bytes32","name":"positionID","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getUnderlyingBalances","outputs":[{"internalType":"uint256","name":"amount0Current","type":"uint256"},{"internalType":"uint256","name":"amount1Current","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint160","name":"sqrtRatioX96","type":"uint160"}],"name":"getUnderlyingBalancesAtPrice","outputs":[{"internalType":"uint256","name":"amount0Current","type":"uint256"},{"internalType":"uint256","name":"amount1Current","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"address","name":"_pool","type":"address"},{"internalType":"uint16","name":"_managerFeeBPS","type":"uint16"},{"internalType":"int24","name":"_lowerTick","type":"int24"},{"internalType":"int24","name":"_upperTick","type":"int24"},{"internalType":"address","name":"_manager_","type":"address"},{"internalType":"address","name":"_managerTreasury","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isManaged","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"islandFactory","outputs":[{"internalType":"contract IKodiakIslandFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lowerTick","outputs":[{"internalType":"int24","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"managerBalance0","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"managerBalance1","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"managerFeeBPS","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"managerTreasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"mintAmount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint128","name":"liquidityMinted","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"pauser","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pool","outputs":[{"internalType":"contract IUniswapV3Pool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"restrictedMint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_pauser","type":"address"},{"internalType":"bool","name":"_status","type":"bool"}],"name":"setPauser","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_status","type":"bool"}],"name":"setRestrictedMint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_router","type":"address"},{"internalType":"bool","name":"_status","type":"bool"}],"name":"setRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"swapRouter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"syncToFactory","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token0","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token1","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0Owed","type":"uint256"},{"internalType":"uint256","name":"amount1Owed","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"uniswapV3MintCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"uniswapV3SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int16","name":"newManagerFeeBPS","type":"int16"},{"internalType":"address","name":"newManagerTreasury","type":"address"},{"internalType":"int16","name":"newSlippageBPS","type":"int16"},{"internalType":"int32","name":"newSlippageInterval","type":"int32"}],"name":"updateManagerParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"upperTick","outputs":[{"internalType":"int24","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdrawManagerBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint16","name":"slippageBPS","type":"uint16"},{"internalType":"uint160","name":"avgSqrtPriceX96","type":"uint160"},{"internalType":"bool","name":"zeroForOne","type":"bool"}],"name":"worstAmountOut","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}]
Contract Creation Code
608060405234801561001057600080fd5b506000805460ff60a01b19169055615f90806200002e6000396000f3fe608060405234801561001057600080fd5b50600436106102ed5760003560e01c80637d7c2a1c11610193578063cc95353e116100e4578063db812fd011610092578063db812fd014610711578063dcf0ff2814610724578063dd62ed3e14610739578063df28408a14610762578063f2fde38b1461076a578063fa461e331461077d578063fcd3533c1461079057600080fd5b8063cc95353e14610677578063ccdf7a021461068a578063d1c122ea146106b2578063d21220a7146106c5578063d3487997146106d8578063d505accf146106eb578063d8329c35146106fe57600080fd5b806399e7061b1161014157806399e7061b146105e95780639b1344ac1461060c578063a9059cbb1461061e578063b670ed7d14610631578063c3c6467414610644578063c7a4ae1714610657578063cbddcbc31461066457600080fd5b80637d7c2a1c1461053e5780637ecd6717146105465780637ecebe001461054e5780638456cb591461057457806394bf804d1461057c57806395d89b41146105b35780639894f21a146105bb57600080fd5b8063385033451161024d5780635e6663cc116101fb5780635e6663cc146104a857806367582f4a146104bb578063688f7218146104ce57806370a08231146104d6578063715018a6146104fc5780637180c8ca14610504578063727dd2281461051757600080fd5b8063385033451461041b5780633f4ba83a1461044757806342fb9d441461044f578063481c6a751461045857806351a2dc921461046957806354fd4d501461047c5780635c975abb146104a057600080fd5b806316f0115b116102aa57806316f0115b146103a657806318160ddd146103b957806318e91fb5146103c957806323b872dd146103de57806324b8fd1b146103f1578063313ce567146104045780633644e5151461041357600080fd5b8063065756db146102f257806306fdde031461030e578063095ea7b3146103235780630a1289ad146103465780630dfe1681146103695780631322d95414610389575b600080fd5b6102fb60065481565b6040519081526020015b60405180910390f35b6103166107a3565b6040516103059190614edc565b610336610331366004614f32565b610835565b6040519015158152602001610305565b610336610354366004614f5e565b600b6020526000908152604090205460ff1681565b60095461037c906001600160a01b031681565b6040516103059190614f7b565b610391610889565b60408051928352602083019190915201610305565b60085461037c906001600160a01b031681565b6805345cdf77eb68f44c546102fb565b6103dc6103d7366004614fa1565b610923565b005b6103366103ec366004614fff565b610acd565b6103dc6103ff36600461505d565b610b78565b60405160128152602001610305565b6102fb610efc565b60035461043290600160481b900463ffffffff1681565b60405163ffffffff9091168152602001610305565b6103dc610f79565b6102fb60075481565b6000546001600160a01b031661037c565b61037c6104773660046150d7565b610fad565b610316604051806040016040528060058152602001640312e302e360dc1b81525081565b610336611191565b6000546001600160a01b03161515610336565b6103dc6104c93660046150f4565b6111a1565b6103dc611212565b6102fb6104e4366004614f5e565b6387a211a2600c908152600091909152602090205490565b6103dc6113a2565b6103dc610512366004615111565b611533565b60035461052b90600160201b900460020b81565b60405160029190910b8152602001610305565b6103dc6115e3565b6103dc61178b565b6102fb61055c366004614f5e565b6338377508600c908152600091909152602090205490565b6103dc6117e7565b61058f61058a366004615158565b6118dc565b6040805193845260208401929092526001600160801b031690820152606001610305565b610316611c2e565b6105ce6105c936600461517d565b611c3d565b60408051938452602084019290925290820152606001610305565b6103366105f7366004614f5e565b600c6020526000908152604090205460ff1681565b60035461052b90610100900460020b81565b61033661062c366004614f32565b611d7c565b61039161063f366004614f5e565b611de5565b6103dc610652366004615111565b611e7d565b6003546103369060ff1681565b60055461037c906001600160a01b031681565b60045461037c906001600160a01b031681565b60035461069f90600160681b900461ffff1681565b60405161ffff9091168152602001610305565b6103dc6106c036600461519f565b611f25565b600a5461037c906001600160a01b031681565b6103dc6106e636600461524f565b6123ad565b6103dc6106f93660046152a1565b612417565b6102fb61070c366004615328565b6125a2565b6103dc61071f366004615425565b61270d565b60035461069f90600160381b900461ffff1681565b6102fb6107473660046154f6565b602052637f5e9f20600c908152600091909152603490205490565b6102fb61297b565b6103dc610778366004614f5e565b61298a565b6103dc61078b36600461524f565b612a81565b61058f61079e366004615158565b612af0565b6060600180546107b290615524565b80601f01602080910402602001604051908101604052809291908181526020018280546107de90615524565b801561082b5780601f106108005761010080835404028352916020019161082b565b820191906000526020600020905b81548152906001019060200180831161080e57829003601f168201915b5050505050905090565b600082602052637f5e9f20600c5233600052816034600c205581600052602c5160601c337f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560206000a35060015b92915050565b600080600080600860009054906101000a90046001600160a01b03166001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156108e2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610906919061555e565b5050505050915091506109198282612ddb565b9350935050509091565b6000546001600160a01b031633146109565760405162461bcd60e51b815260040161094d906155fa565b60405180910390fd5b6127108260010b13156109915760405162461bcd60e51b815260206004820152600360248201526242505360e81b604482015260640161094d565b6127108460010b13156109b65760405162461bcd60e51b815260040161094d9061563c565b60008460010b126109dc576003805461ffff60681b1916600160681b61ffff8716021790555b6001600160a01b03831615610a0757600480546001600160a01b0319166001600160a01b0385161790555b60008260010b12610a2d576003805461ffff60381b1916600160381b61ffff8516021790555b60008160030b12610a57576003805463ffffffff60481b1916600160481b63ffffffff8416021790555b6003546004546040517fd61f3e2d0a1abe8c7a06f409e2069f4ba0ad684d8dcb174b9101f0bccf5e283f92610abf92600160681b820461ffff908116936001600160a01b0390921692600160381b810490911691600160481b90910463ffffffff169061566c565b60405180910390a150505050565b60008360601b33602052637f5e9f208117600c526034600c208054801915610b0b5780851115610b05576313be252b6000526004601cfd5b84810382555b50506387a211a28117600c526020600c20805480851115610b345763f4d678b86000526004601cfd5b84810382555050836000526020600c208381540181555082602052600c5160601c8160601c600080516020615f3b833981519152602080a3505060015b9392505050565b610b80613056565b6000546001600160a01b03163314610baa5760405162461bcd60e51b815260040161094d906155fa565b6000806000610bc06805345cdf77eb68f44c5490565b1115610e86576008546001600160a01b031663514ea4bf610bdf61309e565b6040518263ffffffff1660e01b8152600401610bfd91815260200190565b60a060405180830381865afa158015610c1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c3e91906156b6565b5092945050506001600160801b038316159050610c8e576003546000908190610c7b906101008104600290810b91600160201b9004900b866130fc565b935093505050610c8b8282613263565b50505b6003805462ffffff888116600160201b0262ffffff60201b19918b16610100029190911666ffffffffffff0019909216919091171790556006546009546040516370a0823160e01b8152600092916001600160a01b0316906370a0823190610cfa903090600401614f7b565b602060405180830381865afa158015610d17573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d3b919061570d565b610d45919061573c565b600754600a546040516370a0823160e01b81529293506000926001600160a01b03909116906370a0823190610d7e903090600401614f7b565b602060405180830381865afa158015610d9b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dbf919061570d565b610dc9919061573c565b9050610dda898984848b8b8b61336d565b6008546001600160a01b031663514ea4bf610df361309e565b6040518263ffffffff1660e01b8152600401610e1191815260200190565b60a060405180830381865afa158015610e2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e5291906156b6565b509295505050506001600160801b038316610e7f5760405162461bcd60e51b815260040161094d9061574f565b5050610ebe565b6003805462ffffff888116600160201b0262ffffff60201b19918b16610100029190911666ffffffffffff0019909216919091171790555b336001600160a01b0316600080516020615f1b83398151915288888585604051610eeb9493929190615777565b60405180910390a250505050505050565b600080610f076107a3565b805190602001209050604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f815260208101929092527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc69082015246606082015230608082015260a09020919050565b6000546001600160a01b03163314610fa35760405162461bcd60e51b815260040161094d906155fa565b610fab6133e2565b565b6000808263ffffffff1611610ff75760405162461bcd60e51b815260206004820152601060248201526f125b9d985b1a59081a5b9d195c9d985b60821b604482015260640161094d565b604080516002808252606082018352600092602083019080368337019050509050828160008151811061102c5761102c6157a5565b602002602001019063ffffffff16908163ffffffff168152505060008160018151811061105b5761105b6157a5565b63ffffffff9092166020928302919091019091015260085460405163883bdbfd60e01b81526000916001600160a01b03169063883bdbfd906110a19085906004016157bb565b600060405180830381865afa1580156110be573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526110e691908101906158ae565b50905080516002146111265760405162461bcd60e51b815260206004820152600960248201526830b93930bc903632b760b91b604482015260640161094d565b60008463ffffffff1660060b82600081518110611145576111456157a5565b602002602001015183600181518110611160576111606157a5565b60200260200101510360060b8161117957611179615970565b0590506111888160020b613427565b95945050505050565b600054600160a01b900460ff1690565b6000546001600160a01b031633146111cb5760405162461bcd60e51b815260040161094d906155fa565b6003805460ff19168215159081179091556040519081527f466ad1943abf95179c60a8c1ab56e7ba1467e287ca7d923b7d98965bc382c8f69060200160405180910390a150565b6000546001600160a01b0316610fab57600560009054906101000a90046001600160a01b03166001600160a01b03166361d027b36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611275573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112999190615986565b600480546001600160a01b0319166001600160a01b0392831617815560055460408051630bdb371360e11b8152905191909316926317b66e2692818101926020929091908290030181865afa1580156112f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061131a91906159a3565b6003805461ffff60681b1916600160681b61ffff938416810291909117918290556004546040517fd61f3e2d0a1abe8c7a06f409e2069f4ba0ad684d8dcb174b9101f0bccf5e283f94611398949384048116936001600160a01b0390931692600160381b810490911691600160481b90910463ffffffff169061566c565b60405180910390a1565b6113aa613056565b6000546001600160a01b031633146113d45760405162461bcd60e51b815260040161094d906155fa565b600560009054906101000a90046001600160a01b03166001600160a01b03166361d027b36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611427573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061144b9190615986565b600480546001600160a01b0319166001600160a01b0392831617815560055460408051630bdb371360e11b8152905191909316926317b66e2692818101926020929091908290030181865afa1580156114a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114cc91906159a3565b6003805461ffff92909216600160681b0261ffff60681b1990921691909117905560006006819055600781905580546001600160a01b031916815560405181907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3565b6000546001600160a01b0316331461155d5760405162461bcd60e51b815260040161094d906155fa565b6001600160a01b0382166115835760405162461bcd60e51b815260040161094d906159c0565b6001600160a01b0382166000818152600b6020908152604091829020805460ff191685151590811790915591519182527fa11b5803b8a35081b8f993e0dee5bc30301a3d83f644e5ab2ff39f972f0a807f91015b60405180910390a25050565b6115eb613056565b6008546000906001600160a01b031663514ea4bf61160761309e565b6040518263ffffffff1660e01b815260040161162591815260200190565b60a060405180830381865afa158015611642573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061166691906156b6565b505050509050611674613834565b6008546000906001600160a01b031663514ea4bf61169061309e565b6040518263ffffffff1660e01b81526004016116ae91815260200190565b60a060405180830381865afa1580156116cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116ef91906156b6565b505050509050816001600160801b0316816001600160801b0316116117505760405162461bcd60e51b81526020600482015260176024820152766c6971756964697479206d75737420696e63726561736560481b604482015260640161094d565b6003546040513391600080516020615f1b833981519152916115d7916101008104600290810b92600160201b909204900b9087908790615777565b60068054600780546000938490559290559081156117c0576004546009546117c0916001600160a01b0391821691168461397b565b80156117e357600454600a546117e3916001600160a01b0391821691168361397b565b5050565b336000908152600b602052604090205460ff168061180f57506000546001600160a01b031633145b6118655760405162461bcd60e51b815260206004820152602160248201527f4f776e61626c653a2063616c6c6572206973206e6f74207468652070617573656044820152603960f91b606482015260840161094d565b6000546001600160a01b03166118d45760405162461bcd60e51b815260206004820152602e60248201527f5061757361626c653a2063616e6e6f7420706175736520776974686f7574206160448201526d103b30b634b21036b0b730b3b2b960911b606482015260840161094d565b610fab6139de565b60008060006118e9613056565b3068929eee149b4bd2126854036119085763ab143c066000526004601cfd5b3068929eee149b4bd212685560035460ff16158061193057506000546001600160a01b031633145b8061194457506000546001600160a01b0316155b61197d5760405162461bcd60e51b815260206004820152600a6024820152691c995cdd1c9a58dd195960b21b604482015260640161094d565b60006119906805345cdf77eb68f44c5490565b90506000600860009054906101000a90046001600160a01b03166001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156119e7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a0b919061555e565b50505050505090506000821115611a6c5760008711611a3c5760405162461bcd60e51b815260040161094d906159e6565b600080611a47610889565b91509150611a56828a86613a21565b9650611a63818a86613a21565b95505050611acb565b600354611aaa908290611a8690610100900460020b613427565b600354611a9c90600160201b900460020b613427565b611aa58b613a61565b613ace565b9095509350611abc60006103e8613b6b565b611ac86103e88861573c565b96505b8415611ae957600954611ae9906001600160a01b0316333088613bd8565b8315611b0757600a54611b07906001600160a01b0316333087613bd8565b600354611b3e908290611b2190610100900460020b613427565b600354611b3790600160201b900460020b613427565b8888613c10565b600854600354604051633c8a7d8d60e01b81529295506001600160a01b0390911691633c8a7d8d91611b8c9130916101008104600290810b92600160201b909204900b908990600401615a06565b60408051808303816000875af1158015611baa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bce9190615a48565b5050611bda8688613b6b565b7f55801cfe493000b734571da1694b21e7f66b11e8ce9fdaa0524ecb59105e73e78688878787604051611c11959493929190615a6c565b60405180910390a150503868929eee149b4bd21268559250925092565b6060600280546107b290615524565b600080600080611c546805345cdf77eb68f44c5490565b90508015611c7357611c67818787613cd3565b91955093509150611d74565b60085460408051633850c7bd60e01b815290516000926001600160a01b031691633850c7bd9160048083019260e09291908290030181865afa158015611cbd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ce1919061555e565b50505050505090506000611d2782611d0a600360019054906101000a900460020b60020b613427565b600354611d2090600160201b900460020b613427565b8b8b613c10565b6003546001600160801b0382169550909150611d6c908390611d5090610100900460020b613427565b600354611d6690600160201b900460020b613427565b84613ace565b909650945050505b509250925092565b60006387a211a2600c52336000526020600c20805480841115611da75763f4d678b86000526004601cfd5b83810382555050826000526020600c208281540181555081602052600c5160601c33600080516020615f3b833981519152602080a350600192915050565b6000806000600860009054906101000a90046001600160a01b03166001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa158015611e3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e61919061555e565b5050505050915050611e738482612ddb565b9250925050915091565b6000546001600160a01b03163314611ea75760405162461bcd60e51b815260040161094d906155fa565b6001600160a01b038216611ecd5760405162461bcd60e51b815260040161094d906159c0565b6001600160a01b0382166000818152600c6020908152604091829020805460ff191685151590811790915591519182527f8443a265af33599abe6c9ed0c3cabd8e2a6c5b8ea35c1d1ed40c513242f95d4591016115d7565b611f2d613056565b6000546001600160a01b03163314611f575760405162461bcd60e51b815260040161094d906155fa565b600c6000611f686020840184614f5e565b6001600160a01b0316815260208101919091526040016000205460ff16611fc75760405162461bcd60e51b81526020600482015260136024820152722ab730baba3437b934bd32b2103937baba32b960691b604482015260640161094d565b60035460009061200990602084013590600160381b810461ffff1690611ff990600160481b900463ffffffff16610fad565b61070c60808701606088016150f4565b90508082604001351161205e5760405162461bcd60e51b815260206004820152601b60248201527f53657420726561736f6e61626c65206d696e416d6f756e744f75740000000000604482015260640161094d565b5060008060006120756805345cdf77eb68f44c5490565b1115612339576008546001600160a01b031663514ea4bf61209461309e565b6040518263ffffffff1660e01b81526004016120b291815260200190565b60a060405180830381865afa1580156120cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120f391906156b6565b5092945050506001600160801b038316159050612143576003546000908190612130906101008104600290810b91600160201b9004900b866130fc565b9350935050506121408282613263565b50505b6003805462ffffff868116600160201b0262ffffff60201b19918916610100029190911666ffffffffffff0019909216919091171790556006546009546040516370a0823160e01b8152600092916001600160a01b0316906370a08231906121af903090600401614f7b565b602060405180830381865afa1580156121cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121f0919061570d565b6121fa919061573c565b600754600a546040516370a0823160e01b81529293506000926001600160a01b03909116906370a0823190612233903090600401614f7b565b602060405180830381865afa158015612250573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612274919061570d565b61227e919061573c565b905061228d8787848489613de2565b6008546001600160a01b031663514ea4bf6122a661309e565b6040518263ffffffff1660e01b81526004016122c491815260200190565b60a060405180830381865afa1580156122e1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061230591906156b6565b509295505050506001600160801b0383166123325760405162461bcd60e51b815260040161094d9061574f565b5050612371565b6003805462ffffff868116600160201b0262ffffff60201b19918916610100029190911666ffffffffffff0019909216919091171790555b336001600160a01b0316600080516020615f1b8339815191528686858560405161239e9493929190615777565b60405180910390a25050505050565b6008546001600160a01b031633146123d75760405162461bcd60e51b815260040161094d90615aa3565b83156123f4576009546123f4906001600160a01b0316338661397b565b821561241157600a54612411906001600160a01b0316338561397b565b50505050565b60006124216107a3565b8051906020012090507fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc64286101561246157631a15a3cc6000526004601cfd5b6040518960601b60601c99508860601b60601c985065383775081901600e52896000526020600c2080547f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f835284602084015283604084015246606084015230608084015260a08320602e527f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c983528b60208401528a60408401528960608401528060808401528860a084015260c08320604e526042602c206000528760ff1660205286604052856060526020806080600060015afa8c3d511461254d5763ddafbaef6000526004601cfd5b0190556303faf4f960a51b89176040526034602c20889055888a7f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925602060608501a36040525050600060605250505050505050565b60006127108461ffff1611156125ed5760405162461bcd60e51b815260206004820152601060248201526f496e76616c696420736c69707061676560801b604482015260640161094d565b600061271061260961ffff87166001600160a01b038716615acc565b6126139190615ae3565b90506000836126345761262f826001600160a01b038716615af7565b612647565b612647826001600160a01b03871661573c565b90508060000361265c57600092505050612705565b83156126ba576001600160801b0381101561269f5761269661267f600283615bee565b61268e6002600160601b615bee565b899190613e88565b92505050612705565b61269681600160601b6126b38a8383613e88565b9190613e88565b6001600160801b038110156126e6576126966126db6002600160601b615bee565b61268e600284615bee565b612696670de0b6b3a7640000826126b3600160601b82828d8387613e88565b949350505050565b6008546001600160a01b0316156127775760405162461bcd60e51b815260206004820152602860248201527f4b6f6469616b49736c616e6453746f726167653a20616c726561647920696e696044820152671d1a585b1a5e995960c21b606482015260840161094d565b6127108561ffff16111561279d5760405162461bcd60e51b815260040161094d9061563c565b600580546001600160a01b03199081163317909155600880546001600160a01b03891692168217905560408051630dfe168160e01b81529051630dfe1681916004808201926020929091908290030181865afa158015612801573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128259190615986565b600980546001600160a01b0319166001600160a01b039283161790556008546040805163d21220a760e01b81529051919092169163d21220a79160048083019260209291908290030181865afa158015612883573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128a79190615986565b600a80546001600160a01b03199081166001600160a01b03938416179091556000805482168584161790556004805490911691831691909117905560038054607d603a1b65ffffffffffff60481b19909116600160681b61ffff89160263ffffffff60481b191617604b604a1b1768ffff000000ffffff00191661010062ffffff88811691909102919091179190911762ffffff60201b1916600160201b91861691909102179055600161295b8982615c4b565b5060026129688882615c4b565b50612971611212565b5050505050505050565b600061298561309e565b905090565b6000546001600160a01b031633146129b45760405162461bcd60e51b815260040161094d906155fa565b6001600160a01b038116612a265760405162461bcd60e51b815260206004820152603360248201527f4f776e61626c653a2063616c6c2072656e6f756e63654f776e65727368697020604482015272746f20736574207a65726f206164647265737360681b606482015260840161094d565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6008546001600160a01b03163314612aab5760405162461bcd60e51b815260040161094d90615aa3565b6000841315612ad057600954612acb906001600160a01b0316338661397b565b612411565b600083131561241157600a54612411906001600160a01b0316338561397b565b6000806000612afd613056565b3068929eee149b4bd212685403612b1c5763ab143c066000526004601cfd5b3068929eee149b4bd212685560008511612b615760405162461bcd60e51b815260206004820152600660248201526506275726e20360d41b604482015260640161094d565b6000612b746805345cdf77eb68f44c5490565b6008549091506000906001600160a01b031663514ea4bf612b9361309e565b6040518263ffffffff1660e01b8152600401612bb191815260200190565b60a060405180830381865afa158015612bce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bf291906156b6565b505050509050612c023388613f36565b6000612c1888836001600160801b031685613e88565b9050612c2381613a61565b600354909450600090819081908190612c50906101008104600290810b91600160201b9004900b8a6130fc565b9350935093509350612c628282613263565b6006546009546040516370a0823160e01b8152612cf8929187916001600160a01b03909116906370a0823190612c9c903090600401614f7b565b602060405180830381865afa158015612cb9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cdd919061570d565b612ce7919061573c565b612cf1919061573c565b8d89613e88565b612d029085615af7565b600754600a546040516370a0823160e01b8152929c50612d3c9286916001600160a01b0316906370a0823190612c9c903090600401614f7b565b612d469084615af7565b98508915612d6557600954612d65906001600160a01b03168c8c61397b565b8815612d8257600a54612d82906001600160a01b03168c8b61397b565b7f7239dff1718b550db7f36cbf69c665cfeb56d0e96b4fb76a5cba712961b655098b8d8c8c8c604051612db9959493929190615a6c565b60405180910390a1505050505050503868929eee149b4bd21268559250925092565b6008546000908190819081908190819081906001600160a01b031663514ea4bf612e0361309e565b6040518263ffffffff1660e01b8152600401612e2191815260200190565b60a060405180830381865afa158015612e3e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e6291906156b6565b94509450945094509450612ea789612e8b600360019054906101000a900460020b60020b613427565b600354612ea190600160201b900460020b613427565b88613ace565b909750955060006001600160801b038316612ec56001878c8a613f9b565b612ecf9190615af7565b90506000826001600160801b0316612eea6000878d8b613f9b565b612ef49190615af7565b9050612f1182826003600d9054906101000a900461ffff16614333565b6006546009546040516370a0823160e01b8152939550919350916001600160a01b03909116906370a0823190612f4b903090600401614f7b565b602060405180830381865afa158015612f68573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f8c919061570d565b612f969084615af7565b612fa0919061573c565b612faa908a615af7565b600754600a546040516370a0823160e01b8152929b5090916001600160a01b03909116906370a0823190612fe2903090600401614f7b565b602060405180830381865afa158015612fff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613023919061570d565b61302d9083615af7565b613037919061573c565b6130419089615af7565b9750505050505050509250929050565b505050565b61305e611191565b15610fab5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015260640161094d565b6003546040516bffffffffffffffffffffffff193060601b166020820152610100820460e890811b6034830152600160201b90920490911b6037820152600090603a0160405160208183030381529060405280519060200120905090565b60085460405163a34123a760e01b8152600285810b600483015284900b60248201526001600160801b03831660448201526000918291829182916001600160a01b039091169063a34123a79060640160408051808303816000875af1158015613169573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061318d9190615a48565b6008546040516309e3d67b60e31b815230600482015260028b810b60248301528a900b60448201526001600160801b0360648201819052608482015292965090945060009182916001600160a01b031690634f1eb3d89060a40160408051808303816000875af1158015613205573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132299190615d0a565b9092509050613241866001600160801b03841661573c565b9350613256856001600160801b03831661573c565b9250505093509350935093565b600354600160681b900461ffff16801561332f5761271061328861ffff831685615acc565b6132929190615ae3565b600660008282546132a39190615af7565b9091555061271090506132ba61ffff831684615acc565b6132c49190615ae3565b600760008282546132d59190615af7565b9091555060009050806132e9858585614333565b60408051838152602081018390529294509092507fc28ad1de9c0c32e5394ba60323e44d8d9536312236a47231772e448a3e49de42910160405180910390a15050505050565b60408051848152602081018490527fc28ad1de9c0c32e5394ba60323e44d8d9536312236a47231772e448a3e49de42910160405180910390a1505050565b6133798787878761438c565b909550935060006133ad61271084846133925787613394565b885b61339e9190615acc565b6133a89190615ae3565b6144ee565b90506000811315612971576133c58686838786614558565b90965094506133d68888888861438c565b50505050505050505050565b6133ea61462d565b6000805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516113989190614f7b565b60008060008360020b1261343e578260020b61344b565b8260020b61344b90615d3d565b905061345a620d89e719615d59565b60020b8111156134905760405162461bcd60e51b81526020600482015260016024820152601560fa1b604482015260640161094d565b6000816001166000036134a757600160801b6134b9565b6ffffcb933bd6fad37aa2d162d1a5940015b6001600160881b0316905060028216156134ee5760806134e9826ffff97272373d413259a46990580e213a615acc565b901c90505b6004821615613518576080613513826ffff2e50f5f656932ef12357cf3c7fdcc615acc565b901c90505b600882161561354257608061353d826fffe5caca7e10e4e61c3624eaa0941cd0615acc565b901c90505b601082161561356c576080613567826fffcb9843d60f6159c9db58835c926644615acc565b901c90505b6020821615613596576080613591826fff973b41fa98c081472e6896dfb254c0615acc565b901c90505b60408216156135c05760806135bb826fff2ea16466c96a3843ec78b326b52861615acc565b901c90505b60808216156135ea5760806135e5826ffe5dee046a99a2a811c461f1969c3053615acc565b901c90505b610100821615613615576080613610826ffcbe86c7900a88aedcffc83b479aa3a4615acc565b901c90505b61020082161561364057608061363b826ff987a7253ac413176f2b074cf7815e54615acc565b901c90505b61040082161561366b576080613666826ff3392b0822b70005940c7a398e4b70f3615acc565b901c90505b610800821615613696576080613691826fe7159475a2c29b7443b29c7fa6e889d9615acc565b901c90505b6110008216156136c15760806136bc826fd097f3bdfd2022b8845ad8f792aa5825615acc565b901c90505b6120008216156136ec5760806136e7826fa9f746462d870fdf8a65dc1f90e061e5615acc565b901c90505b614000821615613717576080613712826f70d869a156d2a1b890bb3df62baf32f7615acc565b901c90505b61800082161561374257608061373d826f31be135f97d08fd981231505542fcfa6615acc565b901c90505b6201000082161561376e576080613769826f09aa508b5b7a84e1c677de54f3e99bc9615acc565b901c90505b62020000821615613799576080613794826e5d6af8dedb81196699c329225ee604615acc565b901c90505b620400008216156137c35760806137be826d2216e584f5fa1ea926041bedfe98615acc565b901c90505b620800008216156137eb5760806137e6826b048a170391f7dc42444e8fa2615acc565b901c90505b60008460020b13156138065761380381600019615ae3565b90505b613814600160201b82615d7b565b15613820576001613823565b60005b6127059060ff16602083901c615af7565b6003546101008104600290810b91600160201b9004900b6000806138598484836130fc565b9350935050506138698282613263565b6006546009546040516370a0823160e01b8152600092916001600160a01b0316906370a082319061389e903090600401614f7b565b602060405180830381865afa1580156138bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138df919061570d565b6138e9919061573c565b600754600a546040516370a0823160e01b81529293506000926001600160a01b03909116906370a0823190613922903090600401614f7b565b602060405180830381865afa15801561393f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613963919061570d565b61396d919061573c565b90506129718686848461438c565b6040516001600160a01b03831660248201526044810182905261305190849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614678565b6139e6613056565b6000805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861341a3390565b6000613a2e848484613e88565b905060008280613a4057613a40615970565b8486091115610b71576000198110613a5757600080fd5b8061118881615d8f565b60006001600160801b03821115613aca5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b606482015260840161094d565b5090565b600080836001600160a01b0316856001600160a01b03161115613aef579293925b846001600160a01b0316866001600160a01b03161015613b1b57613b1485858561474d565b9150613b62565b836001600160a01b0316866001600160a01b03161015613b5457613b4086858561474d565b9150613b4d8587856147b7565b9050613b62565b613b5f8585856147b7565b90505b94509492505050565b6805345cdf77eb68f44c5481810181811015613b8f5763e5cfe9576000526004601cfd5b806805345cdf77eb68f44c5550506387a211a2600c52816000526020600c208181540181555080602052600c5160601c6000600080516020615f3b833981519152602080a35050565b6040516001600160a01b03808516602483015283166044820152606481018290526124119085906323b872dd60e01b906084016139a7565b6000836001600160a01b0316856001600160a01b03161115613c30579293925b846001600160a01b0316866001600160a01b03161015613c5c57613c55858585614801565b9050611188565b836001600160a01b0316866001600160a01b03161015613cbe576000613c83878686614801565b90506000613c9287898661486b565b9050806001600160801b0316826001600160801b031610613cb35780613cb5565b815b92505050611188565b613cc985858461486b565b9695505050505050565b6000806000806000613ce3610889565b91509150816000148015613cf75750600081115b15613d0e57613d07868983613e88565b9250613dbd565b80158015613d1c5750600082115b15613d2c57613d07878984613e88565b81158015613d38575080155b15613d5f5760405162461bcd60e51b8152602060048201526000602482015260440161094d565b6000613d6c888a85613e88565b90506000613d7b888b85613e88565b9050600082118015613d8d5750600081115b613da95760405162461bcd60e51b815260040161094d906159e6565b808210613db65780613db8565b815b945050505b613dc883838a613a21565b9450613dd583828a613a21565b9350505093509350939050565b613dee8585858561438c565b9093509150602081013515613e8157613e0d60808201606083016150f4565b613e175781613e19565b825b81602001351115613e625760405162461bcd60e51b81526020600482015260136024820152725377617020616d6f756e7420746f6f2062696760681b604482015260640161094d565b613e6d8383836148a1565b9093509150613e7e8585858561438c565b50505b5050505050565b6000808060001985870985870292508281108382030391505080600003613ec15760008411613eb657600080fd5b508290049050610b71565b808411613ecd57600080fd5b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b6387a211a2600c52816000526020600c20805480831115613f5f5763f4d678b86000526004601cfd5b82900390556805345cdf77eb68f44c8054829003905560008181526001600160a01b038316600080516020615f3b833981519152602083a35050565b600080600080871561413257600860009054906101000a90046001600160a01b03166001600160a01b031663f30583996040518163ffffffff1660e01b8152600401602060405180830381865afa158015613ffa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061401e919061570d565b60085460035460405163f30dba9360e01b815261010090910460020b60048201529192506001600160a01b03169063f30dba939060240161010060405180830381865afa158015614073573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140979190615da8565b505060085460035460405163f30dba9360e01b8152959a506001600160a01b03909116965063f30dba9395506140e094600160201b90910460020b9350600401915061514a9050565b61010060405180830381865afa1580156140fe573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141229190615da8565b509397506142b795505050505050565b600860009054906101000a90046001600160a01b03166001600160a01b031663461413196040518163ffffffff1660e01b8152600401602060405180830381865afa158015614185573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141a9919061570d565b60085460035460405163f30dba9360e01b815261010090910460020b60048201529192506001600160a01b03169063f30dba939060240161010060405180830381865afa1580156141fe573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142229190615da8565b505060085460035460405163f30dba9360e01b8152949a506001600160a01b03909116965063f30dba93955061426a9450600160201b900460020b92600401915061514a9050565b61010060405180830381865afa158015614288573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142ac9190615da8565b509297505050505050505b6003546000906101009004600290810b9088900b126142d75750826142dc565b508281035b600354600090600160201b9004600290810b9089900b12156142ff575082614304565b508282035b8183038190036143246001600160801b0389168b8303600160801b613e88565b9b9a5050505050505050505050565b60008061271061434761ffff851687615acc565b6143519190615ae3565b61435b908661573c565b915061271061436e61ffff851686615acc565b6143789190615ae3565b614382908561573c565b9050935093915050565b6000806000600860009054906101000a90046001600160a01b03166001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156143e4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614408919061555e565b50505050505090506000614435826144228a60020b613427565b61442e8a60020b613427565b8989613c10565b90506001600160801b038116156144e357600854604051633c8a7d8d60e01b815260009182916001600160a01b0390911690633c8a7d8d906144819030908e908e908990600401615a06565b60408051808303816000875af115801561449f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144c39190615a48565b90925090506144d2828961573c565b95506144de818861573c565b945050505b505094509492505050565b60006001600160ff1b03821115613aca5760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b606482015260840161094d565b600854604051630251596160e31b81523060048201528215156024820152604481018590526001600160a01b03848116606483015260a06084830152600060a4830181905292839283928392169063128acb089060c40160408051808303816000875af11580156145cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145f19190615a48565b91509150816145ff8a6144ee565b6146099190615e44565b935080614615896144ee565b61461f9190615e44565b925050509550959350505050565b614635611191565b610fab5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015260640161094d565b60006146cd826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614c689092919063ffffffff16565b90508051600014806146ee5750808060200190518101906146ee9190615e6b565b6130515760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161094d565b6000826001600160a01b0316846001600160a01b0316111561476d579192915b6001600160a01b0384166147ad600160601b600160e01b03606085901b166147958787615e88565b6001600160a01b0316866001600160a01b0316613e88565b6127059190615ae3565b6000826001600160a01b0316846001600160a01b031611156147d7579192915b6127056001600160801b0383166147ee8686615e88565b6001600160a01b0316600160601b613e88565b6000826001600160a01b0316846001600160a01b03161115614821579192915b6000614844856001600160a01b0316856001600160a01b0316600160601b613e88565b905061118861486684836148588989615e88565b6001600160a01b0316613e88565b614c77565b6000826001600160a01b0316846001600160a01b0316111561488b579192915b61270561486683600160601b6148588888615e88565b600080806148b560808501606086016150f4565b6148ca57600a546001600160a01b03166148d7565b6009546001600160a01b03165b905060006148eb60808601606087016150f4565b614900576009546001600160a01b031661490d565b600a546001600160a01b03165b90506000826001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161493d9190614f7b565b602060405180830381865afa15801561495a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061497e919061570d565b90506000826001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016149ae9190614f7b565b602060405180830381865afa1580156149cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906149ef919061570d565b9050614a16614a016020890189614f5e565b6001600160a01b0386169060208a0135614c92565b6000614a256020890189614f5e565b6001600160a01b0316614a3b60808a018a615ea8565b604051614a49929190615eee565b6000604051808303816000865af19150503d8060008114614a86576040519150601f19603f3d011682016040523d82523d6000602084013e614a8b565b606091505b5050905080614aca5760405162461bcd60e51b815260206004820152600b60248201526a1cddd85c0819985a5b195960aa1b604482015260640161094d565b6040516370a0823160e01b81526000906001600160a01b038716906370a0823190614af9903090600401614f7b565b602060405180830381865afa158015614b16573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614b3a919061570d565b614b44908561573c565b9050600083866001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401614b759190614f7b565b602060405180830381865afa158015614b92573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614bb6919061570d565b614bc0919061573c565b90508960400135811015614c0e5760405162461bcd60e51b81526020600482015260156024820152741a5b9cdd59999a58da595b9d081d1bdad95b93dd5d605a1b604482015260640161094d565b614c1e60808b0160608c016150f4565b15614c4057614c2d828d61573c565b9850614c39818c615af7565b9750614c59565b614c4a818d615af7565b9850614c56828c61573c565b97505b50505050505050935093915050565b60606127058484600085614d3f565b806001600160801b0381168114614c8d57600080fd5b919050565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa158015614ce2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614d06919061570d565b90506124118463095ea7b360e01b85614d1f8686615af7565b6040516001600160a01b03909216602483015260448201526064016139a7565b606082471015614da05760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161094d565b600080866001600160a01b03168587604051614dbc9190615efe565b60006040518083038185875af1925050503d8060008114614df9576040519150601f19603f3d011682016040523d82523d6000602084013e614dfe565b606091505b5091509150614e0f87838387614e1a565b979650505050505050565b60608315614e89578251600003614e82576001600160a01b0385163b614e825760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161094d565b5081612705565b6127058383815115614e9e5781518083602001fd5b8060405162461bcd60e51b815260040161094d9190614edc565b60005b83811015614ed3578181015183820152602001614ebb565b50506000910152565b6020815260008251806020840152614efb816040850160208701614eb8565b601f01601f19169190910160400192915050565b6001600160a01b0381168114614f2457600080fd5b50565b8035614c8d81614f0f565b60008060408385031215614f4557600080fd5b8235614f5081614f0f565b946020939093013593505050565b600060208284031215614f7057600080fd5b8135610b7181614f0f565b6001600160a01b0391909116815260200190565b8035600181900b8114614c8d57600080fd5b60008060008060808587031215614fb757600080fd5b614fc085614f8f565b93506020850135614fd081614f0f565b9250614fde60408601614f8f565b915060608501358060030b8114614ff457600080fd5b939692955090935050565b60008060006060848603121561501457600080fd5b833561501f81614f0f565b9250602084013561502f81614f0f565b929592945050506040919091013590565b8060020b8114614f2457600080fd5b8015158114614f2457600080fd5b600080600080600060a0868803121561507557600080fd5b853561508081615040565b9450602086013561509081615040565b935060408601356150a081614f0f565b92506060860135915060808601356150b78161504f565b809150509295509295909350565b63ffffffff81168114614f2457600080fd5b6000602082840312156150e957600080fd5b8135610b71816150c5565b60006020828403121561510657600080fd5b8135610b718161504f565b6000806040838503121561512457600080fd5b823561512f81614f0f565b9150602083013561513f8161504f565b809150509250929050565b60029190910b815260200190565b6000806040838503121561516b57600080fd5b82359150602083013561513f81614f0f565b6000806040838503121561519057600080fd5b50508035926020909101359150565b6000806000606084860312156151b457600080fd5b83356151bf81615040565b925060208401356151cf81615040565b915060408401356001600160401b038111156151ea57600080fd5b840160a081870312156151fc57600080fd5b809150509250925092565b60008083601f84011261521957600080fd5b5081356001600160401b0381111561523057600080fd5b60208301915083602082850101111561524857600080fd5b9250929050565b6000806000806060858703121561526557600080fd5b843593506020850135925060408501356001600160401b0381111561528957600080fd5b61529587828801615207565b95989497509550505050565b600080600080600080600060e0888a0312156152bc57600080fd5b87356152c781614f0f565b965060208801356152d781614f0f565b95506040880135945060608801359350608088013560ff811681146152fb57600080fd5b9699959850939692959460a0840135945060c09093013592915050565b61ffff81168114614f2457600080fd5b6000806000806080858703121561533e57600080fd5b84359350602085013561535081615318565b9250604085013561536081614f0f565b91506060850135614ff48161504f565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156153ae576153ae615370565b604052919050565b600082601f8301126153c757600080fd5b81356001600160401b038111156153e0576153e0615370565b6153f3601f8201601f1916602001615386565b81815284602083860101111561540857600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600080600080610100898b03121561544257600080fd5b88356001600160401b038082111561545957600080fd5b6154658c838d016153b6565b995060208b013591508082111561547b57600080fd5b506154888b828c016153b6565b975050604089013561549981614f0f565b955060608901356154a981615318565b945060808901356154b981615040565b935060a08901356154c981615040565b925060c08901356154d981614f0f565b91506154e760e08a01614f27565b90509295985092959890939650565b6000806040838503121561550957600080fd5b823561551481614f0f565b9150602083013561513f81614f0f565b600181811c9082168061553857607f821691505b60208210810361555857634e487b7160e01b600052602260045260246000fd5b50919050565b600080600080600080600060e0888a03121561557957600080fd5b875161558481614f0f565b602089015190975061559581615040565b60408901519096506155a681615318565b60608901519095506155b781615318565b60808901519094506155c881615318565b60a08901519093506155d9816150c5565b60c08901519092506155ea8161504f565b8091505092959891949750929550565b60208082526022908201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206d616e616760408201526132b960f11b606082015260800190565b6020808252601690820152750dac2dcc2cecae48ccaca84e0e640deeccae440dac2f60531b604082015260600190565b61ffff94851681526001600160a01b039390931660208401529216604082015263ffffffff909116606082015260800190565b80516001600160801b0381168114614c8d57600080fd5b600080600080600060a086880312156156ce57600080fd5b6156d78661569f565b945060208601519350604086015192506156f36060870161569f565b91506157016080870161569f565b90509295509295909350565b60006020828403121561571f57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561088357610883615726565b6020808252600e908201526d06e657720706f736974696f6e20360941b604082015260600190565b600294850b81529290930b60208301526001600160801b039081166040830152909116606082015260800190565b634e487b7160e01b600052603260045260246000fd5b6020808252825182820181905260009190848201906040850190845b818110156157f957835163ffffffff16835292840192918401916001016157d7565b50909695505050505050565b60006001600160401b0382111561581e5761581e615370565b5060051b60200190565b8051600681900b8114614c8d57600080fd5b600082601f83011261584b57600080fd5b8151602061586061585b83615805565b615386565b82815260059290921b8401810191818101908684111561587f57600080fd5b8286015b848110156158a357805161589681614f0f565b8352918301918301615883565b509695505050505050565b600080604083850312156158c157600080fd5b82516001600160401b03808211156158d857600080fd5b818501915085601f8301126158ec57600080fd5b815160206158fc61585b83615805565b82815260059290921b8401810191818101908984111561591b57600080fd5b948201945b838610156159405761593186615828565b82529482019490820190615920565b9188015191965090935050508082111561595957600080fd5b506159668582860161583a565b9150509250929050565b634e487b7160e01b600052601260045260246000fd5b60006020828403121561599857600080fd5b8151610b7181614f0f565b6000602082840312156159b557600080fd5b8151610b7181615318565b6020808252600c908201526b5a65726f206164647265737360a01b604082015260600190565b60208082526006908201526506d696e7420360d41b604082015260600190565b6001600160a01b03949094168452600292830b6020850152910b60408301526001600160801b0316606082015260a06080820181905260009082015260c00190565b60008060408385031215615a5b57600080fd5b505080516020909101519092909150565b6001600160a01b039590951685526020850193909352604084019190915260608301526001600160801b0316608082015260a00190565b6020808252600f908201526e31b0b6363130b1b59031b0b63632b960891b604082015260600190565b808202811582820484141761088357610883615726565b600082615af257615af2615970565b500490565b8082018082111561088357610883615726565b600181815b80851115615b45578160001904821115615b2b57615b2b615726565b80851615615b3857918102915b93841c9390800290615b0f565b509250929050565b600082615b5c57506001610883565b81615b6957506000610883565b8160018114615b7f5760028114615b8957615ba5565b6001915050610883565b60ff841115615b9a57615b9a615726565b50506001821b610883565b5060208310610133831016604e8410600b8410161715615bc8575081810a610883565b615bd28383615b0a565b8060001904821115615be657615be6615726565b029392505050565b6000610b7160ff841683615b4d565b601f82111561305157600081815260208120601f850160051c81016020861015615c245750805b601f850160051c820191505b81811015615c4357828155600101615c30565b505050505050565b81516001600160401b03811115615c6457615c64615370565b615c7881615c728454615524565b84615bfd565b602080601f831160018114615cad5760008415615c955750858301515b600019600386901b1c1916600185901b178555615c43565b600085815260208120601f198616915b82811015615cdc57888601518255948401946001909101908401615cbd565b5085821015615cfa5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60008060408385031215615d1d57600080fd5b615d268361569f565b9150615d346020840161569f565b90509250929050565b6000600160ff1b8201615d5257615d52615726565b5060000390565b60008160020b627fffff198103615d7257615d72615726565b60000392915050565b600082615d8a57615d8a615970565b500690565b600060018201615da157615da1615726565b5060010190565b600080600080600080600080610100898b031215615dc557600080fd5b615dce8961569f565b9750602089015180600f0b8114615de457600080fd5b60408a015160608b015191985096509450615e0160808a01615828565b935060a0890151615e1181614f0f565b60c08a0151909350615e22816150c5565b60e08a0151909250615e338161504f565b809150509295985092959890939650565b8181036000831280158383131683831282161715615e6457615e64615726565b5092915050565b600060208284031215615e7d57600080fd5b8151610b718161504f565b6001600160a01b03828116828216039080821115615e6457615e64615726565b6000808335601e19843603018112615ebf57600080fd5b8301803591506001600160401b03821115615ed957600080fd5b60200191503681900382131561524857600080fd5b8183823760009101908152919050565b60008251615f10818460208701614eb8565b919091019291505056feff52cb3b4d8fbd8cdf8f14ffefacf8704a332a0167fd0fc3c804ead362430d85ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa264697066735822122063adbc4a67e6f962ba8ce94d947fa4b984a605a3ae8642611127a0a6fe325aac64736f6c63430008130033
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106102ed5760003560e01c80637d7c2a1c11610193578063cc95353e116100e4578063db812fd011610092578063db812fd014610711578063dcf0ff2814610724578063dd62ed3e14610739578063df28408a14610762578063f2fde38b1461076a578063fa461e331461077d578063fcd3533c1461079057600080fd5b8063cc95353e14610677578063ccdf7a021461068a578063d1c122ea146106b2578063d21220a7146106c5578063d3487997146106d8578063d505accf146106eb578063d8329c35146106fe57600080fd5b806399e7061b1161014157806399e7061b146105e95780639b1344ac1461060c578063a9059cbb1461061e578063b670ed7d14610631578063c3c6467414610644578063c7a4ae1714610657578063cbddcbc31461066457600080fd5b80637d7c2a1c1461053e5780637ecd6717146105465780637ecebe001461054e5780638456cb591461057457806394bf804d1461057c57806395d89b41146105b35780639894f21a146105bb57600080fd5b8063385033451161024d5780635e6663cc116101fb5780635e6663cc146104a857806367582f4a146104bb578063688f7218146104ce57806370a08231146104d6578063715018a6146104fc5780637180c8ca14610504578063727dd2281461051757600080fd5b8063385033451461041b5780633f4ba83a1461044757806342fb9d441461044f578063481c6a751461045857806351a2dc921461046957806354fd4d501461047c5780635c975abb146104a057600080fd5b806316f0115b116102aa57806316f0115b146103a657806318160ddd146103b957806318e91fb5146103c957806323b872dd146103de57806324b8fd1b146103f1578063313ce567146104045780633644e5151461041357600080fd5b8063065756db146102f257806306fdde031461030e578063095ea7b3146103235780630a1289ad146103465780630dfe1681146103695780631322d95414610389575b600080fd5b6102fb60065481565b6040519081526020015b60405180910390f35b6103166107a3565b6040516103059190614edc565b610336610331366004614f32565b610835565b6040519015158152602001610305565b610336610354366004614f5e565b600b6020526000908152604090205460ff1681565b60095461037c906001600160a01b031681565b6040516103059190614f7b565b610391610889565b60408051928352602083019190915201610305565b60085461037c906001600160a01b031681565b6805345cdf77eb68f44c546102fb565b6103dc6103d7366004614fa1565b610923565b005b6103366103ec366004614fff565b610acd565b6103dc6103ff36600461505d565b610b78565b60405160128152602001610305565b6102fb610efc565b60035461043290600160481b900463ffffffff1681565b60405163ffffffff9091168152602001610305565b6103dc610f79565b6102fb60075481565b6000546001600160a01b031661037c565b61037c6104773660046150d7565b610fad565b610316604051806040016040528060058152602001640312e302e360dc1b81525081565b610336611191565b6000546001600160a01b03161515610336565b6103dc6104c93660046150f4565b6111a1565b6103dc611212565b6102fb6104e4366004614f5e565b6387a211a2600c908152600091909152602090205490565b6103dc6113a2565b6103dc610512366004615111565b611533565b60035461052b90600160201b900460020b81565b60405160029190910b8152602001610305565b6103dc6115e3565b6103dc61178b565b6102fb61055c366004614f5e565b6338377508600c908152600091909152602090205490565b6103dc6117e7565b61058f61058a366004615158565b6118dc565b6040805193845260208401929092526001600160801b031690820152606001610305565b610316611c2e565b6105ce6105c936600461517d565b611c3d565b60408051938452602084019290925290820152606001610305565b6103366105f7366004614f5e565b600c6020526000908152604090205460ff1681565b60035461052b90610100900460020b81565b61033661062c366004614f32565b611d7c565b61039161063f366004614f5e565b611de5565b6103dc610652366004615111565b611e7d565b6003546103369060ff1681565b60055461037c906001600160a01b031681565b60045461037c906001600160a01b031681565b60035461069f90600160681b900461ffff1681565b60405161ffff9091168152602001610305565b6103dc6106c036600461519f565b611f25565b600a5461037c906001600160a01b031681565b6103dc6106e636600461524f565b6123ad565b6103dc6106f93660046152a1565b612417565b6102fb61070c366004615328565b6125a2565b6103dc61071f366004615425565b61270d565b60035461069f90600160381b900461ffff1681565b6102fb6107473660046154f6565b602052637f5e9f20600c908152600091909152603490205490565b6102fb61297b565b6103dc610778366004614f5e565b61298a565b6103dc61078b36600461524f565b612a81565b61058f61079e366004615158565b612af0565b6060600180546107b290615524565b80601f01602080910402602001604051908101604052809291908181526020018280546107de90615524565b801561082b5780601f106108005761010080835404028352916020019161082b565b820191906000526020600020905b81548152906001019060200180831161080e57829003601f168201915b5050505050905090565b600082602052637f5e9f20600c5233600052816034600c205581600052602c5160601c337f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560206000a35060015b92915050565b600080600080600860009054906101000a90046001600160a01b03166001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156108e2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610906919061555e565b5050505050915091506109198282612ddb565b9350935050509091565b6000546001600160a01b031633146109565760405162461bcd60e51b815260040161094d906155fa565b60405180910390fd5b6127108260010b13156109915760405162461bcd60e51b815260206004820152600360248201526242505360e81b604482015260640161094d565b6127108460010b13156109b65760405162461bcd60e51b815260040161094d9061563c565b60008460010b126109dc576003805461ffff60681b1916600160681b61ffff8716021790555b6001600160a01b03831615610a0757600480546001600160a01b0319166001600160a01b0385161790555b60008260010b12610a2d576003805461ffff60381b1916600160381b61ffff8516021790555b60008160030b12610a57576003805463ffffffff60481b1916600160481b63ffffffff8416021790555b6003546004546040517fd61f3e2d0a1abe8c7a06f409e2069f4ba0ad684d8dcb174b9101f0bccf5e283f92610abf92600160681b820461ffff908116936001600160a01b0390921692600160381b810490911691600160481b90910463ffffffff169061566c565b60405180910390a150505050565b60008360601b33602052637f5e9f208117600c526034600c208054801915610b0b5780851115610b05576313be252b6000526004601cfd5b84810382555b50506387a211a28117600c526020600c20805480851115610b345763f4d678b86000526004601cfd5b84810382555050836000526020600c208381540181555082602052600c5160601c8160601c600080516020615f3b833981519152602080a3505060015b9392505050565b610b80613056565b6000546001600160a01b03163314610baa5760405162461bcd60e51b815260040161094d906155fa565b6000806000610bc06805345cdf77eb68f44c5490565b1115610e86576008546001600160a01b031663514ea4bf610bdf61309e565b6040518263ffffffff1660e01b8152600401610bfd91815260200190565b60a060405180830381865afa158015610c1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c3e91906156b6565b5092945050506001600160801b038316159050610c8e576003546000908190610c7b906101008104600290810b91600160201b9004900b866130fc565b935093505050610c8b8282613263565b50505b6003805462ffffff888116600160201b0262ffffff60201b19918b16610100029190911666ffffffffffff0019909216919091171790556006546009546040516370a0823160e01b8152600092916001600160a01b0316906370a0823190610cfa903090600401614f7b565b602060405180830381865afa158015610d17573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d3b919061570d565b610d45919061573c565b600754600a546040516370a0823160e01b81529293506000926001600160a01b03909116906370a0823190610d7e903090600401614f7b565b602060405180830381865afa158015610d9b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dbf919061570d565b610dc9919061573c565b9050610dda898984848b8b8b61336d565b6008546001600160a01b031663514ea4bf610df361309e565b6040518263ffffffff1660e01b8152600401610e1191815260200190565b60a060405180830381865afa158015610e2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e5291906156b6565b509295505050506001600160801b038316610e7f5760405162461bcd60e51b815260040161094d9061574f565b5050610ebe565b6003805462ffffff888116600160201b0262ffffff60201b19918b16610100029190911666ffffffffffff0019909216919091171790555b336001600160a01b0316600080516020615f1b83398151915288888585604051610eeb9493929190615777565b60405180910390a250505050505050565b600080610f076107a3565b805190602001209050604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f815260208101929092527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc69082015246606082015230608082015260a09020919050565b6000546001600160a01b03163314610fa35760405162461bcd60e51b815260040161094d906155fa565b610fab6133e2565b565b6000808263ffffffff1611610ff75760405162461bcd60e51b815260206004820152601060248201526f125b9d985b1a59081a5b9d195c9d985b60821b604482015260640161094d565b604080516002808252606082018352600092602083019080368337019050509050828160008151811061102c5761102c6157a5565b602002602001019063ffffffff16908163ffffffff168152505060008160018151811061105b5761105b6157a5565b63ffffffff9092166020928302919091019091015260085460405163883bdbfd60e01b81526000916001600160a01b03169063883bdbfd906110a19085906004016157bb565b600060405180830381865afa1580156110be573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526110e691908101906158ae565b50905080516002146111265760405162461bcd60e51b815260206004820152600960248201526830b93930bc903632b760b91b604482015260640161094d565b60008463ffffffff1660060b82600081518110611145576111456157a5565b602002602001015183600181518110611160576111606157a5565b60200260200101510360060b8161117957611179615970565b0590506111888160020b613427565b95945050505050565b600054600160a01b900460ff1690565b6000546001600160a01b031633146111cb5760405162461bcd60e51b815260040161094d906155fa565b6003805460ff19168215159081179091556040519081527f466ad1943abf95179c60a8c1ab56e7ba1467e287ca7d923b7d98965bc382c8f69060200160405180910390a150565b6000546001600160a01b0316610fab57600560009054906101000a90046001600160a01b03166001600160a01b03166361d027b36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611275573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112999190615986565b600480546001600160a01b0319166001600160a01b0392831617815560055460408051630bdb371360e11b8152905191909316926317b66e2692818101926020929091908290030181865afa1580156112f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061131a91906159a3565b6003805461ffff60681b1916600160681b61ffff938416810291909117918290556004546040517fd61f3e2d0a1abe8c7a06f409e2069f4ba0ad684d8dcb174b9101f0bccf5e283f94611398949384048116936001600160a01b0390931692600160381b810490911691600160481b90910463ffffffff169061566c565b60405180910390a1565b6113aa613056565b6000546001600160a01b031633146113d45760405162461bcd60e51b815260040161094d906155fa565b600560009054906101000a90046001600160a01b03166001600160a01b03166361d027b36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611427573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061144b9190615986565b600480546001600160a01b0319166001600160a01b0392831617815560055460408051630bdb371360e11b8152905191909316926317b66e2692818101926020929091908290030181865afa1580156114a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114cc91906159a3565b6003805461ffff92909216600160681b0261ffff60681b1990921691909117905560006006819055600781905580546001600160a01b031916815560405181907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3565b6000546001600160a01b0316331461155d5760405162461bcd60e51b815260040161094d906155fa565b6001600160a01b0382166115835760405162461bcd60e51b815260040161094d906159c0565b6001600160a01b0382166000818152600b6020908152604091829020805460ff191685151590811790915591519182527fa11b5803b8a35081b8f993e0dee5bc30301a3d83f644e5ab2ff39f972f0a807f91015b60405180910390a25050565b6115eb613056565b6008546000906001600160a01b031663514ea4bf61160761309e565b6040518263ffffffff1660e01b815260040161162591815260200190565b60a060405180830381865afa158015611642573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061166691906156b6565b505050509050611674613834565b6008546000906001600160a01b031663514ea4bf61169061309e565b6040518263ffffffff1660e01b81526004016116ae91815260200190565b60a060405180830381865afa1580156116cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116ef91906156b6565b505050509050816001600160801b0316816001600160801b0316116117505760405162461bcd60e51b81526020600482015260176024820152766c6971756964697479206d75737420696e63726561736560481b604482015260640161094d565b6003546040513391600080516020615f1b833981519152916115d7916101008104600290810b92600160201b909204900b9087908790615777565b60068054600780546000938490559290559081156117c0576004546009546117c0916001600160a01b0391821691168461397b565b80156117e357600454600a546117e3916001600160a01b0391821691168361397b565b5050565b336000908152600b602052604090205460ff168061180f57506000546001600160a01b031633145b6118655760405162461bcd60e51b815260206004820152602160248201527f4f776e61626c653a2063616c6c6572206973206e6f74207468652070617573656044820152603960f91b606482015260840161094d565b6000546001600160a01b03166118d45760405162461bcd60e51b815260206004820152602e60248201527f5061757361626c653a2063616e6e6f7420706175736520776974686f7574206160448201526d103b30b634b21036b0b730b3b2b960911b606482015260840161094d565b610fab6139de565b60008060006118e9613056565b3068929eee149b4bd2126854036119085763ab143c066000526004601cfd5b3068929eee149b4bd212685560035460ff16158061193057506000546001600160a01b031633145b8061194457506000546001600160a01b0316155b61197d5760405162461bcd60e51b815260206004820152600a6024820152691c995cdd1c9a58dd195960b21b604482015260640161094d565b60006119906805345cdf77eb68f44c5490565b90506000600860009054906101000a90046001600160a01b03166001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156119e7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a0b919061555e565b50505050505090506000821115611a6c5760008711611a3c5760405162461bcd60e51b815260040161094d906159e6565b600080611a47610889565b91509150611a56828a86613a21565b9650611a63818a86613a21565b95505050611acb565b600354611aaa908290611a8690610100900460020b613427565b600354611a9c90600160201b900460020b613427565b611aa58b613a61565b613ace565b9095509350611abc60006103e8613b6b565b611ac86103e88861573c565b96505b8415611ae957600954611ae9906001600160a01b0316333088613bd8565b8315611b0757600a54611b07906001600160a01b0316333087613bd8565b600354611b3e908290611b2190610100900460020b613427565b600354611b3790600160201b900460020b613427565b8888613c10565b600854600354604051633c8a7d8d60e01b81529295506001600160a01b0390911691633c8a7d8d91611b8c9130916101008104600290810b92600160201b909204900b908990600401615a06565b60408051808303816000875af1158015611baa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bce9190615a48565b5050611bda8688613b6b565b7f55801cfe493000b734571da1694b21e7f66b11e8ce9fdaa0524ecb59105e73e78688878787604051611c11959493929190615a6c565b60405180910390a150503868929eee149b4bd21268559250925092565b6060600280546107b290615524565b600080600080611c546805345cdf77eb68f44c5490565b90508015611c7357611c67818787613cd3565b91955093509150611d74565b60085460408051633850c7bd60e01b815290516000926001600160a01b031691633850c7bd9160048083019260e09291908290030181865afa158015611cbd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ce1919061555e565b50505050505090506000611d2782611d0a600360019054906101000a900460020b60020b613427565b600354611d2090600160201b900460020b613427565b8b8b613c10565b6003546001600160801b0382169550909150611d6c908390611d5090610100900460020b613427565b600354611d6690600160201b900460020b613427565b84613ace565b909650945050505b509250925092565b60006387a211a2600c52336000526020600c20805480841115611da75763f4d678b86000526004601cfd5b83810382555050826000526020600c208281540181555081602052600c5160601c33600080516020615f3b833981519152602080a350600192915050565b6000806000600860009054906101000a90046001600160a01b03166001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa158015611e3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e61919061555e565b5050505050915050611e738482612ddb565b9250925050915091565b6000546001600160a01b03163314611ea75760405162461bcd60e51b815260040161094d906155fa565b6001600160a01b038216611ecd5760405162461bcd60e51b815260040161094d906159c0565b6001600160a01b0382166000818152600c6020908152604091829020805460ff191685151590811790915591519182527f8443a265af33599abe6c9ed0c3cabd8e2a6c5b8ea35c1d1ed40c513242f95d4591016115d7565b611f2d613056565b6000546001600160a01b03163314611f575760405162461bcd60e51b815260040161094d906155fa565b600c6000611f686020840184614f5e565b6001600160a01b0316815260208101919091526040016000205460ff16611fc75760405162461bcd60e51b81526020600482015260136024820152722ab730baba3437b934bd32b2103937baba32b960691b604482015260640161094d565b60035460009061200990602084013590600160381b810461ffff1690611ff990600160481b900463ffffffff16610fad565b61070c60808701606088016150f4565b90508082604001351161205e5760405162461bcd60e51b815260206004820152601b60248201527f53657420726561736f6e61626c65206d696e416d6f756e744f75740000000000604482015260640161094d565b5060008060006120756805345cdf77eb68f44c5490565b1115612339576008546001600160a01b031663514ea4bf61209461309e565b6040518263ffffffff1660e01b81526004016120b291815260200190565b60a060405180830381865afa1580156120cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120f391906156b6565b5092945050506001600160801b038316159050612143576003546000908190612130906101008104600290810b91600160201b9004900b866130fc565b9350935050506121408282613263565b50505b6003805462ffffff868116600160201b0262ffffff60201b19918916610100029190911666ffffffffffff0019909216919091171790556006546009546040516370a0823160e01b8152600092916001600160a01b0316906370a08231906121af903090600401614f7b565b602060405180830381865afa1580156121cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121f0919061570d565b6121fa919061573c565b600754600a546040516370a0823160e01b81529293506000926001600160a01b03909116906370a0823190612233903090600401614f7b565b602060405180830381865afa158015612250573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612274919061570d565b61227e919061573c565b905061228d8787848489613de2565b6008546001600160a01b031663514ea4bf6122a661309e565b6040518263ffffffff1660e01b81526004016122c491815260200190565b60a060405180830381865afa1580156122e1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061230591906156b6565b509295505050506001600160801b0383166123325760405162461bcd60e51b815260040161094d9061574f565b5050612371565b6003805462ffffff868116600160201b0262ffffff60201b19918916610100029190911666ffffffffffff0019909216919091171790555b336001600160a01b0316600080516020615f1b8339815191528686858560405161239e9493929190615777565b60405180910390a25050505050565b6008546001600160a01b031633146123d75760405162461bcd60e51b815260040161094d90615aa3565b83156123f4576009546123f4906001600160a01b0316338661397b565b821561241157600a54612411906001600160a01b0316338561397b565b50505050565b60006124216107a3565b8051906020012090507fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc64286101561246157631a15a3cc6000526004601cfd5b6040518960601b60601c99508860601b60601c985065383775081901600e52896000526020600c2080547f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f835284602084015283604084015246606084015230608084015260a08320602e527f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c983528b60208401528a60408401528960608401528060808401528860a084015260c08320604e526042602c206000528760ff1660205286604052856060526020806080600060015afa8c3d511461254d5763ddafbaef6000526004601cfd5b0190556303faf4f960a51b89176040526034602c20889055888a7f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925602060608501a36040525050600060605250505050505050565b60006127108461ffff1611156125ed5760405162461bcd60e51b815260206004820152601060248201526f496e76616c696420736c69707061676560801b604482015260640161094d565b600061271061260961ffff87166001600160a01b038716615acc565b6126139190615ae3565b90506000836126345761262f826001600160a01b038716615af7565b612647565b612647826001600160a01b03871661573c565b90508060000361265c57600092505050612705565b83156126ba576001600160801b0381101561269f5761269661267f600283615bee565b61268e6002600160601b615bee565b899190613e88565b92505050612705565b61269681600160601b6126b38a8383613e88565b9190613e88565b6001600160801b038110156126e6576126966126db6002600160601b615bee565b61268e600284615bee565b612696670de0b6b3a7640000826126b3600160601b82828d8387613e88565b949350505050565b6008546001600160a01b0316156127775760405162461bcd60e51b815260206004820152602860248201527f4b6f6469616b49736c616e6453746f726167653a20616c726561647920696e696044820152671d1a585b1a5e995960c21b606482015260840161094d565b6127108561ffff16111561279d5760405162461bcd60e51b815260040161094d9061563c565b600580546001600160a01b03199081163317909155600880546001600160a01b03891692168217905560408051630dfe168160e01b81529051630dfe1681916004808201926020929091908290030181865afa158015612801573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128259190615986565b600980546001600160a01b0319166001600160a01b039283161790556008546040805163d21220a760e01b81529051919092169163d21220a79160048083019260209291908290030181865afa158015612883573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128a79190615986565b600a80546001600160a01b03199081166001600160a01b03938416179091556000805482168584161790556004805490911691831691909117905560038054607d603a1b65ffffffffffff60481b19909116600160681b61ffff89160263ffffffff60481b191617604b604a1b1768ffff000000ffffff00191661010062ffffff88811691909102919091179190911762ffffff60201b1916600160201b91861691909102179055600161295b8982615c4b565b5060026129688882615c4b565b50612971611212565b5050505050505050565b600061298561309e565b905090565b6000546001600160a01b031633146129b45760405162461bcd60e51b815260040161094d906155fa565b6001600160a01b038116612a265760405162461bcd60e51b815260206004820152603360248201527f4f776e61626c653a2063616c6c2072656e6f756e63654f776e65727368697020604482015272746f20736574207a65726f206164647265737360681b606482015260840161094d565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6008546001600160a01b03163314612aab5760405162461bcd60e51b815260040161094d90615aa3565b6000841315612ad057600954612acb906001600160a01b0316338661397b565b612411565b600083131561241157600a54612411906001600160a01b0316338561397b565b6000806000612afd613056565b3068929eee149b4bd212685403612b1c5763ab143c066000526004601cfd5b3068929eee149b4bd212685560008511612b615760405162461bcd60e51b815260206004820152600660248201526506275726e20360d41b604482015260640161094d565b6000612b746805345cdf77eb68f44c5490565b6008549091506000906001600160a01b031663514ea4bf612b9361309e565b6040518263ffffffff1660e01b8152600401612bb191815260200190565b60a060405180830381865afa158015612bce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bf291906156b6565b505050509050612c023388613f36565b6000612c1888836001600160801b031685613e88565b9050612c2381613a61565b600354909450600090819081908190612c50906101008104600290810b91600160201b9004900b8a6130fc565b9350935093509350612c628282613263565b6006546009546040516370a0823160e01b8152612cf8929187916001600160a01b03909116906370a0823190612c9c903090600401614f7b565b602060405180830381865afa158015612cb9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cdd919061570d565b612ce7919061573c565b612cf1919061573c565b8d89613e88565b612d029085615af7565b600754600a546040516370a0823160e01b8152929c50612d3c9286916001600160a01b0316906370a0823190612c9c903090600401614f7b565b612d469084615af7565b98508915612d6557600954612d65906001600160a01b03168c8c61397b565b8815612d8257600a54612d82906001600160a01b03168c8b61397b565b7f7239dff1718b550db7f36cbf69c665cfeb56d0e96b4fb76a5cba712961b655098b8d8c8c8c604051612db9959493929190615a6c565b60405180910390a1505050505050503868929eee149b4bd21268559250925092565b6008546000908190819081908190819081906001600160a01b031663514ea4bf612e0361309e565b6040518263ffffffff1660e01b8152600401612e2191815260200190565b60a060405180830381865afa158015612e3e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e6291906156b6565b94509450945094509450612ea789612e8b600360019054906101000a900460020b60020b613427565b600354612ea190600160201b900460020b613427565b88613ace565b909750955060006001600160801b038316612ec56001878c8a613f9b565b612ecf9190615af7565b90506000826001600160801b0316612eea6000878d8b613f9b565b612ef49190615af7565b9050612f1182826003600d9054906101000a900461ffff16614333565b6006546009546040516370a0823160e01b8152939550919350916001600160a01b03909116906370a0823190612f4b903090600401614f7b565b602060405180830381865afa158015612f68573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f8c919061570d565b612f969084615af7565b612fa0919061573c565b612faa908a615af7565b600754600a546040516370a0823160e01b8152929b5090916001600160a01b03909116906370a0823190612fe2903090600401614f7b565b602060405180830381865afa158015612fff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613023919061570d565b61302d9083615af7565b613037919061573c565b6130419089615af7565b9750505050505050509250929050565b505050565b61305e611191565b15610fab5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015260640161094d565b6003546040516bffffffffffffffffffffffff193060601b166020820152610100820460e890811b6034830152600160201b90920490911b6037820152600090603a0160405160208183030381529060405280519060200120905090565b60085460405163a34123a760e01b8152600285810b600483015284900b60248201526001600160801b03831660448201526000918291829182916001600160a01b039091169063a34123a79060640160408051808303816000875af1158015613169573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061318d9190615a48565b6008546040516309e3d67b60e31b815230600482015260028b810b60248301528a900b60448201526001600160801b0360648201819052608482015292965090945060009182916001600160a01b031690634f1eb3d89060a40160408051808303816000875af1158015613205573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132299190615d0a565b9092509050613241866001600160801b03841661573c565b9350613256856001600160801b03831661573c565b9250505093509350935093565b600354600160681b900461ffff16801561332f5761271061328861ffff831685615acc565b6132929190615ae3565b600660008282546132a39190615af7565b9091555061271090506132ba61ffff831684615acc565b6132c49190615ae3565b600760008282546132d59190615af7565b9091555060009050806132e9858585614333565b60408051838152602081018390529294509092507fc28ad1de9c0c32e5394ba60323e44d8d9536312236a47231772e448a3e49de42910160405180910390a15050505050565b60408051848152602081018490527fc28ad1de9c0c32e5394ba60323e44d8d9536312236a47231772e448a3e49de42910160405180910390a1505050565b6133798787878761438c565b909550935060006133ad61271084846133925787613394565b885b61339e9190615acc565b6133a89190615ae3565b6144ee565b90506000811315612971576133c58686838786614558565b90965094506133d68888888861438c565b50505050505050505050565b6133ea61462d565b6000805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516113989190614f7b565b60008060008360020b1261343e578260020b61344b565b8260020b61344b90615d3d565b905061345a620d89e719615d59565b60020b8111156134905760405162461bcd60e51b81526020600482015260016024820152601560fa1b604482015260640161094d565b6000816001166000036134a757600160801b6134b9565b6ffffcb933bd6fad37aa2d162d1a5940015b6001600160881b0316905060028216156134ee5760806134e9826ffff97272373d413259a46990580e213a615acc565b901c90505b6004821615613518576080613513826ffff2e50f5f656932ef12357cf3c7fdcc615acc565b901c90505b600882161561354257608061353d826fffe5caca7e10e4e61c3624eaa0941cd0615acc565b901c90505b601082161561356c576080613567826fffcb9843d60f6159c9db58835c926644615acc565b901c90505b6020821615613596576080613591826fff973b41fa98c081472e6896dfb254c0615acc565b901c90505b60408216156135c05760806135bb826fff2ea16466c96a3843ec78b326b52861615acc565b901c90505b60808216156135ea5760806135e5826ffe5dee046a99a2a811c461f1969c3053615acc565b901c90505b610100821615613615576080613610826ffcbe86c7900a88aedcffc83b479aa3a4615acc565b901c90505b61020082161561364057608061363b826ff987a7253ac413176f2b074cf7815e54615acc565b901c90505b61040082161561366b576080613666826ff3392b0822b70005940c7a398e4b70f3615acc565b901c90505b610800821615613696576080613691826fe7159475a2c29b7443b29c7fa6e889d9615acc565b901c90505b6110008216156136c15760806136bc826fd097f3bdfd2022b8845ad8f792aa5825615acc565b901c90505b6120008216156136ec5760806136e7826fa9f746462d870fdf8a65dc1f90e061e5615acc565b901c90505b614000821615613717576080613712826f70d869a156d2a1b890bb3df62baf32f7615acc565b901c90505b61800082161561374257608061373d826f31be135f97d08fd981231505542fcfa6615acc565b901c90505b6201000082161561376e576080613769826f09aa508b5b7a84e1c677de54f3e99bc9615acc565b901c90505b62020000821615613799576080613794826e5d6af8dedb81196699c329225ee604615acc565b901c90505b620400008216156137c35760806137be826d2216e584f5fa1ea926041bedfe98615acc565b901c90505b620800008216156137eb5760806137e6826b048a170391f7dc42444e8fa2615acc565b901c90505b60008460020b13156138065761380381600019615ae3565b90505b613814600160201b82615d7b565b15613820576001613823565b60005b6127059060ff16602083901c615af7565b6003546101008104600290810b91600160201b9004900b6000806138598484836130fc565b9350935050506138698282613263565b6006546009546040516370a0823160e01b8152600092916001600160a01b0316906370a082319061389e903090600401614f7b565b602060405180830381865afa1580156138bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138df919061570d565b6138e9919061573c565b600754600a546040516370a0823160e01b81529293506000926001600160a01b03909116906370a0823190613922903090600401614f7b565b602060405180830381865afa15801561393f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613963919061570d565b61396d919061573c565b90506129718686848461438c565b6040516001600160a01b03831660248201526044810182905261305190849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614678565b6139e6613056565b6000805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861341a3390565b6000613a2e848484613e88565b905060008280613a4057613a40615970565b8486091115610b71576000198110613a5757600080fd5b8061118881615d8f565b60006001600160801b03821115613aca5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b606482015260840161094d565b5090565b600080836001600160a01b0316856001600160a01b03161115613aef579293925b846001600160a01b0316866001600160a01b03161015613b1b57613b1485858561474d565b9150613b62565b836001600160a01b0316866001600160a01b03161015613b5457613b4086858561474d565b9150613b4d8587856147b7565b9050613b62565b613b5f8585856147b7565b90505b94509492505050565b6805345cdf77eb68f44c5481810181811015613b8f5763e5cfe9576000526004601cfd5b806805345cdf77eb68f44c5550506387a211a2600c52816000526020600c208181540181555080602052600c5160601c6000600080516020615f3b833981519152602080a35050565b6040516001600160a01b03808516602483015283166044820152606481018290526124119085906323b872dd60e01b906084016139a7565b6000836001600160a01b0316856001600160a01b03161115613c30579293925b846001600160a01b0316866001600160a01b03161015613c5c57613c55858585614801565b9050611188565b836001600160a01b0316866001600160a01b03161015613cbe576000613c83878686614801565b90506000613c9287898661486b565b9050806001600160801b0316826001600160801b031610613cb35780613cb5565b815b92505050611188565b613cc985858461486b565b9695505050505050565b6000806000806000613ce3610889565b91509150816000148015613cf75750600081115b15613d0e57613d07868983613e88565b9250613dbd565b80158015613d1c5750600082115b15613d2c57613d07878984613e88565b81158015613d38575080155b15613d5f5760405162461bcd60e51b8152602060048201526000602482015260440161094d565b6000613d6c888a85613e88565b90506000613d7b888b85613e88565b9050600082118015613d8d5750600081115b613da95760405162461bcd60e51b815260040161094d906159e6565b808210613db65780613db8565b815b945050505b613dc883838a613a21565b9450613dd583828a613a21565b9350505093509350939050565b613dee8585858561438c565b9093509150602081013515613e8157613e0d60808201606083016150f4565b613e175781613e19565b825b81602001351115613e625760405162461bcd60e51b81526020600482015260136024820152725377617020616d6f756e7420746f6f2062696760681b604482015260640161094d565b613e6d8383836148a1565b9093509150613e7e8585858561438c565b50505b5050505050565b6000808060001985870985870292508281108382030391505080600003613ec15760008411613eb657600080fd5b508290049050610b71565b808411613ecd57600080fd5b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b6387a211a2600c52816000526020600c20805480831115613f5f5763f4d678b86000526004601cfd5b82900390556805345cdf77eb68f44c8054829003905560008181526001600160a01b038316600080516020615f3b833981519152602083a35050565b600080600080871561413257600860009054906101000a90046001600160a01b03166001600160a01b031663f30583996040518163ffffffff1660e01b8152600401602060405180830381865afa158015613ffa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061401e919061570d565b60085460035460405163f30dba9360e01b815261010090910460020b60048201529192506001600160a01b03169063f30dba939060240161010060405180830381865afa158015614073573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140979190615da8565b505060085460035460405163f30dba9360e01b8152959a506001600160a01b03909116965063f30dba9395506140e094600160201b90910460020b9350600401915061514a9050565b61010060405180830381865afa1580156140fe573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141229190615da8565b509397506142b795505050505050565b600860009054906101000a90046001600160a01b03166001600160a01b031663461413196040518163ffffffff1660e01b8152600401602060405180830381865afa158015614185573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141a9919061570d565b60085460035460405163f30dba9360e01b815261010090910460020b60048201529192506001600160a01b03169063f30dba939060240161010060405180830381865afa1580156141fe573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142229190615da8565b505060085460035460405163f30dba9360e01b8152949a506001600160a01b03909116965063f30dba93955061426a9450600160201b900460020b92600401915061514a9050565b61010060405180830381865afa158015614288573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142ac9190615da8565b509297505050505050505b6003546000906101009004600290810b9088900b126142d75750826142dc565b508281035b600354600090600160201b9004600290810b9089900b12156142ff575082614304565b508282035b8183038190036143246001600160801b0389168b8303600160801b613e88565b9b9a5050505050505050505050565b60008061271061434761ffff851687615acc565b6143519190615ae3565b61435b908661573c565b915061271061436e61ffff851686615acc565b6143789190615ae3565b614382908561573c565b9050935093915050565b6000806000600860009054906101000a90046001600160a01b03166001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156143e4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614408919061555e565b50505050505090506000614435826144228a60020b613427565b61442e8a60020b613427565b8989613c10565b90506001600160801b038116156144e357600854604051633c8a7d8d60e01b815260009182916001600160a01b0390911690633c8a7d8d906144819030908e908e908990600401615a06565b60408051808303816000875af115801561449f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144c39190615a48565b90925090506144d2828961573c565b95506144de818861573c565b945050505b505094509492505050565b60006001600160ff1b03821115613aca5760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b606482015260840161094d565b600854604051630251596160e31b81523060048201528215156024820152604481018590526001600160a01b03848116606483015260a06084830152600060a4830181905292839283928392169063128acb089060c40160408051808303816000875af11580156145cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145f19190615a48565b91509150816145ff8a6144ee565b6146099190615e44565b935080614615896144ee565b61461f9190615e44565b925050509550959350505050565b614635611191565b610fab5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015260640161094d565b60006146cd826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614c689092919063ffffffff16565b90508051600014806146ee5750808060200190518101906146ee9190615e6b565b6130515760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161094d565b6000826001600160a01b0316846001600160a01b0316111561476d579192915b6001600160a01b0384166147ad600160601b600160e01b03606085901b166147958787615e88565b6001600160a01b0316866001600160a01b0316613e88565b6127059190615ae3565b6000826001600160a01b0316846001600160a01b031611156147d7579192915b6127056001600160801b0383166147ee8686615e88565b6001600160a01b0316600160601b613e88565b6000826001600160a01b0316846001600160a01b03161115614821579192915b6000614844856001600160a01b0316856001600160a01b0316600160601b613e88565b905061118861486684836148588989615e88565b6001600160a01b0316613e88565b614c77565b6000826001600160a01b0316846001600160a01b0316111561488b579192915b61270561486683600160601b6148588888615e88565b600080806148b560808501606086016150f4565b6148ca57600a546001600160a01b03166148d7565b6009546001600160a01b03165b905060006148eb60808601606087016150f4565b614900576009546001600160a01b031661490d565b600a546001600160a01b03165b90506000826001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161493d9190614f7b565b602060405180830381865afa15801561495a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061497e919061570d565b90506000826001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016149ae9190614f7b565b602060405180830381865afa1580156149cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906149ef919061570d565b9050614a16614a016020890189614f5e565b6001600160a01b0386169060208a0135614c92565b6000614a256020890189614f5e565b6001600160a01b0316614a3b60808a018a615ea8565b604051614a49929190615eee565b6000604051808303816000865af19150503d8060008114614a86576040519150601f19603f3d011682016040523d82523d6000602084013e614a8b565b606091505b5050905080614aca5760405162461bcd60e51b815260206004820152600b60248201526a1cddd85c0819985a5b195960aa1b604482015260640161094d565b6040516370a0823160e01b81526000906001600160a01b038716906370a0823190614af9903090600401614f7b565b602060405180830381865afa158015614b16573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614b3a919061570d565b614b44908561573c565b9050600083866001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401614b759190614f7b565b602060405180830381865afa158015614b92573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614bb6919061570d565b614bc0919061573c565b90508960400135811015614c0e5760405162461bcd60e51b81526020600482015260156024820152741a5b9cdd59999a58da595b9d081d1bdad95b93dd5d605a1b604482015260640161094d565b614c1e60808b0160608c016150f4565b15614c4057614c2d828d61573c565b9850614c39818c615af7565b9750614c59565b614c4a818d615af7565b9850614c56828c61573c565b97505b50505050505050935093915050565b60606127058484600085614d3f565b806001600160801b0381168114614c8d57600080fd5b919050565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa158015614ce2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614d06919061570d565b90506124118463095ea7b360e01b85614d1f8686615af7565b6040516001600160a01b03909216602483015260448201526064016139a7565b606082471015614da05760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161094d565b600080866001600160a01b03168587604051614dbc9190615efe565b60006040518083038185875af1925050503d8060008114614df9576040519150601f19603f3d011682016040523d82523d6000602084013e614dfe565b606091505b5091509150614e0f87838387614e1a565b979650505050505050565b60608315614e89578251600003614e82576001600160a01b0385163b614e825760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161094d565b5081612705565b6127058383815115614e9e5781518083602001fd5b8060405162461bcd60e51b815260040161094d9190614edc565b60005b83811015614ed3578181015183820152602001614ebb565b50506000910152565b6020815260008251806020840152614efb816040850160208701614eb8565b601f01601f19169190910160400192915050565b6001600160a01b0381168114614f2457600080fd5b50565b8035614c8d81614f0f565b60008060408385031215614f4557600080fd5b8235614f5081614f0f565b946020939093013593505050565b600060208284031215614f7057600080fd5b8135610b7181614f0f565b6001600160a01b0391909116815260200190565b8035600181900b8114614c8d57600080fd5b60008060008060808587031215614fb757600080fd5b614fc085614f8f565b93506020850135614fd081614f0f565b9250614fde60408601614f8f565b915060608501358060030b8114614ff457600080fd5b939692955090935050565b60008060006060848603121561501457600080fd5b833561501f81614f0f565b9250602084013561502f81614f0f565b929592945050506040919091013590565b8060020b8114614f2457600080fd5b8015158114614f2457600080fd5b600080600080600060a0868803121561507557600080fd5b853561508081615040565b9450602086013561509081615040565b935060408601356150a081614f0f565b92506060860135915060808601356150b78161504f565b809150509295509295909350565b63ffffffff81168114614f2457600080fd5b6000602082840312156150e957600080fd5b8135610b71816150c5565b60006020828403121561510657600080fd5b8135610b718161504f565b6000806040838503121561512457600080fd5b823561512f81614f0f565b9150602083013561513f8161504f565b809150509250929050565b60029190910b815260200190565b6000806040838503121561516b57600080fd5b82359150602083013561513f81614f0f565b6000806040838503121561519057600080fd5b50508035926020909101359150565b6000806000606084860312156151b457600080fd5b83356151bf81615040565b925060208401356151cf81615040565b915060408401356001600160401b038111156151ea57600080fd5b840160a081870312156151fc57600080fd5b809150509250925092565b60008083601f84011261521957600080fd5b5081356001600160401b0381111561523057600080fd5b60208301915083602082850101111561524857600080fd5b9250929050565b6000806000806060858703121561526557600080fd5b843593506020850135925060408501356001600160401b0381111561528957600080fd5b61529587828801615207565b95989497509550505050565b600080600080600080600060e0888a0312156152bc57600080fd5b87356152c781614f0f565b965060208801356152d781614f0f565b95506040880135945060608801359350608088013560ff811681146152fb57600080fd5b9699959850939692959460a0840135945060c09093013592915050565b61ffff81168114614f2457600080fd5b6000806000806080858703121561533e57600080fd5b84359350602085013561535081615318565b9250604085013561536081614f0f565b91506060850135614ff48161504f565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156153ae576153ae615370565b604052919050565b600082601f8301126153c757600080fd5b81356001600160401b038111156153e0576153e0615370565b6153f3601f8201601f1916602001615386565b81815284602083860101111561540857600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600080600080610100898b03121561544257600080fd5b88356001600160401b038082111561545957600080fd5b6154658c838d016153b6565b995060208b013591508082111561547b57600080fd5b506154888b828c016153b6565b975050604089013561549981614f0f565b955060608901356154a981615318565b945060808901356154b981615040565b935060a08901356154c981615040565b925060c08901356154d981614f0f565b91506154e760e08a01614f27565b90509295985092959890939650565b6000806040838503121561550957600080fd5b823561551481614f0f565b9150602083013561513f81614f0f565b600181811c9082168061553857607f821691505b60208210810361555857634e487b7160e01b600052602260045260246000fd5b50919050565b600080600080600080600060e0888a03121561557957600080fd5b875161558481614f0f565b602089015190975061559581615040565b60408901519096506155a681615318565b60608901519095506155b781615318565b60808901519094506155c881615318565b60a08901519093506155d9816150c5565b60c08901519092506155ea8161504f565b8091505092959891949750929550565b60208082526022908201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206d616e616760408201526132b960f11b606082015260800190565b6020808252601690820152750dac2dcc2cecae48ccaca84e0e640deeccae440dac2f60531b604082015260600190565b61ffff94851681526001600160a01b039390931660208401529216604082015263ffffffff909116606082015260800190565b80516001600160801b0381168114614c8d57600080fd5b600080600080600060a086880312156156ce57600080fd5b6156d78661569f565b945060208601519350604086015192506156f36060870161569f565b91506157016080870161569f565b90509295509295909350565b60006020828403121561571f57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561088357610883615726565b6020808252600e908201526d06e657720706f736974696f6e20360941b604082015260600190565b600294850b81529290930b60208301526001600160801b039081166040830152909116606082015260800190565b634e487b7160e01b600052603260045260246000fd5b6020808252825182820181905260009190848201906040850190845b818110156157f957835163ffffffff16835292840192918401916001016157d7565b50909695505050505050565b60006001600160401b0382111561581e5761581e615370565b5060051b60200190565b8051600681900b8114614c8d57600080fd5b600082601f83011261584b57600080fd5b8151602061586061585b83615805565b615386565b82815260059290921b8401810191818101908684111561587f57600080fd5b8286015b848110156158a357805161589681614f0f565b8352918301918301615883565b509695505050505050565b600080604083850312156158c157600080fd5b82516001600160401b03808211156158d857600080fd5b818501915085601f8301126158ec57600080fd5b815160206158fc61585b83615805565b82815260059290921b8401810191818101908984111561591b57600080fd5b948201945b838610156159405761593186615828565b82529482019490820190615920565b9188015191965090935050508082111561595957600080fd5b506159668582860161583a565b9150509250929050565b634e487b7160e01b600052601260045260246000fd5b60006020828403121561599857600080fd5b8151610b7181614f0f565b6000602082840312156159b557600080fd5b8151610b7181615318565b6020808252600c908201526b5a65726f206164647265737360a01b604082015260600190565b60208082526006908201526506d696e7420360d41b604082015260600190565b6001600160a01b03949094168452600292830b6020850152910b60408301526001600160801b0316606082015260a06080820181905260009082015260c00190565b60008060408385031215615a5b57600080fd5b505080516020909101519092909150565b6001600160a01b039590951685526020850193909352604084019190915260608301526001600160801b0316608082015260a00190565b6020808252600f908201526e31b0b6363130b1b59031b0b63632b960891b604082015260600190565b808202811582820484141761088357610883615726565b600082615af257615af2615970565b500490565b8082018082111561088357610883615726565b600181815b80851115615b45578160001904821115615b2b57615b2b615726565b80851615615b3857918102915b93841c9390800290615b0f565b509250929050565b600082615b5c57506001610883565b81615b6957506000610883565b8160018114615b7f5760028114615b8957615ba5565b6001915050610883565b60ff841115615b9a57615b9a615726565b50506001821b610883565b5060208310610133831016604e8410600b8410161715615bc8575081810a610883565b615bd28383615b0a565b8060001904821115615be657615be6615726565b029392505050565b6000610b7160ff841683615b4d565b601f82111561305157600081815260208120601f850160051c81016020861015615c245750805b601f850160051c820191505b81811015615c4357828155600101615c30565b505050505050565b81516001600160401b03811115615c6457615c64615370565b615c7881615c728454615524565b84615bfd565b602080601f831160018114615cad5760008415615c955750858301515b600019600386901b1c1916600185901b178555615c43565b600085815260208120601f198616915b82811015615cdc57888601518255948401946001909101908401615cbd565b5085821015615cfa5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60008060408385031215615d1d57600080fd5b615d268361569f565b9150615d346020840161569f565b90509250929050565b6000600160ff1b8201615d5257615d52615726565b5060000390565b60008160020b627fffff198103615d7257615d72615726565b60000392915050565b600082615d8a57615d8a615970565b500690565b600060018201615da157615da1615726565b5060010190565b600080600080600080600080610100898b031215615dc557600080fd5b615dce8961569f565b9750602089015180600f0b8114615de457600080fd5b60408a015160608b015191985096509450615e0160808a01615828565b935060a0890151615e1181614f0f565b60c08a0151909350615e22816150c5565b60e08a0151909250615e338161504f565b809150509295985092959890939650565b8181036000831280158383131683831282161715615e6457615e64615726565b5092915050565b600060208284031215615e7d57600080fd5b8151610b718161504f565b6001600160a01b03828116828216039080821115615e6457615e64615726565b6000808335601e19843603018112615ebf57600080fd5b8301803591506001600160401b03821115615ed957600080fd5b60200191503681900382131561524857600080fd5b8183823760009101908152919050565b60008251615f10818460208701614eb8565b919091019291505056feff52cb3b4d8fbd8cdf8f14ffefacf8704a332a0167fd0fc3c804ead362430d85ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa264697066735822122063adbc4a67e6f962ba8ce94d947fa4b984a605a3ae8642611127a0a6fe325aac64736f6c63430008130033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
Loading...
Loading
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.