ERC-20
Overview
Max Total Supply
253.278465361785438659 Crabv2
Holders
2,763
Market
Onchain Market Cap
$0.00
Circulating Supply Market Cap
-
Other Info
Token Contract (WITH 18 Decimals)
Balance
0.015707299015088323 Crabv2Value
$0.00Loading...
Loading
Loading...
Loading
Loading...
Loading
# | Exchange | Pair | Price | 24H Volume | % Volume |
---|
Contract Name:
CrabStrategyV2
Compiler Version
v0.7.6+commit.7338295f
Optimization Enabled:
Yes with 800 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0-only pragma solidity =0.7.6; pragma abicoder v2; // interface import {IController} from "../interfaces/IController.sol"; import {IWPowerPerp} from "../interfaces/IWPowerPerp.sol"; import {IOracle} from "../interfaces/IOracle.sol"; import {IWETH9} from "../interfaces/IWETH9.sol"; import {IUniswapV3Pool} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; import {IController} from "../interfaces/IController.sol"; import {IShortPowerPerp} from "../interfaces/IShortPowerPerp.sol"; // contract import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import {StrategyBase} from "./base/StrategyBase.sol"; import {StrategyFlashSwap} from "./base/StrategyFlashSwap.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {EIP712} from "@openzeppelin/contracts/drafts/EIP712.sol"; // lib import {Address} from "@openzeppelin/contracts/utils/Address.sol"; // StrategyMath licensed under AGPL-3.0-only import {StrategyMath} from "./base/StrategyMath.sol"; import {Power2Base} from "../libs/Power2Base.sol"; import {ECDSA} from "@openzeppelin/contracts/cryptography/ECDSA.sol"; /** * Crab V2 Error Codes: * C1: Caller is not timelock * C2: Contract not yet initialized * C3: Invalid oracle address * C4: Invalid timelock address * C5: Invalid ETH:WSqueeth address * C6: Invalid crabMigration address * C7: Invalid hedge time threshold * C8: Invalid hedge price threshold * C9: Cannot receive ETH * C10: Caller not Crab Migration contract * C11: Crab V2 already initialized * C12: Squeeth contracts not shut down * C13: Crab must redeemShortShutdown * C14: Twap period is too short * C15: Price tolerance is too high * C16: Deposit exceeds strategy cap * C17: Clearing Price should be below bid price * C18: Clearing Price should be above offer price * C19: Invalid offer signature * C20: Order has expired * C21: Manager Price should be greater than 0 * C22: Not a valid Time or Price hedge * C23: Orders must take the opposite side of the hedge * C24: All orders must be either buying or selling * C25: Orders are not arranged properly * C26: Crab contracts shut down * C27: Nonce already used. */ /** * @dev CrabStrategyV2 contract * @notice Contract for Crab strategy * @author Opyn team */ contract CrabStrategyV2 is StrategyBase, StrategyFlashSwap, ReentrancyGuard, Ownable, EIP712 { using StrategyMath for uint256; using Address for address payable; /// @dev the cap in ETH for the strategy, above which deposits will be rejected uint256 public strategyCap; /// @dev the TWAP_PERIOD used in the PowerPerp Controller contract uint32 public constant POWER_PERP_PERIOD = 420 seconds; /// @dev basic unit used for calculation uint256 private constant ONE = 1e18; uint256 private constant ONE_ONE = 1e36; // @dev OTC price must be within this distance of the uniswap twap price uint256 public otcPriceTolerance = 5e16; // 5% // @dev OTC price tolerance cannot exceed 20% uint256 public constant MAX_OTC_PRICE_TOLERANCE = 2e17; // 20% /// @dev twap period to use for hedge calculations uint32 public hedgingTwapPeriod = 420 seconds; /// @dev true if CrabV2 was initialized bool public isInitialized; /// @dev typehash for signed orders bytes32 private constant _CRAB_BALANCE_TYPEHASH = keccak256( "Order(uint256 bidId,address trader,uint256 quantity,uint256 price,bool isBuying,uint256 expiry,uint256 nonce)" ); /// @dev enum to differentiate between uniswap swap callback function source enum FLASH_SOURCE { FLASH_DEPOSIT, FLASH_WITHDRAW } /// @dev ETH:wSqueeth uniswap pool address public immutable ethWSqueethPool; /// @dev strategy uniswap oracle address public immutable oracle; address public immutable timelock; address public immutable crabMigration; /// @dev time difference to trigger a hedge (seconds) uint256 public hedgeTimeThreshold; /// @dev price movement to trigger a hedge (0.1*1e18 = 10%) uint256 public hedgePriceThreshold; /// @dev timestamp when last hedge executed uint256 public timeAtLastHedge; /// @dev wSqueeth/Eth price when last hedge executed uint256 public priceAtLastHedge; /// @dev set to true when redeemShortShutdown has been called bool private hasRedeemedInShutdown; /// @dev store the used flag for a nonce for each address mapping(address => mapping(uint256 => bool)) public nonces; struct FlashDepositData { uint256 totalDeposit; } struct FlashWithdrawData { uint256 crabAmount; } struct Order { uint256 bidId; address trader; uint256 quantity; uint256 price; bool isBuying; uint256 expiry; uint256 nonce; uint8 v; bytes32 r; bytes32 s; } event Deposit(address indexed depositor, uint256 wSqueethAmount, uint256 lpAmount); event Withdraw(address indexed withdrawer, uint256 crabAmount, uint256 wSqueethAmount, uint256 ethWithdrawn); event WithdrawShutdown(address indexed withdrawer, uint256 crabAmount, uint256 ethWithdrawn); event FlashDeposit(address indexed depositor, uint256 depositedAmount, uint256 tradedAmountOut); event FlashWithdraw(address indexed withdrawer, uint256 crabAmount, uint256 wSqueethAmount); event FlashDepositCallback(address indexed depositor, uint256 flashswapDebt, uint256 excess); event FlashWithdrawCallback(address indexed withdrawer, uint256 flashswapDebt, uint256 excess); event HedgeOTCSingle( address trader, uint256 bidId, uint256 quantity, uint256 price, bool isBuying, uint256 clearingPrice ); event HedgeOTC(uint256 bidId, uint256 quantity, bool isBuying, uint256 clearingPrice); event SetStrategyCap(uint256 newCapAmount); event SetHedgingTwapPeriod(uint32 newHedgingTwapPeriod); event SetHedgeTimeThreshold(uint256 newHedgeTimeThreshold); event SetHedgePriceThreshold(uint256 newHedgePriceThreshold); event SetOTCPriceTolerance(uint256 otcPriceTolerance); event VaultTransferred(address indexed newStrategy, uint256 vaultId); modifier onlyTimelock() { require(msg.sender == timelock, "C1"); _; } modifier afterInitialization() { require(isInitialized, "C2"); _; } /** * @notice strategy constructor * @dev this will open a vault in the power token contract and store the vault ID * @param _wSqueethController power token controller address * @param _oracle oracle address * @param _weth weth address * @param _uniswapFactory uniswap factory address * @param _ethWSqueethPool eth:wSqueeth uniswap pool address * @param _timelock timelock contract address * @param _crabMigration crab migration contract address * @param _hedgeTimeThreshold hedge time threshold (seconds) * @param _hedgePriceThreshold hedge price threshold (0.1*1e18 = 10%) */ constructor( address _wSqueethController, address _oracle, address _weth, address _uniswapFactory, address _ethWSqueethPool, address _timelock, address _crabMigration, uint256 _hedgeTimeThreshold, uint256 _hedgePriceThreshold ) StrategyBase(_wSqueethController, _weth, "Crab Strategy v2", "Crabv2") StrategyFlashSwap(_uniswapFactory) EIP712("CrabOTC", "2") { require(_oracle != address(0), "C3"); require(_timelock != address(0), "C4"); require(_ethWSqueethPool != address(0), "C5"); require(_crabMigration != address(0), "C6"); require(_hedgeTimeThreshold > 0, "C7"); require((_hedgePriceThreshold > 0) && (_hedgePriceThreshold <= ONE), "C8"); oracle = _oracle; ethWSqueethPool = _ethWSqueethPool; hedgeTimeThreshold = _hedgeTimeThreshold; hedgePriceThreshold = _hedgePriceThreshold; timelock = _timelock; crabMigration = _crabMigration; } /** * @notice receive function to allow ETH transfer to this contract */ receive() external payable { require(msg.sender == weth || msg.sender == address(powerTokenController), "C9"); } /** * @notice initializes the collateral ratio after the first migration * @param _wSqueethToMint amount of wPowerPerp to mint * @param _crabSharesToMint crab shares to mint * @param _timeAtLastHedge time at last hedge for crab V1 * @param _priceAtLastHedge price at last hedge for crab V1 * @param _strategyCap strategy cap for crab V2 */ function initialize( uint256 _wSqueethToMint, uint256 _crabSharesToMint, uint256 _timeAtLastHedge, uint256 _priceAtLastHedge, uint256 _strategyCap ) external payable { require(msg.sender == crabMigration, "C10"); require(!isInitialized, "C11"); _setStrategyCap(_strategyCap); uint256 amount = msg.value; _checkStrategyCap(amount, 0); // store hedge data from crab V1 timeAtLastHedge = _timeAtLastHedge; priceAtLastHedge = _priceAtLastHedge; // mint wSqueeth and send it to msg.sender _mintWPowerPerp(msg.sender, _wSqueethToMint, amount, false); // mint LP to depositor _mintStrategyToken(msg.sender, _crabSharesToMint); isInitialized = true; } /** * @notice transfer vault NFT to new contract * @dev strategy cap is set to 0 to avoid future deposits * @param _newStrategy new strategy contract address */ function transferVault(address _newStrategy) external onlyTimelock afterInitialization { IShortPowerPerp(powerTokenController.shortPowerPerp()).safeTransferFrom(address(this), _newStrategy, vaultId); _setStrategyCap(0); emit VaultTransferred(_newStrategy, vaultId); } /** * @notice owner can set the strategy cap in ETH collateral terms * @dev deposits are rejected if it would put the strategy above the cap amount * @dev strategy collateral can be above the cap amount due to hedging activities * @param _capAmount the maximum strategy collateral in ETH, checked on deposits */ function setStrategyCap(uint256 _capAmount) external onlyOwner afterInitialization { _setStrategyCap(_capAmount); } /** * @notice set strategy cap amount * @dev deposits are rejected if it would put the strategy above the cap amount * @dev strategy collateral can be above the cap amount due to hedging activities * @param _capAmount the maximum strategy collateral in ETH, checked on deposits */ function _setStrategyCap(uint256 _capAmount) internal { strategyCap = _capAmount; emit SetStrategyCap(_capAmount); } /** * @notice called to redeem the net value of a vault post shutdown * @dev needs to be called before users can exit strategy using withdrawShutdown */ function redeemShortShutdown() external afterInitialization { hasRedeemedInShutdown = true; powerTokenController.redeemShort(vaultId); } /** * @notice flash deposit into strategy, providing ETH, selling wSqueeth and receiving strategy tokens * @dev this function will execute a flash swap where it receives ETH, deposits and mints using flash swap proceeds and msg.value, and then repays the flash swap with wSqueeth * @dev _ethToDeposit must be less than msg.value plus the proceeds from the flash swap * @dev the difference between _ethToDeposit and msg.value provides the minimum that a user can receive for their sold wSqueeth * @param _ethToDeposit total ETH that will be deposited in to the strategy which is a combination of msg.value and flash swap proceeds * @param _poolFee Uniswap pool fee */ function flashDeposit(uint256 _ethToDeposit, uint24 _poolFee) external payable nonReentrant { (uint256 cachedStrategyDebt, uint256 cachedStrategyCollateral) = _syncStrategyState(); _checkStrategyCap(_ethToDeposit, cachedStrategyCollateral); (uint256 wSqueethToMint, ) = _calcWsqueethToMintAndFee( _ethToDeposit, cachedStrategyDebt, cachedStrategyCollateral ); _exactInFlashSwap( wPowerPerp, weth, _poolFee, wSqueethToMint, _ethToDeposit.sub(msg.value), uint8(FLASH_SOURCE.FLASH_DEPOSIT), abi.encodePacked(_ethToDeposit) ); emit FlashDeposit(msg.sender, _ethToDeposit, wSqueethToMint); } /** * @notice flash withdraw from strategy, providing strategy tokens, buying wSqueeth, burning and receiving ETH * @dev this function will execute a flash swap where it receives wSqueeth, burns, withdraws ETH and then repays the flash swap with ETH * @param _crabAmount strategy token amount to burn * @param _maxEthToPay maximum ETH to pay to buy back the wSqueeth debt * @param _poolFee Uniswap pool fee */ function flashWithdraw( uint256 _crabAmount, uint256 _maxEthToPay, uint24 _poolFee ) external nonReentrant { uint256 exactWSqueethNeeded = _getDebtFromStrategyAmount(_crabAmount); _exactOutFlashSwap( weth, wPowerPerp, _poolFee, exactWSqueethNeeded, _maxEthToPay, uint8(FLASH_SOURCE.FLASH_WITHDRAW), abi.encodePacked(_crabAmount) ); emit FlashWithdraw(msg.sender, _crabAmount, exactWSqueethNeeded); } /** * @notice deposit ETH into strategy * @dev provide ETH, return wSqueeth and strategy token */ function deposit() external payable nonReentrant { uint256 amount = msg.value; (uint256 wSqueethToMint, uint256 depositorCrabAmount) = _deposit(msg.sender, amount, false); emit Deposit(msg.sender, wSqueethToMint, depositorCrabAmount); } /** * @notice withdraw WETH from strategy * @dev provide strategy tokens and wSqueeth, returns ETH * @param _crabAmount amount of strategy token to burn */ function withdraw(uint256 _crabAmount) external nonReentrant { uint256 wSqueethAmount = _getDebtFromStrategyAmount(_crabAmount); uint256 ethToWithdraw = _withdraw(msg.sender, _crabAmount, wSqueethAmount, false); // send back ETH collateral payable(msg.sender).sendValue(ethToWithdraw); emit Withdraw(msg.sender, _crabAmount, wSqueethAmount, ethToWithdraw); } /** * @notice called to exit a vault if the Squeeth Power Perp contracts are shutdown * @param _crabAmount amount of strategy token to burn */ function withdrawShutdown(uint256 _crabAmount) external nonReentrant { require(powerTokenController.isShutDown(), "C12"); require(hasRedeemedInShutdown, "C13"); uint256 strategyShare = _calcCrabRatio(_crabAmount, totalSupply()); uint256 ethToWithdraw = _calcEthToWithdraw(strategyShare, address(this).balance); _burn(msg.sender, _crabAmount); payable(msg.sender).sendValue(ethToWithdraw); emit WithdrawShutdown(msg.sender, _crabAmount, ethToWithdraw); } /** * @notice set nonce to true * @param _nonce the number to be set true */ function setNonceTrue(uint256 _nonce) external { nonces[msg.sender][_nonce] = true; } /** * @notice get wSqueeth debt amount associated with strategy token amount * @param _crabAmount strategy token amount * @return wSqueeth amount */ function getWsqueethFromCrabAmount(uint256 _crabAmount) external view returns (uint256) { return _getDebtFromStrategyAmount(_crabAmount); } /** * @notice owner can set the twap period in seconds that is used for calculating twaps for hedging * @param _hedgingTwapPeriod the twap period, in seconds */ function setHedgingTwapPeriod(uint32 _hedgingTwapPeriod) external onlyOwner { require(_hedgingTwapPeriod >= 180, "C14"); hedgingTwapPeriod = _hedgingTwapPeriod; emit SetHedgingTwapPeriod(_hedgingTwapPeriod); } /** * @notice owner can set the hedge time threshold in seconds that determines how often the strategy can be hedged * @param _hedgeTimeThreshold the hedge time threshold, in seconds */ function setHedgeTimeThreshold(uint256 _hedgeTimeThreshold) external onlyOwner { require(_hedgeTimeThreshold > 0, "C7"); hedgeTimeThreshold = _hedgeTimeThreshold; emit SetHedgeTimeThreshold(_hedgeTimeThreshold); } /** * @notice owner can set the hedge time threshold in percent, scaled by 1e18 that determines the deviation in wPowerPerp price that can trigger a rebalance * @param _hedgePriceThreshold the hedge price threshold, in percent, scaled by 1e18 */ function setHedgePriceThreshold(uint256 _hedgePriceThreshold) external onlyOwner { require((_hedgePriceThreshold > 0) && (_hedgePriceThreshold <= ONE), "C8"); hedgePriceThreshold = _hedgePriceThreshold; emit SetHedgePriceThreshold(_hedgePriceThreshold); } /** * @notice owner can set a threshold, scaled by 1e18 that determines the maximum discount of a clearing sale price to the current uniswap twap price * @param _otcPriceTolerance the OTC price tolerance, in percent, scaled by 1e18 */ function setOTCPriceTolerance(uint256 _otcPriceTolerance) external onlyOwner { // Tolerance cannot be more than 20% require(_otcPriceTolerance <= MAX_OTC_PRICE_TOLERANCE, "C15"); otcPriceTolerance = _otcPriceTolerance; emit SetOTCPriceTolerance(_otcPriceTolerance); } /** * @notice check if a user deposit puts the strategy above the cap * @dev reverts if a deposit amount puts strategy over the cap * @dev it is possible for the strategy to be over the cap from trading/hedging activities, but withdrawals are still allowed * @param _depositAmount the user deposit amount in ETH * @param _strategyCollateral the updated strategy collateral */ function _checkStrategyCap(uint256 _depositAmount, uint256 _strategyCollateral) internal view { require(_strategyCollateral.add(_depositAmount) <= strategyCap, "C16"); } /** * @notice uniswap flash swap callback function * @dev this function will be called by flashswap callback function uniswapV3SwapCallback() * @param _caller address of original function caller * @param _amountToPay amount to pay back for flashswap * @param _callData arbitrary data attached to callback * @param _callSource identifier for which function triggered callback */ function _strategyFlash( address _caller, address _tokenIn, address _tokenOut, uint24 _fee, uint256 _amountToPay, bytes memory _callData, uint8 _callSource ) internal override { if (FLASH_SOURCE(_callSource) == FLASH_SOURCE.FLASH_DEPOSIT) { FlashDepositData memory data = abi.decode(_callData, (FlashDepositData)); // convert WETH to ETH as Uniswap uses WETH IWETH9(weth).withdraw(IWETH9(weth).balanceOf(address(this))); // use user msg.value and unwrapped WETH from uniswap flash swap proceeds to deposit into strategy // will revert if data.totalDeposit is > eth balance in contract _deposit(_caller, data.totalDeposit, true); IUniswapV3Pool pool = _getPool(_tokenIn, _tokenOut, _fee); // repay the flash swap IWPowerPerp(wPowerPerp).transfer(address(pool), _amountToPay); emit FlashDepositCallback(_caller, _amountToPay, address(this).balance); // return excess eth to the user that was not needed for slippage if (address(this).balance > 0) { payable(_caller).sendValue(address(this).balance); } } else if (FLASH_SOURCE(_callSource) == FLASH_SOURCE.FLASH_WITHDRAW) { FlashWithdrawData memory data = abi.decode(_callData, (FlashWithdrawData)); // use flash swap wSqueeth proceeds to withdraw ETH along with user crabAmount uint256 ethToWithdraw = _withdraw( _caller, data.crabAmount, IWPowerPerp(wPowerPerp).balanceOf(address(this)), true ); IUniswapV3Pool pool = _getPool(_tokenIn, _tokenOut, _fee); // use some amount of withdrawn ETH to repay flash swap IWETH9(weth).deposit{value: _amountToPay}(); IWETH9(weth).transfer(address(pool), _amountToPay); // excess ETH not used to repay flash swap is transferred to the user uint256 proceeds = ethToWithdraw.sub(_amountToPay); emit FlashWithdrawCallback(_caller, _amountToPay, proceeds); if (proceeds > 0) { payable(_caller).sendValue(proceeds); } } } /** * @notice deposit into strategy * @dev if _isFlashDeposit is true, keeps wSqueeth in contract, otherwise sends to user * @param _depositor depositor address * @param _amount amount of ETH collateral to deposit * @param _isFlashDeposit true if called by flashDeposit * @return wSqueethToMint minted amount of WSqueeth * @return depositorCrabAmount minted CRAB strategy token amount */ function _deposit( address _depositor, uint256 _amount, bool _isFlashDeposit ) internal returns (uint256, uint256) { (uint256 strategyDebt, uint256 strategyCollateral) = _syncStrategyState(); _checkStrategyCap(_amount, strategyCollateral); (uint256 wSqueethToMint, uint256 ethFee) = _calcWsqueethToMintAndFee(_amount, strategyDebt, strategyCollateral); uint256 depositorCrabAmount = _calcSharesToMint(_amount.sub(ethFee), strategyCollateral, totalSupply()); // mint wSqueeth and send it to msg.sender _mintWPowerPerp(_depositor, wSqueethToMint, _amount, _isFlashDeposit); // mint LP to depositor _mintStrategyToken(_depositor, depositorCrabAmount); return (wSqueethToMint, depositorCrabAmount); } /** * @notice withdraw WETH from strategy * @dev if _isFlashDeposit is true, keeps wSqueeth in contract, otherwise sends to user * @param _crabAmount amount of strategy token to burn * @param _wSqueethAmount amount of wSqueeth to burn * @param _isFlashWithdraw flag if called by flashWithdraw * @return ETH amount to withdraw */ function _withdraw( address _from, uint256 _crabAmount, uint256 _wSqueethAmount, bool _isFlashWithdraw ) internal returns (uint256) { (, uint256 strategyCollateral) = _syncStrategyState(); uint256 strategyShare = _calcCrabRatio(_crabAmount, totalSupply()); uint256 ethToWithdraw = _calcEthToWithdraw(strategyShare, strategyCollateral); _burnWPowerPerp(_from, _wSqueethAmount, ethToWithdraw, _isFlashWithdraw); _burn(_from, _crabAmount); return ethToWithdraw; } /** * @dev set nonce flag of the trader to true * @param _trader address of the signer * @param _nonce number that is to be traded only once */ function _useNonce(address _trader, uint256 _nonce) internal { require(!nonces[_trader][_nonce], "C27"); nonces[_trader][_nonce] = true; } /** * @dev view function to get the domain seperator used in signing */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32) { return _domainSeparatorV4(); } /** * @dev check the signer and swap tokens in the order * @param _remainingAmount quantity the manager wants to trade * @param _clearingPrice the price at which all orders are traded * @param _order a signed order to swap tokens */ function _execOrder( uint256 _remainingAmount, uint256 _clearingPrice, Order memory _order ) internal { // check that order beats clearing price if (_order.isBuying) { require(_clearingPrice <= _order.price, "C17"); } else { require(_clearingPrice >= _order.price, "C18"); } _useNonce(_order.trader, _order.nonce); bytes32 structHash = keccak256( abi.encode( _CRAB_BALANCE_TYPEHASH, _order.bidId, _order.trader, _order.quantity, _order.price, _order.isBuying, _order.expiry, _order.nonce ) ); bytes32 hash = _hashTypedDataV4(structHash); address offerSigner = ECDSA.recover(hash, _order.v, _order.r, _order.s); require(offerSigner == _order.trader, "C19"); require(_order.expiry >= block.timestamp, "C20"); // adjust quantity for partial fills if (_remainingAmount < _order.quantity) { _order.quantity = _remainingAmount; } // weth clearing price for the order uint256 wethAmount = _order.quantity.mul(_clearingPrice).div(ONE); if (_order.isBuying) { // trader sends weth and receives oSQTH IWETH9(weth).transferFrom(_order.trader, address(this), wethAmount); IWETH9(weth).withdraw(wethAmount); _mintWPowerPerp(_order.trader, _order.quantity, wethAmount, false); } else { // trader sends oSQTH and receives weth _burnWPowerPerp(_order.trader, _order.quantity, wethAmount, false); // wrap it IWETH9(weth).deposit{value: wethAmount}(); IWETH9(weth).transfer(_order.trader, wethAmount); } emit HedgeOTCSingle( _order.trader, // market maker _order.bidId, _order.quantity, // order oSQTH quantity _order.price, // order price _order.isBuying, // order direction _clearingPrice // executed price for order ); } /** * @dev hedge function to reduce delta using an array of signed orders * @param _totalQuantity quantity the manager wants to trade * @param _clearingPrice clearing price in weth * @param _isHedgeBuying direction of hedge trade * @param _orders an array of signed order to swap tokens */ function hedgeOTC( uint256 _totalQuantity, uint256 _clearingPrice, bool _isHedgeBuying, Order[] memory _orders ) external onlyOwner afterInitialization { require(_clearingPrice > 0, "C21"); require(_isTimeHedge() || _isPriceHedge(), "C22"); _checkOTCPrice(_clearingPrice, _isHedgeBuying); timeAtLastHedge = block.timestamp; priceAtLastHedge = _clearingPrice; uint256 remainingAmount = _totalQuantity; uint256 prevPrice = _orders[0].price; uint256 currentPrice = _orders[0].price; bool isOrderBuying = _orders[0].isBuying; require(_isHedgeBuying != isOrderBuying, "C23"); // iterate through order array and execute if valid for (uint256 i; i < _orders.length; ++i) { currentPrice = _orders[i].price; require(_orders[i].isBuying == isOrderBuying, "C24"); if (_isHedgeBuying) { require(currentPrice >= prevPrice, "C25"); } else { require(currentPrice <= prevPrice, "C25"); } prevPrice = currentPrice; _execOrder(remainingAmount, _clearingPrice, _orders[i]); if (remainingAmount > _orders[i].quantity) { remainingAmount = remainingAmount.sub(_orders[i].quantity); } else { break; } } emit HedgeOTC(_orders[0].bidId, _totalQuantity, _isHedgeBuying, _clearingPrice); } /** * @notice check that the proposed sale price is within a tolerance of the current Uniswap twap * @param _price clearing price provided by manager * @param _isHedgeBuying is crab buying or selling oSQTH */ function _checkOTCPrice(uint256 _price, bool _isHedgeBuying) internal view { // Get twap uint256 wSqueethEthPrice = IOracle(oracle).getTwap(ethWSqueethPool, wPowerPerp, weth, hedgingTwapPeriod, true); if (_isHedgeBuying) { require( _price <= wSqueethEthPrice.mul((ONE.add(otcPriceTolerance))).div(ONE), "Price too high relative to Uniswap twap." ); } else { require( _price >= wSqueethEthPrice.mul((ONE.sub(otcPriceTolerance))).div(ONE), "Price too low relative to Uniswap twap." ); } } /** * @notice sync strategy debt and collateral amount from vault * @return synced debt amount * @return synced collateral amount */ function _syncStrategyState() internal view returns (uint256, uint256) { (, , uint256 syncedStrategyCollateral, uint256 syncedStrategyDebt) = _getVaultDetails(); return (syncedStrategyDebt, syncedStrategyCollateral); } /** * @notice calculate the fee adjustment factor, which is the amount of ETH owed per 1 wSqueeth minted * @dev the fee is a based off the index value of squeeth and uses a twap scaled down by the PowerPerp's INDEX_SCALE * @return the fee adjustment factor */ function _calcFeeAdjustment() internal view returns (uint256) { uint256 wSqueethEthPrice = Power2Base._getTwap( oracle, ethWSqueethPool, wPowerPerp, weth, POWER_PERP_PERIOD, false ); uint256 feeRate = IController(powerTokenController).feeRate(); return wSqueethEthPrice.mul(feeRate).div(10000); } /** * @notice calculate amount of wSqueeth to mint and fee paid from deposited amount * @param _depositedAmount amount of deposited WETH * @param _strategyDebtAmount amount of strategy debt * @param _strategyCollateralAmount collateral amount in strategy * @return amount of minted wSqueeth and ETH fee paid on minted squeeth */ function _calcWsqueethToMintAndFee( uint256 _depositedAmount, uint256 _strategyDebtAmount, uint256 _strategyCollateralAmount ) internal view returns (uint256, uint256) { uint256 wSqueethToMint; uint256 feeAdjustment = _calcFeeAdjustment(); bool isShutdown = (_strategyDebtAmount == 0 && _strategyCollateralAmount == 0) && (totalSupply() != 0); require(!isShutdown, "C26"); wSqueethToMint = _depositedAmount.wmul(_strategyDebtAmount).wdiv( _strategyCollateralAmount.add(_strategyDebtAmount.wmul(feeAdjustment)) ); uint256 fee = wSqueethToMint.wmul(feeAdjustment); return (wSqueethToMint, fee); } /** * @notice check if hedging based on time threshold is allowed * @return true if time hedging is allowed */ function _isTimeHedge() internal view returns (bool) { return (block.timestamp >= timeAtLastHedge.add(hedgeTimeThreshold)); } /** * @notice check if hedging based on price threshold is allowed * @return true if hedging is allowed */ function _isPriceHedge() internal view returns (bool) { uint256 wSqueethEthPrice = IOracle(oracle).getTwap(ethWSqueethPool, wPowerPerp, weth, hedgingTwapPeriod, true); uint256 cachedRatio = wSqueethEthPrice.wdiv(priceAtLastHedge); uint256 priceThreshold = cachedRatio > ONE ? (cachedRatio).sub(ONE) : uint256(ONE).sub(cachedRatio); return priceThreshold >= hedgePriceThreshold; } /** * @notice check if hedging based on price threshold is allowed * @return true if hedging is allowed */ function checkPriceHedge() external view returns (bool) { return _isPriceHedge(); } /** * @notice check if hedging based on time threshold is allowed * @return true if hedging is allowed */ function checkTimeHedge() external view returns (bool) { return _isTimeHedge(); } /** * @dev calculate amount of strategy token to mint for depositor * @param _amount amount of ETH deposited * @param _strategyCollateralAmount amount of strategy collateral * @param _crabTotalSupply total supply of strategy token * @return amount of strategy token to mint */ function _calcSharesToMint( uint256 _amount, uint256 _strategyCollateralAmount, uint256 _crabTotalSupply ) internal pure returns (uint256) { uint256 depositorShare = _amount.wdiv(_strategyCollateralAmount.add(_amount)); if (_crabTotalSupply != 0) return _crabTotalSupply.wmul(depositorShare).wdiv(uint256(ONE).sub(depositorShare)); return _amount; } /** * @notice calculates the ownership proportion for strategy debt and collateral relative to a total amount of strategy tokens * @param _crabAmount strategy token amount * @param _totalSupply strategy total supply * @return ownership proportion of a strategy token amount relative to the total strategy tokens */ function _calcCrabRatio(uint256 _crabAmount, uint256 _totalSupply) internal pure returns (uint256) { return _crabAmount.wdiv(_totalSupply); } /** * @notice calculate ETH to withdraw from strategy given a ownership proportion * @param _crabRatio crab ratio * @param _strategyCollateralAmount amount of collateral in strategy * @return amount of ETH allowed to withdraw */ function _calcEthToWithdraw(uint256 _crabRatio, uint256 _strategyCollateralAmount) internal pure returns (uint256) { return _strategyCollateralAmount.wmul(_crabRatio); } }
// SPDX-License-Identifier: MIT pragma solidity =0.7.6; pragma abicoder v2; import {VaultLib} from "../libs/VaultLib.sol"; interface IController { function ethQuoteCurrencyPool() external view returns (address); function feeRate() external view returns (uint256); function getFee( uint256 _vaultId, uint256 _wPowerPerpAmount, uint256 _collateralAmount ) external view returns (uint256); function quoteCurrency() external view returns (address); function vaults(uint256 _vaultId) external view returns (VaultLib.Vault memory); function shortPowerPerp() external view returns (address); function wPowerPerp() external view returns (address); function wPowerPerpPool() external view returns (address); function oracle() external view returns (address); function weth() external view returns (address); function getExpectedNormalizationFactor() external view returns (uint256); function mintPowerPerpAmount( uint256 _vaultId, uint256 _powerPerpAmount, uint256 _uniTokenId ) external payable returns (uint256 vaultId, uint256 wPowerPerpAmount); function mintWPowerPerpAmount( uint256 _vaultId, uint256 _wPowerPerpAmount, uint256 _uniTokenId ) external payable returns (uint256 vaultId); /** * Deposit collateral into a vault */ function deposit(uint256 _vaultId) external payable; /** * Withdraw collateral from a vault. */ function withdraw(uint256 _vaultId, uint256 _amount) external payable; function burnWPowerPerpAmount( uint256 _vaultId, uint256 _wPowerPerpAmount, uint256 _withdrawAmount ) external; function burnPowerPerpAmount( uint256 _vaultId, uint256 _powerPerpAmount, uint256 _withdrawAmount ) external returns (uint256 wPowerPerpAmount); function liquidate(uint256 _vaultId, uint256 _maxDebtAmount) external returns (uint256); function updateOperator(uint256 _vaultId, address _operator) external; /** * External function to update the normalized factor as a way to pay funding. */ function applyFunding() external; function redeemShort(uint256 _vaultId) external; function reduceDebtShutdown(uint256 _vaultId) external; function isShutDown() external returns (bool); function depositUniPositionToken(uint256 _vaultId, uint256 _uniTokenId) external; function withdrawUniPositionToken(uint256 _vaultId) external; }
// SPDX-License-Identifier: MIT pragma solidity =0.7.6; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IWPowerPerp is IERC20 { function mint(address _account, uint256 _amount) external; function burn(address _account, uint256 _amount) external; }
// SPDX-License-Identifier: MIT pragma solidity =0.7.6; interface IOracle { function getHistoricalTwap( address _pool, address _base, address _quote, uint32 _period, uint32 _periodToHistoricPrice ) external view returns (uint256); function getTwap( address _pool, address _base, address _quote, uint32 _period, bool _checkPeriod ) external view returns (uint256); function getMaxPeriod(address _pool) external view returns (uint32); function getTimeWeightedAverageTickSafe(address _pool, uint32 _period) external view returns (int24 timeWeightedAverageTick); }
// SPDX-License-Identifier: MIT pragma solidity 0.7.6; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IWETH9 is IERC20 { function deposit() external payable; function withdraw(uint256 wad) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import './pool/IUniswapV3PoolImmutables.sol'; import './pool/IUniswapV3PoolState.sol'; import './pool/IUniswapV3PoolDerivedState.sol'; import './pool/IUniswapV3PoolActions.sol'; import './pool/IUniswapV3PoolOwnerActions.sol'; import './pool/IUniswapV3PoolEvents.sol'; /// @title The interface for a Uniswap V3 Pool /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform /// to the ERC20 specification /// @dev The pool interface is broken up into many smaller pieces interface IUniswapV3Pool is IUniswapV3PoolImmutables, IUniswapV3PoolState, IUniswapV3PoolDerivedState, IUniswapV3PoolActions, IUniswapV3PoolOwnerActions, IUniswapV3PoolEvents { }
// SPDX-License-Identifier: MIT pragma solidity =0.7.6; import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; interface IShortPowerPerp is IERC721 { function nextId() external view returns (uint256); function mintNFT(address recipient) external returns (uint256 _newId); }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor () { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity =0.7.6; pragma abicoder v2; // interface import {IController} from "../../interfaces/IController.sol"; import {IWPowerPerp} from "../../interfaces/IWPowerPerp.sol"; // contract import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; // lib import {Address} from "@openzeppelin/contracts/utils/Address.sol"; // StrategyMath licensed under AGPL-3.0-only import {StrategyMath} from "./StrategyMath.sol"; import {VaultLib} from "../../libs/VaultLib.sol"; /** * @dev StrategyBase contract * @notice base contract for PowerToken strategy * @author opyn team */ contract StrategyBase is ERC20 { using StrategyMath for uint256; using Address for address payable; /// @dev power token controller IController public powerTokenController; /// @dev WETH token address public immutable weth; address public immutable wPowerPerp; /// @dev power token strategy vault ID uint256 public immutable vaultId; /** * @notice constructor for StrategyBase * @dev this will open a vault in the power token contract and store the vault ID * @param _powerTokenController power token controller address * @param _weth weth token address * @param _name token name for strategy ERC20 token * @param _symbol token symbol for strategy ERC20 token */ constructor(address _powerTokenController, address _weth, string memory _name, string memory _symbol) ERC20(_name, _symbol) { require(_powerTokenController != address(0), "invalid controller address"); require(_weth != address(0), "invalid weth address"); weth = _weth; powerTokenController = IController(_powerTokenController); wPowerPerp = address(powerTokenController.wPowerPerp()); vaultId = powerTokenController.mintWPowerPerpAmount(0, 0, 0); } /** * @notice get power token strategy vault ID * @return vault ID */ function getStrategyVaultId() external view returns (uint256) { return vaultId; } /** * @notice get the vault composition of the strategy * @return operator * @return nft collateral id * @return collateral amount * @return short amount */ function getVaultDetails() external view returns (address, uint256, uint256, uint256) { return _getVaultDetails(); } /** * @notice mint WPowerPerp and deposit collateral * @dev this function will not send WPowerPerp to msg.sender if _keepWSqueeth == true * @param _to receiver address * @param _wAmount amount of WPowerPerp to mint * @param _collateral amount of collateral to deposit * @param _keepWsqueeth keep minted wSqueeth in this contract if it is set to true */ function _mintWPowerPerp( address _to, uint256 _wAmount, uint256 _collateral, bool _keepWsqueeth ) internal { powerTokenController.mintWPowerPerpAmount{value: _collateral}(vaultId, _wAmount, 0); if (!_keepWsqueeth) { IWPowerPerp(wPowerPerp).transfer(_to, _wAmount); } } /** * @notice burn WPowerPerp and withdraw collateral * @dev this function will not take WPowerPerp from msg.sender if _isOwnedWSqueeth == true * @param _from WPowerPerp holder address * @param _amount amount of wPowerPerp to burn * @param _collateralToWithdraw amount of collateral to withdraw * @param _isOwnedWSqueeth transfer WPowerPerp from holder if it is set to false */ function _burnWPowerPerp( address _from, uint256 _amount, uint256 _collateralToWithdraw, bool _isOwnedWSqueeth ) internal { if (!_isOwnedWSqueeth) { IWPowerPerp(wPowerPerp).transferFrom(_from, address(this), _amount); } powerTokenController.burnWPowerPerpAmount(vaultId, _amount, _collateralToWithdraw); } /** * @notice mint strategy token * @param _to recepient address * @param _amount token amount */ function _mintStrategyToken(address _to, uint256 _amount) internal { _mint(_to, _amount); } /** * @notice get strategy debt amount for a specific strategy token amount * @param _strategyAmount strategy amount * @return debt amount */ function _getDebtFromStrategyAmount(uint256 _strategyAmount) internal view returns (uint256) { (, , ,uint256 strategyDebt) = _getVaultDetails(); return strategyDebt.wmul(_strategyAmount).wdiv(totalSupply()); } /** * @notice get the vault composition of the strategy * @return operator * @return nft collateral id * @return collateral amount * @return short amount */ function _getVaultDetails() internal view returns (address, uint256, uint256, uint256) { VaultLib.Vault memory strategyVault = powerTokenController.vaults(vaultId); return (strategyVault.operator, strategyVault.NftCollateralId, strategyVault.collateralAmount, strategyVault.shortAmount); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.7.6; pragma abicoder v2; // interface import "@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol"; import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; // lib import '@uniswap/v3-core/contracts/libraries/LowGasSafeMath.sol'; import '@uniswap/v3-periphery/contracts/libraries/Path.sol'; import '@uniswap/v3-periphery/contracts/libraries/PoolAddress.sol'; import '@uniswap/v3-periphery/contracts/libraries/CallbackValidation.sol'; import '@uniswap/v3-core/contracts/libraries/TickMath.sol'; import '@uniswap/v3-core/contracts/libraries/SafeCast.sol'; contract StrategyFlashSwap is IUniswapV3SwapCallback { using Path for bytes; using SafeCast for uint256; using LowGasSafeMath for uint256; using LowGasSafeMath for int256; /// @dev Uniswap factory address address public immutable factory; struct SwapCallbackData { bytes path; address caller; uint8 callSource; bytes callData; } /** * @dev constructor * @param _factory uniswap factory address */ constructor( address _factory ) { require(_factory != address(0), "invalid factory address"); factory = _factory; } /** * @notice uniswap swap callback function for flashes * @param amount0Delta amount of token0 * @param amount1Delta amount of token1 * @param _data callback data encoded as SwapCallbackData struct */ function uniswapV3SwapCallback( int256 amount0Delta, int256 amount1Delta, bytes calldata _data ) external override { require(amount0Delta > 0 || amount1Delta > 0); // swaps entirely within 0-liquidity regions are not supported SwapCallbackData memory data = abi.decode(_data, (SwapCallbackData)); (address tokenIn, address tokenOut, uint24 fee) = data.path.decodeFirstPool(); //ensure that callback comes from uniswap pool CallbackValidation.verifyCallback(factory, tokenIn, tokenOut, fee); //determine the amount that needs to be repaid as part of the flashswap uint256 amountToPay = amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta); //calls the strategy function that uses the proceeds from flash swap and executes logic to have an amount of token to repay the flash swap _strategyFlash(data.caller, tokenIn, tokenOut, fee, amountToPay, data.callData, data.callSource); } /** * @notice execute an exact-in flash swap (specify an exact amount to pay) * @param _tokenIn token address to sell * @param _tokenOut token address to receive * @param _fee pool fee * @param _amountIn amount to sell * @param _amountOutMinimum minimum amount to receive * @param _callSource function call source * @param _data arbitrary data assigned with the call */ function _exactInFlashSwap(address _tokenIn, address _tokenOut, uint24 _fee, uint256 _amountIn, uint256 _amountOutMinimum, uint8 _callSource, bytes memory _data) internal { //calls internal uniswap swap function that will trigger a callback for the flash swap uint256 amountOut = _exactInputInternal( _amountIn, address(this), uint160(0), SwapCallbackData({path: abi.encodePacked(_tokenIn, _fee, _tokenOut), caller: msg.sender, callSource: _callSource, callData: _data}) ); //slippage limit check require(amountOut >= _amountOutMinimum, "amount out less than min"); } /** * @notice execute an exact-out flash swap (specify an exact amount to receive) * @param _tokenIn token address to sell * @param _tokenOut token address to receive * @param _fee pool fee * @param _amountOut exact amount to receive * @param _amountInMaximum maximum amount to sell * @param _callSource function call source * @param _data arbitrary data assigned with the call */ function _exactOutFlashSwap(address _tokenIn, address _tokenOut, uint24 _fee, uint256 _amountOut, uint256 _amountInMaximum, uint8 _callSource, bytes memory _data) internal { //calls internal uniswap swap function that will trigger a callback for the flash swap uint256 amountIn = _exactOutputInternal( _amountOut, address(this), uint160(0), SwapCallbackData({path: abi.encodePacked(_tokenOut, _fee, _tokenIn), caller: msg.sender, callSource: _callSource, callData: _data}) ); //slippage limit check require(amountIn <= _amountInMaximum, "amount in greater than max"); } /** * @notice function to be called by uniswap callback. * @dev this function should be overridden by the child contract * param _caller initial strategy function caller * param _tokenIn token address sold * param _tokenOut token address bought * param _fee pool fee * param _amountToPay amount to pay for the pool second token * param _callData arbitrary data assigned with the flashswap call * param _callSource function call source */ function _strategyFlash(address /*_caller*/, address /*_tokenIn*/, address /*_tokenOut*/, uint24 /*_fee*/, uint256 /*_amountToPay*/, bytes memory _callData, uint8 _callSource) internal virtual {} /** * @notice internal function for exact-in swap on uniswap (specify exact amount to pay) * @param _amountIn amount of token to pay * @param _recipient recipient for receive * @param _sqrtPriceLimitX96 price limit * @return amount of token bought (amountOut) */ function _exactInputInternal( uint256 _amountIn, address _recipient, uint160 _sqrtPriceLimitX96, SwapCallbackData memory data ) private returns (uint256) { (address tokenIn, address tokenOut, uint24 fee) = data.path.decodeFirstPool(); //uniswap token0 has a lower address than token1 //if tokenIn<tokenOut, we are selling an exact amount of token0 in exchange for token1 //zeroForOne determines which token is being sold and which is being bought bool zeroForOne = tokenIn < tokenOut; //swap on uniswap, including data to trigger call back for flashswap (int256 amount0, int256 amount1) = _getPool(tokenIn, tokenOut, fee).swap( _recipient, zeroForOne, _amountIn.toInt256(), _sqrtPriceLimitX96 == 0 ? (zeroForOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1) : _sqrtPriceLimitX96, abi.encode(data) ); //determine the amountOut based on which token has a lower address return uint256(-(zeroForOne ? amount1 : amount0)); } /** * @notice internal function for exact-out swap on uniswap (specify exact amount to receive) * @param _amountOut amount of token to receive * @param _recipient recipient for receive * @param _sqrtPriceLimitX96 price limit * @return amount of token sold (amountIn) */ function _exactOutputInternal( uint256 _amountOut, address _recipient, uint160 _sqrtPriceLimitX96, SwapCallbackData memory data ) private returns (uint256) { (address tokenOut, address tokenIn, uint24 fee) = data.path.decodeFirstPool(); //uniswap token0 has a lower address than token1 //if tokenIn<tokenOut, we are buying an exact amount of token1 in exchange for token0 //zeroForOne determines which token is being sold and which is being bought bool zeroForOne = tokenIn < tokenOut; //swap on uniswap, including data to trigger call back for flashswap (int256 amount0Delta, int256 amount1Delta) = _getPool(tokenIn, tokenOut, fee).swap( _recipient, zeroForOne, -_amountOut.toInt256(), _sqrtPriceLimitX96 == 0 ? (zeroForOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1) : _sqrtPriceLimitX96, abi.encode(data) ); //determine the amountIn and amountOut based on which token has a lower address (uint256 amountIn, uint256 amountOutReceived) = zeroForOne ? (uint256(amount0Delta), uint256(-amount1Delta)) : (uint256(amount1Delta), uint256(-amount0Delta)); // it's technically possible to not receive the full output amount, // so if no price limit has been specified, require this possibility away if (_sqrtPriceLimitX96 == 0) require(amountOutReceived == _amountOut); return amountIn; } /** * @notice returns the uniswap pool for the given token pair and fee * @dev the pool contract may or may not exist * @param tokenA address of first token * @param tokenB address of second token * @param fee fee tier for pool */ function _getPool( address tokenA, address tokenB, uint24 fee ) internal view returns (IUniswapV3Pool) { return IUniswapV3Pool(PoolAddress.computeAddress(factory, PoolAddress.getPoolKey(tokenA, tokenB, fee))); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner 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 * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
// SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data. * * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible, * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding * they need in their contracts using a combination of `abi.encode` and `keccak256`. * * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA * ({_hashTypedDataV4}). * * The implementation of the domain separator was designed to be as efficient as possible while still properly updating * the chain id to protect against replay attacks on an eventual fork of the chain. * * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask]. * * _Available since v3.4._ */ abstract contract EIP712 { /* solhint-disable var-name-mixedcase */ // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to // invalidate the cached domain separator if the chain id changes. bytes32 private immutable _CACHED_DOMAIN_SEPARATOR; uint256 private immutable _CACHED_CHAIN_ID; bytes32 private immutable _HASHED_NAME; bytes32 private immutable _HASHED_VERSION; bytes32 private immutable _TYPE_HASH; /* solhint-enable var-name-mixedcase */ /** * @dev Initializes the domain separator and parameter caches. * * The meaning of `name` and `version` is specified in * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]: * * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol. * - `version`: the current major version of the signing domain. * * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart * contract upgrade]. */ constructor(string memory name, string memory version) { bytes32 hashedName = keccak256(bytes(name)); bytes32 hashedVersion = keccak256(bytes(version)); bytes32 typeHash = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); _HASHED_NAME = hashedName; _HASHED_VERSION = hashedVersion; _CACHED_CHAIN_ID = _getChainId(); _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion); _TYPE_HASH = typeHash; } /** * @dev Returns the domain separator for the current chain. */ function _domainSeparatorV4() internal view virtual returns (bytes32) { if (_getChainId() == _CACHED_CHAIN_ID) { return _CACHED_DOMAIN_SEPARATOR; } else { return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION); } } function _buildDomainSeparator(bytes32 typeHash, bytes32 name, bytes32 version) private view returns (bytes32) { return keccak256( abi.encode( typeHash, name, version, _getChainId(), address(this) ) ); } /** * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this * function returns the hash of the fully encoded EIP712 message for this domain. * * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example: * * ```solidity * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( * keccak256("Mail(address to,string contents)"), * mailTo, * keccak256(bytes(mailContents)) * ))); * address signer = ECDSA.recover(digest, signature); * ``` */ function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), structHash)); } function _getChainId() private view returns (uint256 chainId) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 // solhint-disable-next-line no-inline-assembly assembly { chainId := chainid() } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (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 functionCall(target, data, "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"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(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) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(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) { require(isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
//SPDX-License-Identifier: AGPL-3.0-only /// math.sol -- mixin for inline numerical wizardry // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity >0.4.13; /** * @notice Copied from https://github.com/dapphub/ds-math/blob/e70a364787804c1ded9801ed6c27b440a86ebd32/src/math.sol * @dev change contract to library, added div() function */ library StrategyMath { function add(uint x, uint y) internal pure returns (uint z) { require((z = x + y) >= x, "ds-math-add-overflow"); } function sub(uint x, uint y) internal pure returns (uint z) { require((z = x - y) <= x, "ds-math-sub-underflow"); } function mul(uint x, uint y) internal pure returns (uint z) { require(y == 0 || (z = x * y) / y == x, "ds-math-mul-overflow"); } function div(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); return a / b; } function min(uint x, uint y) internal pure returns (uint z) { return x <= y ? x : y; } function max(uint x, uint y) internal pure returns (uint z) { return x >= y ? x : y; } function imin(int x, int y) internal pure returns (int z) { return x <= y ? x : y; } function imax(int x, int y) internal pure returns (int z) { return x >= y ? x : y; } uint constant WAD = 10 ** 18; uint constant RAY = 10 ** 27; //rounds to zero if x*y < WAD / 2 function wmul(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, y), WAD / 2) / WAD; } //rounds to zero if x*y < WAD / 2 function rmul(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, y), RAY / 2) / RAY; } //rounds to zero if x*y < WAD / 2 function wdiv(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, WAD), y / 2) / y; } //rounds to zero if x*y < RAY / 2 function rdiv(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, RAY), y / 2) / y; } // Ceil A to a multiple m function ceil(uint a, uint m) internal pure returns(uint z) { z = mul(div(sub(add(a, m), 1), m), m); } // Floor A to a multiple m function floor(uint a, uint m) internal pure returns(uint z) { z = mul(div(a, m), m); } // This famous algorithm is called "exponentiation by squaring" // and calculates x^n with x as fixed-point and n as regular unsigned. // // It's O(log n), instead of O(n) for naive repeated multiplication. // // These facts are why it works: // // If n is even, then x^n = (x^2)^(n/2). // If n is odd, then x^n = x * x^(n-1), // and applying the equation for even x gives // x^n = x * (x^2)^((n-1) / 2). // // Also, EVM division is flooring and // floor[(n-1) / 2] = floor[n / 2]. // function rpow(uint x, uint n) internal pure returns (uint z) { z = n % 2 != 0 ? x : RAY; for (n /= 2; n != 0; n /= 2) { x = rmul(x, x); if (n % 2 != 0) { z = rmul(z, x); } } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.7.6; //interface import {IOracle} from "../interfaces/IOracle.sol"; //lib import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol"; library Power2Base { using SafeMath for uint256; uint32 private constant TWAP_PERIOD = 420 seconds; uint256 private constant INDEX_SCALE = 1e4; uint256 private constant ONE = 1e18; uint256 private constant ONE_ONE = 1e36; /** * @notice return the scaled down index of the power perp in USD, scaled by 18 decimals * @param _period period of time for the twap in seconds (cannot be longer than maximum period for the pool) * @param _oracle oracle address * @param _ethQuoteCurrencyPool uniswap v3 pool for weth / quoteCurrency * @param _weth weth address * @param _quoteCurrency quoteCurrency address * @return for squeeth, return ethPrice^2 */ function _getIndex( uint32 _period, address _oracle, address _ethQuoteCurrencyPool, address _weth, address _quoteCurrency ) internal view returns (uint256) { uint256 ethQuoteCurrencyPrice = _getScaledTwap( _oracle, _ethQuoteCurrencyPool, _weth, _quoteCurrency, _period, false ); return ethQuoteCurrencyPrice.mul(ethQuoteCurrencyPrice).div(ONE); } /** * @notice return the unscaled index of the power perp in USD, scaled by 18 decimals * @param _period period of time for the twap in seconds (cannot be longer than maximum period for the pool) * @param _oracle oracle address * @param _ethQuoteCurrencyPool uniswap v3 pool for weth / quoteCurrency * @param _weth weth address * @param _quoteCurrency quoteCurrency address * @return for squeeth, return ethPrice^2 */ function _getUnscaledIndex( uint32 _period, address _oracle, address _ethQuoteCurrencyPool, address _weth, address _quoteCurrency ) internal view returns (uint256) { uint256 ethQuoteCurrencyPrice = _getTwap(_oracle, _ethQuoteCurrencyPool, _weth, _quoteCurrency, _period, false); return ethQuoteCurrencyPrice.mul(ethQuoteCurrencyPrice).div(ONE); } /** * @notice return the mark price of power perp in quoteCurrency, scaled by 18 decimals * @param _period period of time for the twap in seconds (cannot be longer than maximum period for the pool) * @param _oracle oracle address * @param _wSqueethEthPool uniswap v3 pool for wSqueeth / weth * @param _ethQuoteCurrencyPool uniswap v3 pool for weth / quoteCurrency * @param _weth weth address * @param _quoteCurrency quoteCurrency address * @param _wSqueeth wSqueeth address * @param _normalizationFactor current normalization factor * @return for squeeth, return ethPrice * squeethPriceInEth */ function _getDenormalizedMark( uint32 _period, address _oracle, address _wSqueethEthPool, address _ethQuoteCurrencyPool, address _weth, address _quoteCurrency, address _wSqueeth, uint256 _normalizationFactor ) internal view returns (uint256) { uint256 ethQuoteCurrencyPrice = _getScaledTwap( _oracle, _ethQuoteCurrencyPool, _weth, _quoteCurrency, _period, false ); uint256 wsqueethEthPrice = _getTwap(_oracle, _wSqueethEthPool, _wSqueeth, _weth, _period, false); return wsqueethEthPrice.mul(ethQuoteCurrencyPrice).div(_normalizationFactor); } /** * @notice get the fair collateral value for a _debtAmount of wSqueeth * @dev the actual amount liquidator can get should have a 10% bonus on top of this value. * @param _debtAmount wSqueeth amount paid by liquidator * @param _oracle oracle address * @param _wSqueethEthPool uniswap v3 pool for wSqueeth / weth * @param _wSqueeth wSqueeth address * @param _weth weth address * @return returns value of debt in ETH */ function _getDebtValueInEth( uint256 _debtAmount, address _oracle, address _wSqueethEthPool, address _wSqueeth, address _weth ) internal view returns (uint256) { uint256 wSqueethPrice = _getTwap(_oracle, _wSqueethEthPool, _wSqueeth, _weth, TWAP_PERIOD, false); return _debtAmount.mul(wSqueethPrice).div(ONE); } /** * @notice request twap from our oracle, scaled down by INDEX_SCALE * @param _oracle oracle address * @param _pool uniswap v3 pool address * @param _base base currency. to get eth/usd price, eth is base token * @param _quote quote currency. to get eth/usd price, usd is the quote currency * @param _period number of seconds in the past to start calculating time-weighted average. * @param _checkPeriod check that period is not longer than maximum period for the pool to prevent reverts * @return twap price scaled down by INDEX_SCALE */ function _getScaledTwap( address _oracle, address _pool, address _base, address _quote, uint32 _period, bool _checkPeriod ) internal view returns (uint256) { uint256 twap = _getTwap(_oracle, _pool, _base, _quote, _period, _checkPeriod); return twap.div(INDEX_SCALE); } /** * @notice request twap from our oracle * @dev this will revert if period is > max period for the pool * @param _oracle oracle address * @param _pool uniswap v3 pool address * @param _base base currency. to get eth/quoteCurrency price, eth is base token * @param _quote quote currency. to get eth/quoteCurrency price, quoteCurrency is the quote currency * @param _period number of seconds in the past to start calculating time-weighted average * @param _checkPeriod check that period is not longer than maximum period for the pool to prevent reverts * @return human readable price. scaled by 1e18 */ function _getTwap( address _oracle, address _pool, address _base, address _quote, uint32 _period, bool _checkPeriod ) internal view returns (uint256) { // period reaching this point should be check, otherwise might revert return IOracle(_oracle).getTwap(_pool, _base, _quote, _period, _checkPeriod); } /** * @notice get the index value of wsqueeth in wei, used when system settles * @dev the index of squeeth is ethPrice^2, so each squeeth will need to pay out {ethPrice} eth * @param _wsqueethAmount amount of wsqueeth used in settlement * @param _indexPriceForSettlement index price for settlement * @param _normalizationFactor current normalization factor * @return amount in wei that should be paid to the token holder */ function _getLongSettlementValue( uint256 _wsqueethAmount, uint256 _indexPriceForSettlement, uint256 _normalizationFactor ) internal pure returns (uint256) { return _wsqueethAmount.mul(_normalizationFactor).mul(_indexPriceForSettlement).div(ONE_ONE); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { // Check the signature length if (signature.length != 65) { revert("ECDSA: invalid signature length"); } // Divide the signature in r, s and v variables bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. // solhint-disable-next-line no-inline-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return recover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover-bytes32-bytes-} that receives the `v`, * `r` and `s` signature fields separately. */ function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "ECDSA: invalid signature 's' value"); require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value"); // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); require(signer != address(0), "ECDSA: invalid signature"); return signer; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * replicates the behavior of the * https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`] * JSON-RPC method. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } }
//SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.7.6; //interface import {INonfungiblePositionManager} from "@uniswap/v3-periphery/contracts/interfaces/INonfungiblePositionManager.sol"; //lib import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol"; import {TickMathExternal} from "./TickMathExternal.sol"; import {SqrtPriceMathPartial} from "./SqrtPriceMathPartial.sol"; import {Uint256Casting} from "./Uint256Casting.sol"; /** * Error code: * V1: Vault already had nft * V2: Vault has no NFT */ library VaultLib { using SafeMath for uint256; using Uint256Casting for uint256; uint256 constant ONE_ONE = 1e36; // the collateralization ratio (CR) is checked with the numerator and denominator separately // a user is safe if - collateral value >= (COLLAT_RATIO_NUMER/COLLAT_RATIO_DENOM)* debt value uint256 public constant CR_NUMERATOR = 3; uint256 public constant CR_DENOMINATOR = 2; struct Vault { // the address that can update the vault address operator; // uniswap position token id deposited into the vault as collateral // 2^32 is 4,294,967,296, which means the vault structure will work with up to 4 billion positions uint32 NftCollateralId; // amount of eth (wei) used in the vault as collateral // 2^96 / 1e18 = 79,228,162,514, which means a vault can store up to 79 billion eth // when we need to do calculations, we always cast this number to uint256 to avoid overflow uint96 collateralAmount; // amount of wPowerPerp minted from the vault uint128 shortAmount; } /** * @notice add eth collateral to a vault * @param _vault in-memory vault * @param _amount amount of eth to add */ function addEthCollateral(Vault memory _vault, uint256 _amount) internal pure { _vault.collateralAmount = uint256(_vault.collateralAmount).add(_amount).toUint96(); } /** * @notice add uniswap position token collateral to a vault * @param _vault in-memory vault * @param _tokenId uniswap position token id */ function addUniNftCollateral(Vault memory _vault, uint256 _tokenId) internal pure { require(_vault.NftCollateralId == 0, "V1"); require(_tokenId != 0, "C23"); _vault.NftCollateralId = _tokenId.toUint32(); } /** * @notice remove eth collateral from a vault * @param _vault in-memory vault * @param _amount amount of eth to remove */ function removeEthCollateral(Vault memory _vault, uint256 _amount) internal pure { _vault.collateralAmount = uint256(_vault.collateralAmount).sub(_amount).toUint96(); } /** * @notice remove uniswap position token collateral from a vault * @param _vault in-memory vault */ function removeUniNftCollateral(Vault memory _vault) internal pure { require(_vault.NftCollateralId != 0, "V2"); _vault.NftCollateralId = 0; } /** * @notice add debt to vault * @param _vault in-memory vault * @param _amount amount of debt to add */ function addShort(Vault memory _vault, uint256 _amount) internal pure { _vault.shortAmount = uint256(_vault.shortAmount).add(_amount).toUint128(); } /** * @notice remove debt from vault * @param _vault in-memory vault * @param _amount amount of debt to remove */ function removeShort(Vault memory _vault, uint256 _amount) internal pure { _vault.shortAmount = uint256(_vault.shortAmount).sub(_amount).toUint128(); } /** * @notice check if a vault is properly collateralized * @param _vault the vault we want to check * @param _positionManager address of the uniswap position manager * @param _normalizationFactor current _normalizationFactor * @param _ethQuoteCurrencyPrice current eth price scaled by 1e18 * @param _minCollateral minimum collateral that needs to be in a vault * @param _wsqueethPoolTick current price tick for wsqueeth pool * @param _isWethToken0 whether weth is token0 in the wsqueeth pool * @return true if the vault is sufficiently collateralized * @return true if the vault is considered as a dust vault */ function getVaultStatus( Vault memory _vault, address _positionManager, uint256 _normalizationFactor, uint256 _ethQuoteCurrencyPrice, uint256 _minCollateral, int24 _wsqueethPoolTick, bool _isWethToken0 ) internal view returns (bool, bool) { if (_vault.shortAmount == 0) return (true, false); uint256 debtValueInETH = uint256(_vault.shortAmount).mul(_normalizationFactor).mul(_ethQuoteCurrencyPrice).div( ONE_ONE ); uint256 totalCollateral = _getEffectiveCollateral( _vault, _positionManager, _normalizationFactor, _ethQuoteCurrencyPrice, _wsqueethPoolTick, _isWethToken0 ); bool isDust = totalCollateral < _minCollateral; bool isAboveWater = totalCollateral.mul(CR_DENOMINATOR) >= debtValueInETH.mul(CR_NUMERATOR); return (isAboveWater, isDust); } /** * @notice get the total effective collateral of a vault, which is: * collateral amount + uniswap position token equivelent amount in eth * @param _vault the vault we want to check * @param _positionManager address of the uniswap position manager * @param _normalizationFactor current _normalizationFactor * @param _ethQuoteCurrencyPrice current eth price scaled by 1e18 * @param _wsqueethPoolTick current price tick for wsqueeth pool * @param _isWethToken0 whether weth is token0 in the wsqueeth pool * @return the total worth of collateral in the vault */ function _getEffectiveCollateral( Vault memory _vault, address _positionManager, uint256 _normalizationFactor, uint256 _ethQuoteCurrencyPrice, int24 _wsqueethPoolTick, bool _isWethToken0 ) internal view returns (uint256) { if (_vault.NftCollateralId == 0) return _vault.collateralAmount; // the user has deposited uniswap position token as collateral, see how much eth / wSqueeth the uniswap position token has (uint256 nftEthAmount, uint256 nftWsqueethAmount) = _getUniPositionBalances( _positionManager, _vault.NftCollateralId, _wsqueethPoolTick, _isWethToken0 ); // convert squeeth amount from uniswap position token as equivalent amount of collateral uint256 wSqueethIndexValueInEth = nftWsqueethAmount.mul(_normalizationFactor).mul(_ethQuoteCurrencyPrice).div( ONE_ONE ); // add eth value from uniswap position token as collateral return nftEthAmount.add(wSqueethIndexValueInEth).add(_vault.collateralAmount); } /** * @notice determine how much eth / wPowerPerp the uniswap position contains * @param _positionManager address of the uniswap position manager * @param _tokenId uniswap position token id * @param _wPowerPerpPoolTick current price tick * @param _isWethToken0 whether weth is token0 in the pool * @return ethAmount the eth amount this LP token contains * @return wPowerPerpAmount the wPowerPerp amount this LP token contains */ function _getUniPositionBalances( address _positionManager, uint256 _tokenId, int24 _wPowerPerpPoolTick, bool _isWethToken0 ) internal view returns (uint256 ethAmount, uint256 wPowerPerpAmount) { ( int24 tickLower, int24 tickUpper, uint128 liquidity, uint128 tokensOwed0, uint128 tokensOwed1 ) = _getUniswapPositionInfo(_positionManager, _tokenId); (uint256 amount0, uint256 amount1) = _getToken0Token1Balances( tickLower, tickUpper, _wPowerPerpPoolTick, liquidity ); return _isWethToken0 ? (amount0 + tokensOwed0, amount1 + tokensOwed1) : (amount1 + tokensOwed1, amount0 + tokensOwed0); } /** * @notice get uniswap position token info * @param _positionManager address of the uniswap position position manager * @param _tokenId uniswap position token id * @return tickLower lower tick of the position * @return tickUpper upper tick of the position * @return liquidity raw liquidity amount of the position * @return tokensOwed0 amount of token 0 can be collected as fee * @return tokensOwed1 amount of token 1 can be collected as fee */ function _getUniswapPositionInfo(address _positionManager, uint256 _tokenId) internal view returns ( int24, int24, uint128, uint128, uint128 ) { INonfungiblePositionManager positionManager = INonfungiblePositionManager(_positionManager); ( , , , , , int24 tickLower, int24 tickUpper, uint128 liquidity, , , uint128 tokensOwed0, uint128 tokensOwed1 ) = positionManager.positions(_tokenId); return (tickLower, tickUpper, liquidity, tokensOwed0, tokensOwed1); } /** * @notice get balances of token0 / token1 in a uniswap position * @dev knowing liquidity, tick range, and current tick gives balances * @param _tickLower address of the uniswap position manager * @param _tickUpper uniswap position token id * @param _tick current price tick used for calculation * @return amount0 the amount of token0 in the uniswap position token * @return amount1 the amount of token1 in the uniswap position token */ function _getToken0Token1Balances( int24 _tickLower, int24 _tickUpper, int24 _tick, uint128 _liquidity ) internal pure returns (uint256 amount0, uint256 amount1) { // get the current price and tick from wPowerPerp pool uint160 sqrtPriceX96 = TickMathExternal.getSqrtRatioAtTick(_tick); if (_tick < _tickLower) { amount0 = SqrtPriceMathPartial.getAmount0Delta( TickMathExternal.getSqrtRatioAtTick(_tickLower), TickMathExternal.getSqrtRatioAtTick(_tickUpper), _liquidity, true ); } else if (_tick < _tickUpper) { amount0 = SqrtPriceMathPartial.getAmount0Delta( sqrtPriceX96, TickMathExternal.getSqrtRatioAtTick(_tickUpper), _liquidity, true ); amount1 = SqrtPriceMathPartial.getAmount1Delta( TickMathExternal.getSqrtRatioAtTick(_tickLower), sqrtPriceX96, _liquidity, true ); } else { amount1 = SqrtPriceMathPartial.getAmount1Delta( TickMathExternal.getSqrtRatioAtTick(_tickLower), TickMathExternal.getSqrtRatioAtTick(_tickUpper), _liquidity, true ); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; pragma abicoder v2; import '@openzeppelin/contracts/token/ERC721/IERC721Metadata.sol'; import '@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol'; import './IPoolInitializer.sol'; import './IERC721Permit.sol'; import './IPeripheryPayments.sol'; import './IPeripheryImmutableState.sol'; import '../libraries/PoolAddress.sol'; /// @title Non-fungible token for positions /// @notice Wraps Uniswap V3 positions in a non-fungible token interface which allows for them to be transferred /// and authorized. interface INonfungiblePositionManager is IPoolInitializer, IPeripheryPayments, IPeripheryImmutableState, IERC721Metadata, IERC721Enumerable, IERC721Permit { /// @notice Emitted when liquidity is increased for a position NFT /// @dev Also emitted when a token is minted /// @param tokenId The ID of the token for which liquidity was increased /// @param liquidity The amount by which liquidity for the NFT position was increased /// @param amount0 The amount of token0 that was paid for the increase in liquidity /// @param amount1 The amount of token1 that was paid for the increase in liquidity event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1); /// @notice Emitted when liquidity is decreased for a position NFT /// @param tokenId The ID of the token for which liquidity was decreased /// @param liquidity The amount by which liquidity for the NFT position was decreased /// @param amount0 The amount of token0 that was accounted for the decrease in liquidity /// @param amount1 The amount of token1 that was accounted for the decrease in liquidity event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1); /// @notice Emitted when tokens are collected for a position NFT /// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior /// @param tokenId The ID of the token for which underlying tokens were collected /// @param recipient The address of the account that received the collected tokens /// @param amount0 The amount of token0 owed to the position that was collected /// @param amount1 The amount of token1 owed to the position that was collected event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1); /// @notice Returns the position information associated with a given token ID. /// @dev Throws if the token ID is not valid. /// @param tokenId The ID of the token that represents the position /// @return nonce The nonce for permits /// @return operator The address that is approved for spending /// @return token0 The address of the token0 for a specific pool /// @return token1 The address of the token1 for a specific pool /// @return fee The fee associated with the pool /// @return tickLower The lower end of the tick range for the position /// @return tickUpper The higher end of the tick range for the position /// @return liquidity The liquidity of the position /// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position /// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position /// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation /// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation function positions(uint256 tokenId) external view returns ( uint96 nonce, address operator, address token0, address token1, uint24 fee, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1 ); struct MintParams { address token0; address token1; uint24 fee; int24 tickLower; int24 tickUpper; uint256 amount0Desired; uint256 amount1Desired; uint256 amount0Min; uint256 amount1Min; address recipient; uint256 deadline; } /// @notice Creates a new position wrapped in a NFT /// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized /// a method does not exist, i.e. the pool is assumed to be initialized. /// @param params The params necessary to mint a position, encoded as `MintParams` in calldata /// @return tokenId The ID of the token that represents the minted position /// @return liquidity The amount of liquidity for this position /// @return amount0 The amount of token0 /// @return amount1 The amount of token1 function mint(MintParams calldata params) external payable returns ( uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1 ); struct IncreaseLiquidityParams { uint256 tokenId; uint256 amount0Desired; uint256 amount1Desired; uint256 amount0Min; uint256 amount1Min; uint256 deadline; } /// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender` /// @param params tokenId The ID of the token for which liquidity is being increased, /// amount0Desired The desired amount of token0 to be spent, /// amount1Desired The desired amount of token1 to be spent, /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check, /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check, /// deadline The time by which the transaction must be included to effect the change /// @return liquidity The new liquidity amount as a result of the increase /// @return amount0 The amount of token0 to acheive resulting liquidity /// @return amount1 The amount of token1 to acheive resulting liquidity function increaseLiquidity(IncreaseLiquidityParams calldata params) external payable returns ( uint128 liquidity, uint256 amount0, uint256 amount1 ); struct DecreaseLiquidityParams { uint256 tokenId; uint128 liquidity; uint256 amount0Min; uint256 amount1Min; uint256 deadline; } /// @notice Decreases the amount of liquidity in a position and accounts it to the position /// @param params tokenId The ID of the token for which liquidity is being decreased, /// amount The amount by which liquidity will be decreased, /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity, /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity, /// deadline The time by which the transaction must be included to effect the change /// @return amount0 The amount of token0 accounted to the position's tokens owed /// @return amount1 The amount of token1 accounted to the position's tokens owed function decreaseLiquidity(DecreaseLiquidityParams calldata params) external payable returns (uint256 amount0, uint256 amount1); struct CollectParams { uint256 tokenId; address recipient; uint128 amount0Max; uint128 amount1Max; } /// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient /// @param params tokenId The ID of the NFT for which tokens are being collected, /// recipient The account that should receive the tokens, /// amount0Max The maximum amount of token0 to collect, /// amount1Max The maximum amount of token1 to collect /// @return amount0 The amount of fees collected in token0 /// @return amount1 The amount of fees collected in token1 function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1); /// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens /// must be collected first. /// @param tokenId The ID of the token that is being burned function burn(uint256 tokenId) external payable; }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: modulo by zero"); return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a % b; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Math library for computing sqrt prices from ticks and vice versa /// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports /// prices between 2**-128 and 2**128 library TickMathExternal { /// @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) public pure returns (uint160 sqrtPriceX96) { uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick)); require(absTick <= uint256(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) external 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: GPL-2.0-or-later pragma solidity >=0.5.0; import "@uniswap/v3-core/contracts/libraries/FullMath.sol"; import "@uniswap/v3-core/contracts/libraries/UnsafeMath.sol"; import "@uniswap/v3-core/contracts/libraries/FixedPoint96.sol"; /// @title Functions based on Q64.96 sqrt price and liquidity /// @notice Exposes two functions from @uniswap/v3-core SqrtPriceMath /// that use square root of price as a Q64.96 and liquidity to compute deltas library SqrtPriceMathPartial { /// @notice Gets the amount0 delta between two prices /// @dev Calculates liquidity / sqrt(lower) - liquidity / sqrt(upper), /// i.e. liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower)) /// @param sqrtRatioAX96 A sqrt price /// @param sqrtRatioBX96 Another sqrt price /// @param liquidity The amount of usable liquidity /// @param roundUp Whether to round the amount up or down /// @return amount0 Amount of token0 required to cover a position of size liquidity between the two passed prices function getAmount0Delta( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity, bool roundUp ) external pure returns (uint256 amount0) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION; uint256 numerator2 = sqrtRatioBX96 - sqrtRatioAX96; require(sqrtRatioAX96 > 0); return roundUp ? UnsafeMath.divRoundingUp( FullMath.mulDivRoundingUp(numerator1, numerator2, sqrtRatioBX96), sqrtRatioAX96 ) : FullMath.mulDiv(numerator1, numerator2, sqrtRatioBX96) / sqrtRatioAX96; } /// @notice Gets the amount1 delta between two prices /// @dev Calculates liquidity * (sqrt(upper) - sqrt(lower)) /// @param sqrtRatioAX96 A sqrt price /// @param sqrtRatioBX96 Another sqrt price /// @param liquidity The amount of usable liquidity /// @param roundUp Whether to round the amount up, or down /// @return amount1 Amount of token1 required to cover a position of size liquidity between the two passed prices function getAmount1Delta( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity, bool roundUp ) external pure returns (uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return roundUp ? FullMath.mulDivRoundingUp(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96) : FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96); } }
//SPDX-License-Identifier: MIT pragma solidity =0.7.6; library Uint256Casting { /** * @notice cast a uint256 to a uint128, revert on overflow * @param y the uint256 to be downcasted * @return z the downcasted integer, now type uint128 */ function toUint128(uint256 y) internal pure returns (uint128 z) { require((z = uint128(y)) == y, "OF128"); } /** * @notice cast a uint256 to a uint96, revert on overflow * @param y the uint256 to be downcasted * @return z the downcasted integer, now type uint96 */ function toUint96(uint256 y) internal pure returns (uint96 z) { require((z = uint96(y)) == y, "OF96"); } /** * @notice cast a uint256 to a uint32, revert on overflow * @param y the uint256 to be downcasted * @return z the downcasted integer, now type uint32 */ function toUint32(uint256 y) internal pure returns (uint32 z) { require((z = uint32(y)) == y, "OF32"); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "./IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "./IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Enumerable is IERC721 { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; pragma abicoder v2; /// @title Creates and initializes V3 Pools /// @notice Provides a method for creating and initializing a pool, if necessary, for bundling with other methods that /// require the pool to exist. interface IPoolInitializer { /// @notice Creates a new pool if it does not exist, then initializes if not initialized /// @dev This method can be bundled with others via IMulticall for the first action (e.g. mint) performed against a pool /// @param token0 The contract address of token0 of the pool /// @param token1 The contract address of token1 of the pool /// @param fee The fee amount of the v3 pool for the specified token pair /// @param sqrtPriceX96 The initial square root price of the pool as a Q64.96 value /// @return pool Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary function createAndInitializePoolIfNecessary( address token0, address token1, uint24 fee, uint160 sqrtPriceX96 ) external payable returns (address pool); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; import '@openzeppelin/contracts/token/ERC721/IERC721.sol'; /// @title ERC721 with permit /// @notice Extension to ERC721 that includes a permit function for signature based approvals interface IERC721Permit is IERC721 { /// @notice The permit typehash used in the permit signature /// @return The typehash for the permit function PERMIT_TYPEHASH() external pure returns (bytes32); /// @notice The domain separator used in the permit signature /// @return The domain seperator used in encoding of permit signature function DOMAIN_SEPARATOR() external view returns (bytes32); /// @notice Approve of a specific token ID for spending by spender via signature /// @param spender The account that is being approved /// @param tokenId The ID of the token that is being approved for spending /// @param deadline The deadline timestamp by which the call must be mined for the approve to work /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s` /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s` /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v` function permit( address spender, uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external payable; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; /// @title Periphery Payments /// @notice Functions to ease deposits and withdrawals of ETH interface IPeripheryPayments { /// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH. /// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users. /// @param amountMinimum The minimum amount of WETH9 to unwrap /// @param recipient The address receiving ETH function unwrapWETH9(uint256 amountMinimum, address recipient) external payable; /// @notice Refunds any ETH balance held by this contract to the `msg.sender` /// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps /// that use ether for the input amount function refundETH() external payable; /// @notice Transfers the full amount of a token held by this contract to recipient /// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users /// @param token The contract address of the token which will be transferred to `recipient` /// @param amountMinimum The minimum amount of token required for a transfer /// @param recipient The destination address of the token function sweepToken( address token, uint256 amountMinimum, address recipient ) external payable; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Immutable state /// @notice Functions that return immutable state of the router interface IPeripheryImmutableState { /// @return Returns the address of the Uniswap V3 factory function factory() external view returns (address); /// @return Returns the address of WETH9 function WETH9() external view returns (address); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Provides functions for deriving a pool address from the factory, tokens, and the fee library PoolAddress { bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; /// @notice The identifying key of the pool struct PoolKey { address token0; address token1; uint24 fee; } /// @notice Returns PoolKey: the ordered tokens with the matched fee levels /// @param tokenA The first token of a pool, unsorted /// @param tokenB The second token of a pool, unsorted /// @param fee The fee level of the pool /// @return Poolkey The pool details with ordered token0 and token1 assignments function getPoolKey( address tokenA, address tokenB, uint24 fee ) internal pure returns (PoolKey memory) { if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); return PoolKey({token0: tokenA, token1: tokenB, fee: fee}); } /// @notice Deterministically computes the pool address given the factory and PoolKey /// @param factory The Uniswap V3 factory contract address /// @param key The PoolKey /// @return pool The contract address of the V3 pool function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { require(key.token0 < key.token1); pool = address( uint256( keccak256( abi.encodePacked( hex'ff', factory, keccak256(abi.encode(key.token0, key.token1, key.fee)), POOL_INIT_CODE_HASH ) ) ) ); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "../../introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 tokenId) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity >=0.4.0; /// @title Contains 512-bit math functions /// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision /// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits library FullMath { /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv function mulDiv( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { // 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. uint256 twos = -denominator & denominator; // 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.5.0; /// @title Math functions that do not check inputs or outputs /// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks library UnsafeMath { /// @notice Returns ceil(x / y) /// @dev division by 0 has unspecified behavior, and must be checked externally /// @param x The dividend /// @param y The divisor /// @return z The quotient, ceil(x / y) function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) { assembly { z := add(div(x, y), gt(mod(x, y), 0)) } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.4.0; /// @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 pragma solidity ^0.7.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool); /** * @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); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that never changes /// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values interface IUniswapV3PoolImmutables { /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface /// @return The contract address function factory() external view returns (address); /// @notice The first of the two tokens of the pool, sorted by address /// @return The token contract address function token0() external view returns (address); /// @notice The second of the two tokens of the pool, sorted by address /// @return The token contract address function token1() external view returns (address); /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6 /// @return The fee function fee() external view returns (uint24); /// @notice The pool tick spacing /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... /// This value is an int24 to avoid casting even though it is always positive. /// @return The tick spacing function tickSpacing() external view returns (int24); /// @notice The maximum amount of position liquidity that can use any tick in the range /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool /// @return The max amount of liquidity per tick function maxLiquidityPerTick() external view returns (uint128); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that can change /// @notice These methods compose the pool's state, and can change with any frequency including multiple times /// per transaction interface IUniswapV3PoolState { /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas /// when accessed externally. /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value /// tick The current tick of the pool, i.e. according to the last tick transition that was run. /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick /// boundary. /// observationIndex The index of the last oracle observation that was written, /// observationCardinality The current maximum number of observations stored in the pool, /// observationCardinalityNext The next maximum number of observations, to be updated when the observation. /// feeProtocol The protocol fee for both tokens of the pool. /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0 /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee. /// unlocked Whether the pool is currently locked to reentrancy function slot0() external view returns ( uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked ); /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal0X128() external view returns (uint256); /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal1X128() external view returns (uint256); /// @notice The amounts of token0 and token1 that are owed to the protocol /// @dev Protocol fees will never exceed uint128 max in either token function protocolFees() external view returns (uint128 token0, uint128 token1); /// @notice The currently in range liquidity available to the pool /// @dev This value has no relationship to the total liquidity across all ticks function liquidity() external view returns (uint128); /// @notice Look up information about a specific tick in the pool /// @param tick The tick to look up /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or /// tick upper, /// liquidityNet how much liquidity changes when the pool price crosses the tick, /// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0, /// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1, /// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick /// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick, /// secondsOutside the seconds spent on the other side of the tick from the current tick, /// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false. /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0. /// In addition, these values are only relative and must be used only in comparison to previous snapshots for /// a specific position. function ticks(int24 tick) external view returns ( uint128 liquidityGross, int128 liquidityNet, uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128, int56 tickCumulativeOutside, uint160 secondsPerLiquidityOutsideX128, uint32 secondsOutside, bool initialized ); /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information function tickBitmap(int16 wordPosition) external view returns (uint256); /// @notice Returns the information about a position by the position's key /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper /// @return _liquidity The amount of liquidity in the position, /// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke, /// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke, /// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke, /// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke function positions(bytes32 key) external view returns ( uint128 _liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1 ); /// @notice Returns data about a specific observation index /// @param index The element of the observations array to fetch /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time /// ago, rather than at a specific index in the array. /// @return blockTimestamp The timestamp of the observation, /// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp, /// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp, /// Returns initialized whether the observation has been initialized and the values are safe to use function observations(uint256 index) external view returns ( uint32 blockTimestamp, int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128, bool initialized ); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that is not stored /// @notice Contains view functions to provide information about the pool that is computed rather than stored on the /// blockchain. The functions here may have variable gas costs. interface IUniswapV3PoolDerivedState { /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick, /// you must call it with secondsAgos = [3600, 0]. /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio. /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block /// timestamp function observe(uint32[] calldata secondsAgos) external view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s); /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed. /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first /// snapshot is taken and the second snapshot is taken. /// @param tickLower The lower tick of the range /// @param tickUpper The upper tick of the range /// @return tickCumulativeInside The snapshot of the tick accumulator for the range /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range /// @return secondsInside The snapshot of seconds per liquidity for the range function snapshotCumulativesInside(int24 tickLower, int24 tickUpper) external view returns ( int56 tickCumulativeInside, uint160 secondsPerLiquidityInsideX128, uint32 secondsInside ); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Permissionless pool actions /// @notice Contains pool methods that can be called by anyone interface IUniswapV3PoolActions { /// @notice Sets the initial price for the pool /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96 function initialize(uint160 sqrtPriceX96) external; /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends /// on tickLower, tickUpper, the amount of liquidity, and the current price. /// @param recipient The address for which the liquidity will be created /// @param tickLower The lower tick of the position in which to add liquidity /// @param tickUpper The upper tick of the position in which to add liquidity /// @param amount The amount of liquidity to mint /// @param data Any data that should be passed through to the callback /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback function mint( address recipient, int24 tickLower, int24 tickUpper, uint128 amount, bytes calldata data ) external returns (uint256 amount0, uint256 amount1); /// @notice Collects tokens owed to a position /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity. /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity. /// @param recipient The address which should receive the fees collected /// @param tickLower The lower tick of the position for which to collect fees /// @param tickUpper The upper tick of the position for which to collect fees /// @param amount0Requested How much token0 should be withdrawn from the fees owed /// @param amount1Requested How much token1 should be withdrawn from the fees owed /// @return amount0 The amount of fees collected in token0 /// @return amount1 The amount of fees collected in token1 function collect( address recipient, int24 tickLower, int24 tickUpper, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0 /// @dev Fees must be collected separately via a call to #collect /// @param tickLower The lower tick of the position for which to burn liquidity /// @param tickUpper The upper tick of the position for which to burn liquidity /// @param amount How much liquidity to burn /// @return amount0 The amount of token0 sent to the recipient /// @return amount1 The amount of token1 sent to the recipient function burn( int24 tickLower, int24 tickUpper, uint128 amount ) external returns (uint256 amount0, uint256 amount1); /// @notice Swap token0 for token1, or token1 for token0 /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback /// @param recipient The address to receive the output of the swap /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0 /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative) /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this /// value after the swap. If one for zero, the price cannot be greater than this value after the swap /// @param data Any data to be passed through to the callback /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive function swap( address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data ) external returns (int256 amount0, int256 amount1); /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling /// with 0 amount{0,1} and sending the donation amount(s) from the callback /// @param recipient The address which will receive the token0 and token1 amounts /// @param amount0 The amount of token0 to send /// @param amount1 The amount of token1 to send /// @param data Any data to be passed through to the callback function flash( address recipient, uint256 amount0, uint256 amount1, bytes calldata data ) external; /// @notice Increase the maximum number of price and liquidity observations that this pool will store /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to /// the input observationCardinalityNext. /// @param observationCardinalityNext The desired minimum number of observations for the pool to store function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Permissioned pool actions /// @notice Contains pool methods that may only be called by the factory owner interface IUniswapV3PoolOwnerActions { /// @notice Set the denominator of the protocol's % share of the fees /// @param feeProtocol0 new protocol fee for token0 of the pool /// @param feeProtocol1 new protocol fee for token1 of the pool function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; /// @notice Collect the protocol fee accrued to the pool /// @param recipient The address to which collected protocol fees should be sent /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 /// @return amount0 The protocol fee collected in token0 /// @return amount1 The protocol fee collected in token1 function collectProtocol( address recipient, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Events emitted by a pool /// @notice Contains all events emitted by the pool interface IUniswapV3PoolEvents { /// @notice Emitted exactly once by a pool when #initialize is first called on the pool /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96 /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool event Initialize(uint160 sqrtPriceX96, int24 tick); /// @notice Emitted when liquidity is minted for a given position /// @param sender The address that minted the liquidity /// @param owner The owner of the position and recipient of any minted liquidity /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity minted to the position range /// @param amount0 How much token0 was required for the minted liquidity /// @param amount1 How much token1 was required for the minted liquidity event Mint( address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted when fees are collected by the owner of a position /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees /// @param owner The owner of the position for which fees are collected /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount0 The amount of token0 fees collected /// @param amount1 The amount of token1 fees collected event Collect( address indexed owner, address recipient, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount0, uint128 amount1 ); /// @notice Emitted when a position's liquidity is removed /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect /// @param owner The owner of the position for which liquidity is removed /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity to remove /// @param amount0 The amount of token0 withdrawn /// @param amount1 The amount of token1 withdrawn event Burn( address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted by the pool for any swaps between token0 and token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the output of the swap /// @param amount0 The delta of the token0 balance of the pool /// @param amount1 The delta of the token1 balance of the pool /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96 /// @param liquidity The liquidity of the pool after the swap /// @param tick The log base 1.0001 of price of the pool after the swap event Swap( address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick ); /// @notice Emitted by the pool for any flashes of token0/token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the tokens from flash /// @param amount0 The amount of token0 that was flashed /// @param amount1 The amount of token1 that was flashed /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee event Flash( address indexed sender, address indexed recipient, uint256 amount0, uint256 amount1, uint256 paid0, uint256 paid1 ); /// @notice Emitted by the pool for increases to the number of observations that can be stored /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index /// just before a mint/swap/burn. /// @param observationCardinalityNextOld The previous value of the next observation cardinality /// @param observationCardinalityNextNew The updated value of the next observation cardinality event IncreaseObservationCardinalityNext( uint16 observationCardinalityNextOld, uint16 observationCardinalityNextNew ); /// @notice Emitted when the protocol fee is changed by the pool /// @param feeProtocol0Old The previous value of the token0 protocol fee /// @param feeProtocol1Old The previous value of the token1 protocol fee /// @param feeProtocol0New The updated value of the token0 protocol fee /// @param feeProtocol1New The updated value of the token1 protocol fee event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New); /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner /// @param sender The address that collects the protocol fees /// @param recipient The address that receives the collected protocol fees /// @param amount0 The amount of token0 protocol fees that is withdrawn /// @param amount0 The amount of token1 protocol fees that is withdrawn event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1); }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "../../utils/Context.sol"; import "./IERC20.sol"; import "../../math/SafeMath.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view virtual returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal virtual { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
// SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <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 GSN 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 payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @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-2.0-or-later pragma solidity >=0.7.0; /// @title Optimized overflow and underflow safe math operations /// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost library LowGasSafeMath { /// @notice Returns x + y, reverts if sum overflows uint256 /// @param x The augend /// @param y The addend /// @return z The sum of x and y function add(uint256 x, uint256 y) internal pure returns (uint256 z) { require((z = x + y) >= x); } /// @notice Returns x - y, reverts if underflows /// @param x The minuend /// @param y The subtrahend /// @return z The difference of x and y function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { require((z = x - y) <= x); } /// @notice Returns x * y, reverts if overflows /// @param x The multiplicand /// @param y The multiplier /// @return z The product of x and y function mul(uint256 x, uint256 y) internal pure returns (uint256 z) { require(x == 0 || (z = x * y) / x == y); } /// @notice Returns x + y, reverts if overflows or underflows /// @param x The augend /// @param y The addend /// @return z The sum of x and y function add(int256 x, int256 y) internal pure returns (int256 z) { require((z = x + y) >= x == (y >= 0)); } /// @notice Returns x - y, reverts if overflows or underflows /// @param x The minuend /// @param y The subtrahend /// @return z The difference of x and y function sub(int256 x, int256 y) internal pure returns (int256 z) { require((z = x - y) <= x == (y >= 0)); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.6.0; import './BytesLib.sol'; /// @title Functions for manipulating path data for multihop swaps library Path { using BytesLib for bytes; /// @dev The length of the bytes encoded address uint256 private constant ADDR_SIZE = 20; /// @dev The length of the bytes encoded fee uint256 private constant FEE_SIZE = 3; /// @dev The offset of a single token address and pool fee uint256 private constant NEXT_OFFSET = ADDR_SIZE + FEE_SIZE; /// @dev The offset of an encoded pool key uint256 private constant POP_OFFSET = NEXT_OFFSET + ADDR_SIZE; /// @dev The minimum length of an encoding that contains 2 or more pools uint256 private constant MULTIPLE_POOLS_MIN_LENGTH = POP_OFFSET + NEXT_OFFSET; /// @notice Returns true iff the path contains two or more pools /// @param path The encoded swap path /// @return True if path contains two or more pools, otherwise false function hasMultiplePools(bytes memory path) internal pure returns (bool) { return path.length >= MULTIPLE_POOLS_MIN_LENGTH; } /// @notice Returns the number of pools in the path /// @param path The encoded swap path /// @return The number of pools in the path function numPools(bytes memory path) internal pure returns (uint256) { // Ignore the first token address. From then on every fee and token offset indicates a pool. return ((path.length - ADDR_SIZE) / NEXT_OFFSET); } /// @notice Decodes the first pool in path /// @param path The bytes encoded swap path /// @return tokenA The first token of the given pool /// @return tokenB The second token of the given pool /// @return fee The fee level of the pool function decodeFirstPool(bytes memory path) internal pure returns ( address tokenA, address tokenB, uint24 fee ) { tokenA = path.toAddress(0); fee = path.toUint24(ADDR_SIZE); tokenB = path.toAddress(NEXT_OFFSET); } /// @notice Gets the segment corresponding to the first pool in the path /// @param path The bytes encoded swap path /// @return The segment containing all data necessary to target the first pool in the path function getFirstPool(bytes memory path) internal pure returns (bytes memory) { return path.slice(0, POP_OFFSET); } /// @notice Skips a token + fee element from the buffer and returns the remainder /// @param path The swap path /// @return The remaining token + fee elements in the path function skipToken(bytes memory path) internal pure returns (bytes memory) { return path.slice(NEXT_OFFSET, path.length - NEXT_OFFSET); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.7.6; import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol'; import './PoolAddress.sol'; /// @notice Provides validation for callbacks from Uniswap V3 Pools library CallbackValidation { /// @notice Returns the address of a valid Uniswap V3 Pool /// @param factory The contract address of the Uniswap V3 factory /// @param tokenA The contract address of either token0 or token1 /// @param tokenB The contract address of the other token /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip /// @return pool The V3 pool contract address function verifyCallback( address factory, address tokenA, address tokenB, uint24 fee ) internal view returns (IUniswapV3Pool pool) { return verifyCallback(factory, PoolAddress.getPoolKey(tokenA, tokenB, fee)); } /// @notice Returns the address of a valid Uniswap V3 Pool /// @param factory The contract address of the Uniswap V3 factory /// @param poolKey The identifying key of the V3 pool /// @return pool The V3 pool contract address function verifyCallback(address factory, PoolAddress.PoolKey memory poolKey) internal view returns (IUniswapV3Pool pool) { pool = IUniswapV3Pool(PoolAddress.computeAddress(factory, poolKey)); require(msg.sender == address(pool)); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Math library for computing sqrt prices from ticks and vice versa /// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports /// prices between 2**-128 and 2**128 library TickMath { /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128 int24 internal constant MIN_TICK = -887272; /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128 int24 internal constant MAX_TICK = -MIN_TICK; /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK) uint160 internal constant MIN_SQRT_RATIO = 4295128739; /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK) uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342; /// @notice Calculates sqrt(1.0001^tick) * 2^96 /// @dev Throws if |tick| > max tick /// @param tick The input tick for the above formula /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0) /// at the given tick function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) { uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick)); require(absTick <= uint256(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: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Safe casting methods /// @notice Contains methods for safely casting between types library SafeCast { /// @notice Cast a uint256 to a uint160, revert on overflow /// @param y The uint256 to be downcasted /// @return z The downcasted integer, now type uint160 function toUint160(uint256 y) internal pure returns (uint160 z) { require((z = uint160(y)) == y); } /// @notice Cast a int256 to a int128, revert on overflow or underflow /// @param y The int256 to be downcasted /// @return z The downcasted integer, now type int128 function toInt128(int256 y) internal pure returns (int128 z) { require((z = int128(y)) == y); } /// @notice Cast a uint256 to a int256, revert on overflow /// @param y The uint256 to be casted /// @return z The casted integer, now type int256 function toInt256(uint256 y) internal pure returns (int256 z) { require(y < 2**255); z = int256(y); } }
// SPDX-License-Identifier: GPL-2.0-or-later /* * @title Solidity Bytes Arrays Utils * @author Gonçalo Sá <[email protected]> * * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity. * The library lets you concatenate, slice and type cast bytes arrays both in memory and storage. */ pragma solidity >=0.5.0 <0.8.0; library BytesLib { function slice( bytes memory _bytes, uint256 _start, uint256 _length ) internal pure returns (bytes memory) { require(_length + 31 >= _length, 'slice_overflow'); require(_start + _length >= _start, 'slice_overflow'); require(_bytes.length >= _start + _length, 'slice_outOfBounds'); bytes memory tempBytes; assembly { switch iszero(_length) case 0 { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // The first word of the slice result is potentially a partial // word read from the original array. To read it, we calculate // the length of that partial word and start copying that many // bytes into the array. The first word we copy will start with // data we don't care about, but the last `lengthmod` bytes will // land at the beginning of the contents of the new array. When // we're done copying, we overwrite the full first word with // the actual length of the slice. let lengthmod := and(_length, 31) // The multiplication in the next line is necessary // because when slicing multiples of 32 bytes (lengthmod == 0) // the following copy loop was copying the origin's length // and then ending prematurely not copying everything it should. let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) let end := add(mc, _length) for { // The multiplication in the next line has the same exact purpose // as the one above. let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } mstore(tempBytes, _length) //update free-memory pointer //allocating the array padded to 32 bytes like the compiler does now mstore(0x40, and(add(mc, 31), not(31))) } //if we want a zero-length slice let's just return a zero-length array default { tempBytes := mload(0x40) //zero out the 32 bytes slice we are about to return //we need to do it because Solidity does not garbage collect mstore(tempBytes, 0) mstore(0x40, add(tempBytes, 0x20)) } } return tempBytes; } function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) { require(_start + 20 >= _start, 'toAddress_overflow'); require(_bytes.length >= _start + 20, 'toAddress_outOfBounds'); address tempAddress; assembly { tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000) } return tempAddress; } function toUint24(bytes memory _bytes, uint256 _start) internal pure returns (uint24) { require(_start + 3 >= _start, 'toUint24_overflow'); require(_bytes.length >= _start + 3, 'toUint24_outOfBounds'); uint24 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x3), _start)) } return tempUint; } }
{ "optimizer": { "enabled": true, "runs": 800 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_wSqueethController","type":"address"},{"internalType":"address","name":"_oracle","type":"address"},{"internalType":"address","name":"_weth","type":"address"},{"internalType":"address","name":"_uniswapFactory","type":"address"},{"internalType":"address","name":"_ethWSqueethPool","type":"address"},{"internalType":"address","name":"_timelock","type":"address"},{"internalType":"address","name":"_crabMigration","type":"address"},{"internalType":"uint256","name":"_hedgeTimeThreshold","type":"uint256"},{"internalType":"uint256","name":"_hedgePriceThreshold","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"depositor","type":"address"},{"indexed":false,"internalType":"uint256","name":"wSqueethAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lpAmount","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"depositor","type":"address"},{"indexed":false,"internalType":"uint256","name":"depositedAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tradedAmountOut","type":"uint256"}],"name":"FlashDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"depositor","type":"address"},{"indexed":false,"internalType":"uint256","name":"flashswapDebt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"excess","type":"uint256"}],"name":"FlashDepositCallback","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"withdrawer","type":"address"},{"indexed":false,"internalType":"uint256","name":"crabAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"wSqueethAmount","type":"uint256"}],"name":"FlashWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"withdrawer","type":"address"},{"indexed":false,"internalType":"uint256","name":"flashswapDebt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"excess","type":"uint256"}],"name":"FlashWithdrawCallback","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"bidId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"quantity","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isBuying","type":"bool"},{"indexed":false,"internalType":"uint256","name":"clearingPrice","type":"uint256"}],"name":"HedgeOTC","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"trader","type":"address"},{"indexed":false,"internalType":"uint256","name":"bidId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"quantity","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"price","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isBuying","type":"bool"},{"indexed":false,"internalType":"uint256","name":"clearingPrice","type":"uint256"}],"name":"HedgeOTCSingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newHedgePriceThreshold","type":"uint256"}],"name":"SetHedgePriceThreshold","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newHedgeTimeThreshold","type":"uint256"}],"name":"SetHedgeTimeThreshold","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"newHedgingTwapPeriod","type":"uint32"}],"name":"SetHedgingTwapPeriod","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"otcPriceTolerance","type":"uint256"}],"name":"SetOTCPriceTolerance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newCapAmount","type":"uint256"}],"name":"SetStrategyCap","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":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newStrategy","type":"address"},{"indexed":false,"internalType":"uint256","name":"vaultId","type":"uint256"}],"name":"VaultTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"withdrawer","type":"address"},{"indexed":false,"internalType":"uint256","name":"crabAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"wSqueethAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ethWithdrawn","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"withdrawer","type":"address"},{"indexed":false,"internalType":"uint256","name":"crabAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ethWithdrawn","type":"uint256"}],"name":"WithdrawShutdown","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_OTC_PRICE_TOLERANCE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"POWER_PERP_PERIOD","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","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":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"checkPriceHedge","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"checkTimeHedge","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"crabMigration","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"ethWSqueethPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_ethToDeposit","type":"uint256"},{"internalType":"uint24","name":"_poolFee","type":"uint24"}],"name":"flashDeposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_crabAmount","type":"uint256"},{"internalType":"uint256","name":"_maxEthToPay","type":"uint256"},{"internalType":"uint24","name":"_poolFee","type":"uint24"}],"name":"flashWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getStrategyVaultId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getVaultDetails","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_crabAmount","type":"uint256"}],"name":"getWsqueethFromCrabAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_totalQuantity","type":"uint256"},{"internalType":"uint256","name":"_clearingPrice","type":"uint256"},{"internalType":"bool","name":"_isHedgeBuying","type":"bool"},{"components":[{"internalType":"uint256","name":"bidId","type":"uint256"},{"internalType":"address","name":"trader","type":"address"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"bool","name":"isBuying","type":"bool"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct CrabStrategyV2.Order[]","name":"_orders","type":"tuple[]"}],"name":"hedgeOTC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"hedgePriceThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hedgeTimeThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hedgingTwapPeriod","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_wSqueethToMint","type":"uint256"},{"internalType":"uint256","name":"_crabSharesToMint","type":"uint256"},{"internalType":"uint256","name":"_timeAtLastHedge","type":"uint256"},{"internalType":"uint256","name":"_priceAtLastHedge","type":"uint256"},{"internalType":"uint256","name":"_strategyCap","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"isInitialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"nonces","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracle","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"otcPriceTolerance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"powerTokenController","outputs":[{"internalType":"contract IController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"priceAtLastHedge","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"redeemShortShutdown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_hedgePriceThreshold","type":"uint256"}],"name":"setHedgePriceThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_hedgeTimeThreshold","type":"uint256"}],"name":"setHedgeTimeThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_hedgingTwapPeriod","type":"uint32"}],"name":"setHedgingTwapPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_nonce","type":"uint256"}],"name":"setNonceTrue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_otcPriceTolerance","type":"uint256"}],"name":"setOTCPriceTolerance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_capAmount","type":"uint256"}],"name":"setStrategyCap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"strategyCap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"timeAtLastHedge","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"timelock","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","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":"address","name":"_newStrategy","type":"address"}],"name":"transferVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"uniswapV3SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"vaultId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wPowerPerp","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_crabAmount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_crabAmount","type":"uint256"}],"name":"withdrawShutdown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
61022060405266b1a2bc2ec50000600955600a805463ffffffff19166101a41790553480156200002e57600080fd5b506040516200621538038062006215833981016040819052620000519162000669565b60405180604001604052806007815260200166437261624f544360c81b815250604051806040016040528060018152602001601960f91b815250878b8a6040518060400160405280601081526020016f21b930b11029ba3930ba32b3bc903b1960811b8152506040518060400160405280600681526020016521b930b13b1960d11b81525081818160039080519060200190620000f09291906200057c565b508051620001069060049060208401906200057c565b50506005805460ff19166012179055506001600160a01b038416620001485760405162461bcd60e51b81526004016200013f90620007af565b60405180910390fd5b6001600160a01b038316620001715760405162461bcd60e51b81526004016200013f90620007e6565b606083901b6001600160601b03191660805260058054610100600160a81b0319166101006001600160a01b0387811682029290921792839055604080516307f07b1360e41b815290519190930490911691637f07b130916004808301926020929190829003018186803b158015620001e857600080fd5b505afa158015620001fd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000223919062000645565b6001600160601b031960609190911b1660a052600554604051630728cf2360e31b81526101009091046001600160a01b0316906339467918906200027190600090819081906004016200072a565b602060405180830381600087803b1580156200028c57600080fd5b505af1158015620002a1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620002c7919062000711565b60c052505050506001600160a01b038116620002f75760405162461bcd60e51b81526004016200013f906200075c565b60601b6001600160601b03191660e052600160065560006200031862000510565b600780546001600160a01b0319166001600160a01b038316908117909155604051919250906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a35081516020808401919091208251918301919091206101408290526101608190527f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f620003b162000514565b61012052620003c281848462000518565b6101005261018052505050506001600160a01b038816620003f75760405162461bcd60e51b81526004016200013f9062000855565b6001600160a01b038416620004205760405162461bcd60e51b81526004016200013f906200081d565b6001600160a01b038516620004495760405162461bcd60e51b81526004016200013f9062000871565b6001600160a01b038316620004725760405162461bcd60e51b81526004016200013f9062000740565b60008211620004955760405162461bcd60e51b81526004016200013f9062000793565b600081118015620004ae5750670de0b6b3a76400008111155b620004cd5760405162461bcd60e51b81526004016200013f9062000839565b6001600160601b0319606098891b81166101c05294881b85166101a052600b91909155600c5590851b82166101e05290931b90921661020052506200088d915050565b3390565b4690565b60008383836200052762000514565b3060405160200180868152602001858152602001848152602001838152602001826001600160a01b03168152602001955050505050506040516020818303038152906040528051906020012090509392505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282620005b45760008555620005ff565b82601f10620005cf57805160ff1916838001178555620005ff565b82800160010185558215620005ff579182015b82811115620005ff578251825591602001919060010190620005e2565b506200060d92915062000611565b5090565b5b808211156200060d576000815560010162000612565b80516001600160a01b03811681146200064057600080fd5b919050565b60006020828403121562000657578081fd5b620006628262000628565b9392505050565b60008060008060008060008060006101208a8c03121562000688578485fd5b620006938a62000628565b9850620006a360208b0162000628565b9750620006b360408b0162000628565b9650620006c360608b0162000628565b9550620006d360808b0162000628565b9450620006e360a08b0162000628565b9350620006f360c08b0162000628565b925060e08a015191506101008a015190509295985092959850929598565b60006020828403121562000723578081fd5b5051919050565b9283526020830191909152604082015260600190565b602080825260029082015261219b60f11b604082015260600190565b60208082526017908201527f696e76616c696420666163746f72792061646472657373000000000000000000604082015260600190565b602080825260029082015261433760f01b604082015260600190565b6020808252601a908201527f696e76616c696420636f6e74726f6c6c65722061646472657373000000000000604082015260600190565b60208082526014908201527f696e76616c696420776574682061646472657373000000000000000000000000604082015260600190565b60208082526002908201526110cd60f21b604082015260600190565b602080825260029082015261086760f31b604082015260600190565b602080825260029082015261433360f01b604082015260600190565b602080825260029082015261433560f01b604082015260600190565b60805160601c60a05160601c60c05160e05160601c61010051610120516101405161016051610180516101a05160601c6101c05160601c6101e05160601c6102005160601c615820620009f560003980610bb55280611d54525080611b495280611d2752508061119852806129395280612ace52806144a2525080610f4452806129665280612afb52806144c352508061264852508061268a5250806126695250806125ef52508061261f525080611a5f5280611fc45280614463525080610cb65280610fb6528061146e5280611c485280611cee5280612859528061328d5280613b3a5250806111bc52806118df52806120b052806129885280612b1d5280613329528061357952806136ad5280613a8152806144e452508061037f5280610f2052806118be52806120d152806129aa5280612b3f5280612e345280612ed65280612f6e5280612ff35280613465528061376152806137e7528061450552506158206000f3fe60806040526004361061036f5760003560e01c80637f07b130116101c6578063cae74029116100f7578063e9c3cb4f11610095578063f5d278e41161006f578063f5d278e41461095e578063f73e19c314610973578063fa461e3314610993578063fc5b73ff146109b3576103e1565b8063e9c3cb4f14610914578063f101d92f14610929578063f2fde38b1461093e576103e1565b8063d2dd9f79116100d1578063d2dd9f79146108ac578063d33219b4146108cc578063dcbab608146108e1578063dd62ed3e146108f4576103e1565b8063cae740291461087a578063cfa70b181461088f578063d0e30db0146108a4576103e1565b8063a457c2d711610164578063b52b7ff01161013e578063b52b7ff014610810578063bdd438b814610830578063c245168914610850578063c45a015514610865576103e1565b8063a457c2d7146107b0578063a9059cbb146107d0578063b24f719b146107f0576103e1565b80638f8b8dbc116101a05780638f8b8dbc1461074657806395d89b41146107665780639ff69a511461077b578063a319b29f1461079b576103e1565b80637f07b1301461070757806388626eb81461071c5780638da5cb5b14610731576103e1565b80633d65fdac116102a057806366a91b761161023e57806370a082311161021857806370a082311461069d578063715018a6146106bd5780637bcdc16e146106d25780637dc0d1d0146106f2576103e1565b806366a91b761461065e57806367b8c345146106735780636c1040a914610688576103e1565b80634d76e6fc1161027a5780634d76e6fc146105ef578063502e1a1614610604578063533092ef1461062457806363bbc4b614610649576103e1565b80633d65fdac146105a55780633dcb0c5d146105c55780633fc8cef3146105da576103e1565b8063313ce5671161030d578063392e53cd116102e7578063392e53cd1461052e5780633950935114610543578063395ebb69146105635780633d3a62ee14610585576103e1565b8063313ce567146104e257806333194c0a146105045780633644e51514610519576103e1565b806318160ddd1161034957806318160ddd1461045e57806323b872dd14610480578063281e78d1146104a05780632e1a7d4d146104c2576103e1565b806306fdde03146103e6578063095ea7b3146104115780630ca514cd1461043e576103e1565b366103e157336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614806103ba575060055461010090046001600160a01b031633145b6103df5760405162461bcd60e51b81526004016103d69061547e565b60405180910390fd5b005b600080fd5b3480156103f257600080fd5b506103fb6109c6565b604051610408919061511f565b60405180910390f35b34801561041d57600080fd5b5061043161042c366004614a72565b610a5d565b60405161040891906150d3565b34801561044a57600080fd5b506103df610459366004614cd2565b610a7b565b34801561046a57600080fd5b50610473610b25565b6040516104089190614fab565b34801561048c57600080fd5b5061043161049b366004614a32565b610b2b565b3480156104ac57600080fd5b506104b5610bb3565b6040516104089190614fb4565b3480156104ce57600080fd5b506103df6104dd366004614cd2565b610bd7565b3480156104ee57600080fd5b506104f7610cab565b604051610408919061559b565b34801561051057600080fd5b50610473610cb4565b34801561052557600080fd5b50610473610cd8565b34801561053a57600080fd5b50610431610ce7565b34801561054f57600080fd5b5061043161055e366004614a72565b610cf8565b34801561056f57600080fd5b50610578610d46565b604051610408919061558a565b34801561059157600080fd5b506103df6105a0366004614cd2565b610d4c565b3480156105b157600080fd5b506103df6105c0366004614cd2565b610ee4565b3480156105d157600080fd5b506104b5610f0a565b3480156105e657600080fd5b506104b5610f1e565b3480156105fb57600080fd5b506104b5610f42565b34801561061057600080fd5b5061043161061f366004614a72565b610f66565b34801561063057600080fd5b50610639610f86565b6040516104089493929190615078565b34801561065557600080fd5b50610473610fa2565b34801561066a57600080fd5b50610473610fa8565b34801561067f57600080fd5b50610473610fae565b34801561069457600080fd5b50610473610fb4565b3480156106a957600080fd5b506104736106b83660046149c2565b610fd8565b3480156106c957600080fd5b506103df610ff7565b3480156106de57600080fd5b506103df6106ed366004614cd2565b6110c2565b3480156106fe57600080fd5b506104b5611196565b34801561071357600080fd5b506104b56111ba565b34801561072857600080fd5b506104316111de565b34801561073d57600080fd5b506104b56111e8565b34801561075257600080fd5b506103df610761366004614ef1565b6111f7565b34801561077257600080fd5b506103fb6112d7565b34801561078757600080fd5b506103df610796366004614cd2565b611338565b3480156107a757600080fd5b506103df611409565b3480156107bc57600080fd5b506104316107cb366004614a72565b6114ca565b3480156107dc57600080fd5b506104316107eb366004614a72565b611532565b3480156107fc57600080fd5b506103df61080b366004614d2d565b611546565b34801561081c57600080fd5b506103df61082b366004614e83565b61184f565b34801561083c57600080fd5b506103df61084b366004614cd2565b611976565b34801561085c57600080fd5b50610431611a53565b34801561087157600080fd5b506104b5611a5d565b34801561088657600080fd5b50610473611a81565b34801561089b57600080fd5b50610473611a87565b6103df611a93565b3480156108b857600080fd5b506103df6108c73660046149c2565b611b3e565b3480156108d857600080fd5b506104b5611d25565b6103df6108ef366004614eb7565b611d49565b34801561090057600080fd5b5061047361090f3660046149fa565b611e0f565b34801561092057600080fd5b50610473611e3a565b34801561093557600080fd5b50610473611e40565b34801561094a57600080fd5b506103df6109593660046149c2565b611e46565b34801561096a57600080fd5b50610578611f68565b34801561097f57600080fd5b5061047361098e366004614cd2565b611f74565b34801561099f57600080fd5b506103df6109ae366004614adc565b611f7f565b6103df6109c1366004614d02565b612025565b60038054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610a525780601f10610a2757610100808354040283529160200191610a52565b820191906000526020600020905b815481529060010190602001808311610a3557829003601f168201915b505050505090505b90565b6000610a71610a6a612172565b8484612176565b5060015b92915050565b610a83612172565b6001600160a01b0316610a946111e8565b6001600160a01b031614610aef576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600a54640100000000900460ff16610b195760405162461bcd60e51b81526004016103d6906151f7565b610b2281612262565b50565b60025490565b6000610b38848484612297565b610ba884610b44612172565b610ba385604051806060016040528060288152602001615734602891396001600160a01b038a16600090815260016020526040812090610b82612172565b6001600160a01b0316815260208101919091526040016000205491906123f2565b612176565b5060015b9392505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60026006541415610c2f576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b60026006556000610c3f82612489565b90506000610c5033848460006124b4565b9050610c5c3382612501565b336001600160a01b03167f02f25270a4d87bea75db541cdfe559334a275b4a233520ed6c0a2429667cca94848484604051610c9993929190615574565b60405180910390a25050600160065550565b60055460ff1690565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000610ce26125eb565b905090565b600a54640100000000900460ff1681565b6000610a71610d05612172565b84610ba38560016000610d16612172565b6001600160a01b03908116825260208083019390935260409182016000908120918c1681529252902054906126b5565b6101a481565b60026006541415610da4576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b6002600681905550600560019054906101000a90046001600160a01b03166001600160a01b031663ff9475256040518163ffffffff1660e01b8152600401602060405180830381600087803b158015610dfc57600080fd5b505af1158015610e10573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e349190614a9d565b610e505760405162461bcd60e51b81526004016103d6906153ee565b600f5460ff16610e725760405162461bcd60e51b81526004016103d6906152aa565b6000610e8582610e80610b25565b61270f565b90506000610e93824761271b565b9050610e9f3384612727565b610ea93382612501565b336001600160a01b03167fe9ab9870b9093d99f8e981919f65ad09b7ae90ff80f1031639af9e0357eb9ed68483604051610c99929190615549565b33600090815260106020908152604080832093835292905220805460ff19166001179055565b60055461010090046001600160a01b031681565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b601060209081526000928352604080842090915290825290205460ff1681565b600080600080610f94612823565b935093509350935090919293565b600e5481565b600b5481565b600d5481565b7f000000000000000000000000000000000000000000000000000000000000000090565b6001600160a01b0381166000908152602081905260409020545b919050565b610fff612172565b6001600160a01b03166110106111e8565b6001600160a01b03161461106b576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6007546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a36007805473ffffffffffffffffffffffffffffffffffffffff19169055565b6110ca612172565b6001600160a01b03166110db6111e8565b6001600160a01b031614611136576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600081116111565760405162461bcd60e51b81526004016103d69061540b565b600b8190556040517f28e0e4ee0b14d4b056ce88e1bcd890ccd32b22e213723c8765901381b5eae7059061118b908390614fab565b60405180910390a150565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000610ce261291a565b6007546001600160a01b031690565b6111ff612172565b6001600160a01b03166112106111e8565b6001600160a01b03161461126b576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60b48163ffffffff1610156112925760405162461bcd60e51b81526004016103d690615169565b600a805463ffffffff191663ffffffff83161790556040517f1cd9c7f99a5530a38c8f2b387dcc78e8a76cb5b203e0c4316a66777d993dee359061118b90839061558a565b60048054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610a525780601f10610a2757610100808354040283529160200191610a52565b611340612172565b6001600160a01b03166113516111e8565b6001600160a01b0316146113ac576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6702c68af0bb1400008111156113d45760405162461bcd60e51b81526004016103d6906153d1565b60098190556040517f829c71710efa317bbdb8e5c4ca2b6d2551b7c2d7d37ea199975807eb3f5c0e7c9061118b908390614fab565b600a54640100000000900460ff166114335760405162461bcd60e51b81526004016103d6906151f7565b600f8054600160ff19909116179055600554604051634bf7d4a160e11b81526101009091046001600160a01b0316906397efa94290611496907f000000000000000000000000000000000000000000000000000000000000000090600401614fab565b600060405180830381600087803b1580156114b057600080fd5b505af11580156114c4573d6000803e3d6000fd5b50505050565b6000610a716114d7612172565b84610ba3856040518060600160405280602581526020016157c66025913960016000611501612172565b6001600160a01b03908116825260208083019390935260409182016000908120918d168152925290205491906123f2565b6000610a7161153f612172565b8484612297565b61154e612172565b6001600160a01b031661155f6111e8565b6001600160a01b0316146115ba576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600a54640100000000900460ff166115e45760405162461bcd60e51b81526004016103d6906151f7565b600083116116045760405162461bcd60e51b81526004016103d690615398565b61160c612a90565b8061161a575061161a61291a565b6116365760405162461bcd60e51b81526004016103d690615444565b6116408383612ab1565b42600d55600e839055805184906000908390829061165a57fe5b602002602001015160600151905060008360008151811061167757fe5b602002602001015160600151905060008460008151811061169457fe5b602002602001015160800151905080151586151514156116c65760405162461bcd60e51b81526004016103d690615324565b60005b85518110156117ef578581815181106116de57fe5b60200260200101516060015192508115158682815181106116fb57fe5b6020026020010151608001511515146117265760405162461bcd60e51b81526004016103d690615427565b8615611751578383101561174c5760405162461bcd60e51b81526004016103d690615341565b611771565b838311156117715760405162461bcd60e51b81526004016103d690615341565b829350611792858988848151811061178557fe5b6020026020010151612c71565b85818151811061179e57fe5b6020026020010151604001518511156117e2576117db8682815181106117c057fe5b602002602001015160400151866130e390919063ffffffff16565b94506117e7565b6117ef565b6001016116c9565b507fbbc3ba742efe346cfdf333000069964e0ee3087c68da267dac977d299f2366fb8560008151811061181e57fe5b60200260200101516000015189888a60405161183d9493929190615557565b60405180910390a15050505050505050565b600260065414156118a7576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b600260065560006118b784612489565b90506119287f00000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000084848760018a6040516020016119149190614fab565b60405160208183030381529060405261313b565b336001600160a01b03167fa13b272c1cf13ba724064d3d4809d9f557aab8da2bb582cba031a2f57e728e9d8583604051611963929190615549565b60405180910390a2505060016006555050565b61197e612172565b6001600160a01b031661198f6111e8565b6001600160a01b0316146119ea576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600081118015611a025750670de0b6b3a76400008111155b611a1e5760405162461bcd60e51b81526004016103d6906154d4565b600c8190556040517f789e4b8ad1c375952cea7f07c9b3b6619a84b406432b948246cecb8ced96b9fa9061118b908390614fab565b6000610ce2612a90565b7f000000000000000000000000000000000000000000000000000000000000000081565b60085481565b6702c68af0bb14000081565b60026006541415611aeb576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b600260065534600080611aff3384836131bc565b91509150336001600160a01b03167f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a158383604051610c99929190615549565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614611b865760405162461bcd60e51b81526004016103d6906153b5565b600a54640100000000900460ff16611bb05760405162461bcd60e51b81526004016103d6906151f7565b600560019054906101000a90046001600160a01b03166001600160a01b0316639d4c94426040518163ffffffff1660e01b815260040160206040518083038186803b158015611bfe57600080fd5b505afa158015611c12573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c3691906149de565b6001600160a01b03166342842e0e30837f00000000000000000000000000000000000000000000000000000000000000006040518463ffffffff1660e01b8152600401611c8593929190614fc8565b600060405180830381600087803b158015611c9f57600080fd5b505af1158015611cb3573d6000803e3d6000fd5b50505050611cc16000612262565b806001600160a01b03167fae97956757017853415251f661bfe857898f44ddb9c90b2483065719b84b0c697f0000000000000000000000000000000000000000000000000000000000000000604051611d1a9190614fab565b60405180910390a250565b7f000000000000000000000000000000000000000000000000000000000000000081565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614611d915760405162461bcd60e51b81526004016103d69061528d565b600a54640100000000900460ff1615611dbc5760405162461bcd60e51b81526004016103d69061535e565b611dc581612262565b34611dd1816000613230565b600d849055600e839055611de8338783600061325f565b611df233866133b9565b5050600a805464ff00000000191664010000000017905550505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60095481565b600c5481565b611e4e612172565b6001600160a01b0316611e5f6111e8565b6001600160a01b031614611eba576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b038116611eff5760405162461bcd60e51b81526004018080602001828103825260268152602001806156486026913960400191505060405180910390fd5b6007546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a36007805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0392909216919091179055565b600a5463ffffffff1681565b6000610a7582612489565b6000841380611f8e5750600083135b611f9757600080fd5b6000611fa582840184614b72565b90506000806000611fb984600001516133c3565b925092509250611feb7f00000000000000000000000000000000000000000000000000000000000000008484846133f4565b506000808913611ffb5787611ffd565b885b905061201a8560200151858585858a606001518b60400151613413565b505050505050505050565b6002600654141561207d576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b600260065560008061208d6138ec565b9150915061209b8482613230565b60006120a8858484613906565b5090506121237f00000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000086846120fc8a346130e3565b60008b60405160200161210f9190614fab565b604051602081830303815290604052613995565b336001600160a01b03167f5d85169ff8329e90f3225f9798e0eba54d00c55d3bbfe201a0d1606febb23a8e868360405161215e929190615549565b60405180910390a250506001600655505050565b3390565b6001600160a01b0383166121bb5760405162461bcd60e51b81526004018080602001828103825260248152602001806157a26024913960400191505060405180910390fd5b6001600160a01b0382166122005760405162461bcd60e51b815260040180806020018281038252602281526020018061566e6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b60088190556040517f29600e2e028c8c5c2b112d021938e0d0237d8fafcbb20394c56cf9fa4661ca279061118b908390614fab565b6001600160a01b0383166122dc5760405162461bcd60e51b815260040180806020018281038252602581526020018061577d6025913960400191505060405180910390fd5b6001600160a01b0382166123215760405162461bcd60e51b81526004018080602001828103825260238152602001806156036023913960400191505060405180910390fd5b61232c8383836125e6565b61236981604051806060016040528060268152602001615690602691396001600160a01b03861660009081526020819052604090205491906123f2565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461239890826126b5565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600081848411156124815760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561244657818101518382015260200161242e565b50505050905090810190601f1680156124735780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b600080612494612823565b9350505050610bac6124a4610b25565b6124ae8386613a0c565b90613a45565b6000806124bf6138ec565b91505060006124d086610e80610b25565b905060006124de828461271b565b90506124ec88878388613a65565b6124f68888612727565b979650505050505050565b80471015612556576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604482015290519081900360640190fd5b6040516000906001600160a01b0384169083908381818185875af1925050503d80600081146125a1576040519150601f19603f3d011682016040523d82523d6000602084013e6125a6565b606091505b50509050806125e65760405162461bcd60e51b815260040180806020018281038252603a8152602001806156b6603a913960400191505060405180910390fd5b505050565b60007f0000000000000000000000000000000000000000000000000000000000000000612616613b94565b141561264357507f0000000000000000000000000000000000000000000000000000000000000000610a5a565b6126ae7f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000613b98565b9050610a5a565b600082820183811015610bac576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6000610bac8383613a45565b6000610bac8284613a0c565b6001600160a01b03821661276c5760405162461bcd60e51b815260040180806020018281038252602181526020018061575c6021913960400191505060405180910390fd5b612778826000836125e6565b6127b581604051806060016040528060228152602001615626602291396001600160a01b03851660009081526020819052604090205491906123f2565b6001600160a01b0383166000908152602081905260409020556002546127db9082613bfa565b6002556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b600554604051634632752560e11b8152600091829182918291829161010090046001600160a01b031690638c64ea4a90612881907f000000000000000000000000000000000000000000000000000000000000000090600401614fab565b60806040518083038186803b15801561289957600080fd5b505afa1580156128ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128d19190614c30565b805160208201516040830151606090930151919863ffffffff90911697506bffffffffffffffffffffffff90921695506fffffffffffffffffffffffffffffffff169350915050565b600a5460405163cce79bd560e01b815260009182916001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163cce79bd5916129de917f0000000000000000000000000000000000000000000000000000000000000000917f0000000000000000000000000000000000000000000000000000000000000000917f00000000000000000000000000000000000000000000000000000000000000009163ffffffff90911690600190600401614fec565b60206040518083038186803b1580156129f657600080fd5b505afa158015612a0a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a2e9190614cea565b90506000612a47600e5483613a4590919063ffffffff16565b90506000670de0b6b3a76400008211612a7157612a6c670de0b6b3a7640000836130e3565b612a83565b612a8382670de0b6b3a76400006130e3565b600c541115935050505090565b6000612aa9600b54600d54613c5790919063ffffffff16565b421015905090565b600a5460405163cce79bd560e01b81526000916001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163cce79bd591612b71917f0000000000000000000000000000000000000000000000000000000000000000917f0000000000000000000000000000000000000000000000000000000000000000917f00000000000000000000000000000000000000000000000000000000000000009163ffffffff1690600190600401614fec565b60206040518083038186803b158015612b8957600080fd5b505afa158015612b9d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bc19190614cea565b90508115612c2657612c02670de0b6b3a7640000612bfc612bf5600954670de0b6b3a7640000613c5790919063ffffffff16565b8490613caf565b90613d1b565b831115612c215760405162461bcd60e51b81526004016103d6906152c7565b6125e6565b612c52670de0b6b3a7640000612bfc612bf5600954670de0b6b3a76400006130e390919063ffffffff16565b8310156125e65760405162461bcd60e51b81526004016103d690615230565b806080015115612ca4578060600151821115612c9f5760405162461bcd60e51b81526004016103d69061549a565b612cc8565b8060600151821015612cc85760405162461bcd60e51b81526004016103d69061537b565b612cda81602001518260c00151613d7a565b60007fc8aea8e60353611f3ed5409dad2d3173390bd252431198e7300eda67fefb66b1826000015183602001518460400151856060015186608001518760a001518860c00151604051602001612d379897969594939291906150de565b6040516020818303038152906040528051906020012090506000612d5a82613dee565b90506000612d78828560e00151866101000151876101200151613e3a565b905083602001516001600160a01b0316816001600160a01b031614612daf5760405162461bcd60e51b81526004016103d690615461565b428460a001511015612dd35760405162461bcd60e51b81526004016103d690615186565b8360400151861015612de757604084018690525b6000612e0c670de0b6b3a7640000612bfc888860400151613caf90919063ffffffff16565b9050846080015115612f575760208501516040516323b872dd60e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016916323b872dd91612e6c919030908690600401614fc8565b602060405180830381600087803b158015612e8657600080fd5b505af1158015612e9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ebe9190614a9d565b50604051632e1a7d4d60e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690632e1a7d4d90612f0b908490600401614fab565b600060405180830381600087803b158015612f2557600080fd5b505af1158015612f39573d6000803e3d6000fd5b50505050612f528560200151866040015183600061325f565b613085565b612f6c85602001518660400151836000613a65565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b158015612fc757600080fd5b505af1158015612fdb573d6000803e3d6000fd5b50505050602086015160405163a9059cbb60e01b81527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316925063a9059cbb9161303191859060040161505f565b602060405180830381600087803b15801561304b57600080fd5b505af115801561305f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130839190614a9d565b505b7f68c36f17c620d197a81d3aeff305f83abf3bb29943a38cd6efc299041238652d856020015186600001518760400151886060015189608001518b6040516130d29695949392919061509e565b60405180910390a150505050505050565b80820382811115610a75576040805162461bcd60e51b815260206004820152601560248201527f64732d6d6174682d7375622d756e646572666c6f770000000000000000000000604482015290519081900360640190fd5b60006131908530600060405180608001604052808c8c8f60405160200161316493929190614f58565b60408051601f1981840301815291815290825233602083015260ff8a1690820152606001879052613faf565b9050838111156131b25760405162461bcd60e51b81526004016103d6906151c0565b5050505050505050565b6000806000806131ca6138ec565b915091506131d88682613230565b6000806131e6888585613906565b909250905060006132086131fa8a846130e3565b85613203610b25565b61411c565b90506132168a848b8b61325f565b6132208a826133b9565b9199919850909650505050505050565b60085461323d8284613c57565b111561325b5760405162461bcd60e51b81526004016103d690615213565b5050565b600554604051630728cf2360e31b81526101009091046001600160a01b03169063394679189084906132ba907f0000000000000000000000000000000000000000000000000000000000000000908890600090600401615574565b6020604051808303818588803b1580156132d357600080fd5b505af11580156132e7573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061330c9190614cea565b50806114c45760405163a9059cbb60e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063a9059cbb90613360908790879060040161505f565b602060405180830381600087803b15801561337a57600080fd5b505af115801561338e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133b29190614a9d565b5050505050565b61325b828261416b565b600080806133d1848261425b565b92506133de846014614327565b90506133eb84601761425b565b91509193909250565b600061340a856134058686866143e3565b614439565b95945050505050565b60008160ff16600181111561342457fe5b600181111561342f57fe5b14156136665760008280602001905181019061344b9190614b57565b6040516370a0823160e01b81529091506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690632e1a7d4d9082906370a08231906134a2903090600401614fb4565b60206040518083038186803b1580156134ba57600080fd5b505afa1580156134ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134f29190614cea565b6040518263ffffffff1660e01b815260040161350e9190614fab565b600060405180830381600087803b15801561352857600080fd5b505af115801561353c573d6000803e3d6000fd5b5050505061355088826000015160016131bc565b5050600061355f88888861445c565b60405163a9059cbb60e01b81529091506001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063a9059cbb906135b0908490899060040161505f565b602060405180830381600087803b1580156135ca57600080fd5b505af11580156135de573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136029190614a9d565b50886001600160a01b03167fc355ebece16d7e85e486911f0cde1074bc4bd3fec251c88cdddc7076d3e99adb864760405161363e929190615549565b60405180910390a2471561365f5761365f6001600160a01b038a1647612501565b50506138e3565b60018160ff16600181111561367757fe5b600181111561368257fe5b14156138e35760008280602001905181019061369e9190614b57565b9050600061374e8983600001517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016136f79190614fb4565b60206040518083038186803b15801561370f57600080fd5b505afa158015613723573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137479190614cea565b60016124b4565b9050600061375d89898961445c565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0876040518263ffffffff1660e01b81526004016000604051808303818588803b1580156137ba57600080fd5b505af11580156137ce573d6000803e3d6000fd5b505060405163a9059cbb60e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016935063a9059cbb9250613821915084908a9060040161505f565b602060405180830381600087803b15801561383b57600080fd5b505af115801561384f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138739190614a9d565b50600061388083886130e3565b90508a6001600160a01b03167f6f3269a64126ef2a1959892f3d921e81865181e09a7f72f55d3a49550c53b48d88836040516138bd929190615549565b60405180910390a280156138de576138de6001600160a01b038c1682612501565b505050505b50505050505050565b6000806000806138fa612823565b96509450505050509091565b60008060008061391461449a565b9050600086158015613924575085155b80156139365750613933610b25565b15155b905080156139565760405162461bcd60e51b81526004016103d6906151a3565b61397761396d6139668985613a0c565b8890613c57565b6124ae8a8a613a0c565b925060006139858484613a0c565b9399939850929650505050505050565b60006139ea8530600060405180608001604052808d8c8e6040516020016139be93929190614f58565b60408051601f1981840301815291815290825233602083015260ff8a16908201526060018790526145d1565b9050838110156131b25760405162461bcd60e51b81526004016103d690615132565b6000670de0b6b3a7640000613a36613a248585613caf565b6002670de0b6b3a76400005b04613c57565b81613a3d57fe5b049392505050565b600081613a36613a5d85670de0b6b3a7640000613caf565b600285613a30565b80613b0e576040516323b872dd60e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906323b872dd90613aba90879030908890600401614fc8565b602060405180830381600087803b158015613ad457600080fd5b505af1158015613ae8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b0c9190614a9d565b505b600554604051638632cb0360e01b81526101009091046001600160a01b031690638632cb0390613b66907f00000000000000000000000000000000000000000000000000000000000000009087908790600401615574565b600060405180830381600087803b158015613b8057600080fd5b505af11580156131b2573d6000803e3d6000fd5b4690565b6000838383613ba5613b94565b3060405160200180868152602001858152602001848152602001838152602001826001600160a01b03168152602001955050505050506040516020818303038152906040528051906020012090509392505050565b600082821115613c51576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b80820182811015610a75576040805162461bcd60e51b815260206004820152601460248201527f64732d6d6174682d6164642d6f766572666c6f77000000000000000000000000604482015290519081900360640190fd5b6000811580613cca57505080820282828281613cc757fe5b04145b610a75576040805162461bcd60e51b815260206004820152601460248201527f64732d6d6174682d6d756c2d6f766572666c6f77000000000000000000000000604482015290519081900360640190fd5b6000808211613d71576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b818381613a3d57fe5b6001600160a01b038216600090815260106020908152604080832084845290915290205460ff1615613dbe5760405162461bcd60e51b81526004016103d6906154b7565b6001600160a01b03909116600090815260106020908152604080832093835292905220805460ff19166001179055565b6000613df86125eb565b82604051602001808061190160f01b81525060020183815260200182815260200192505050604051602081830303815290604052805190602001209050919050565b60007f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0821115613e9b5760405162461bcd60e51b81526004018080602001828103825260228152602001806156f06022913960400191505060405180910390fd5b8360ff16601b1480613eb057508360ff16601c145b613eeb5760405162461bcd60e51b81526004018080602001828103825260228152602001806157126022913960400191505060405180910390fd5b600060018686868660405160008152602001604052604051808581526020018460ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa158015613f47573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661340a576040805162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604482015290519081900360640190fd5b600080600080613fc285600001516133c3565b919450925090506001600160a01b0380841690831610600080613fe685878661445c565b6001600160a01b031663128acb088b85613fff8f614710565b6000036001600160a01b038e1615614017578d61403d565b876140365773fffd8963efd1fc6a506488495d951d5263988d2561403d565b6401000276a45b8d60405160200161404e91906154f0565b6040516020818303038152906040526040518663ffffffff1660e01b815260040161407d959493929190615025565b6040805180830381600087803b15801561409657600080fd5b505af11580156140aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140ce9190614ab9565b91509150600080846140e45782846000036140ea565b83836000035b915091508a6001600160a01b03166000141561410c578c811461410c57600080fd5b509b9a5050505050505050505050565b60008061413361412c8587613c57565b8690613a45565b905082156141625761415a614150670de0b6b3a7640000836130e3565b6124ae8584613a0c565b915050610bac565b50929392505050565b6001600160a01b0382166141c6576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b6141d2600083836125e6565b6002546141df90826126b5565b6002556001600160a01b03821660009081526020819052604090205461420590826126b5565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6000818260140110156142b5576040805162461bcd60e51b815260206004820152601260248201527f746f416464726573735f6f766572666c6f770000000000000000000000000000604482015290519081900360640190fd5b816014018351101561430e576040805162461bcd60e51b815260206004820152601560248201527f746f416464726573735f6f75744f66426f756e64730000000000000000000000604482015290519081900360640190fd5b5001602001516c01000000000000000000000000900490565b600081826003011015614381576040805162461bcd60e51b815260206004820152601160248201527f746f55696e7432345f6f766572666c6f77000000000000000000000000000000604482015290519081900360640190fd5b81600301835110156143da576040805162461bcd60e51b815260206004820152601460248201527f746f55696e7432345f6f75744f66426f756e6473000000000000000000000000604482015290519081900360640190fd5b50016003015190565b6143eb6148c8565b826001600160a01b0316846001600160a01b03161115614409579192915b50604080516060810182526001600160a01b03948516815292909316602083015262ffffff169181019190915290565b60006144458383614726565b9050336001600160a01b03821614610a7557600080fd5b60006144927f000000000000000000000000000000000000000000000000000000000000000061448d8686866143e3565b614726565b949350505050565b60008061452e7f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006101a46000614822565b90506000600560019054906101000a90046001600160a01b03166001600160a01b031663978bbdb96040518163ffffffff1660e01b815260040160206040518083038186803b15801561458057600080fd5b505afa158015614594573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145b89190614cea565b90506145ca612710612bfc8484613caf565b9250505090565b6000806000806145e485600001516133c3565b919450925090506001600160a01b038083169084161060008061460886868661445c565b6001600160a01b031663128acb088b856146218f614710565b6001600160a01b038e1615614636578d61465c565b876146555773fffd8963efd1fc6a506488495d951d5263988d2561465c565b6401000276a45b8d60405160200161466d91906154f0565b6040516020818303038152906040526040518663ffffffff1660e01b815260040161469c959493929190615025565b6040805180830381600087803b1580156146b557600080fd5b505af11580156146c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146ed9190614ab9565b91509150826146fc57816146fe565b805b6000039b9a5050505050505050505050565b6000600160ff1b821061472257600080fd5b5090565b600081602001516001600160a01b031682600001516001600160a01b03161061474e57600080fd5b50805160208083015160409384015184516001600160a01b0394851681850152939091168385015262ffffff166060808401919091528351808403820181526080840185528051908301207fff0000000000000000000000000000000000000000000000000000000000000060a085015294901b6bffffffffffffffffffffffff191660a183015260b58201939093527fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b5460d5808301919091528251808303909101815260f5909101909152805191012090565b6040805163cce79bd560e01b81526001600160a01b0387811660048301528681166024830152858116604483015263ffffffff851660648301528315156084830152915160009289169163cce79bd59160a4808301926020929190829003018186803b15801561489157600080fd5b505afa1580156148a5573d6000803e3d6000fd5b505050506040513d60208110156148bb57600080fd5b5051979650505050505050565b604080516060810182526000808252602082018190529181019190915290565b8035610ff2816155cd565b8035610ff2816155e2565b600082601f83011261490e578081fd5b813567ffffffffffffffff81111561492257fe5b614935601f8201601f19166020016155a9565b818152846020838601011115614949578283fd5b816020850160208301379081016020019190915292915050565b600060208284031215614974578081fd5b6040516020810181811067ffffffffffffffff8211171561499157fe5b6040529151825250919050565b803562ffffff81168114610ff257600080fd5b803560ff81168114610ff257600080fd5b6000602082840312156149d3578081fd5b8135610bac816155cd565b6000602082840312156149ef578081fd5b8151610bac816155cd565b60008060408385031215614a0c578081fd5b8235614a17816155cd565b91506020830135614a27816155cd565b809150509250929050565b600080600060608486031215614a46578081fd5b8335614a51816155cd565b92506020840135614a61816155cd565b929592945050506040919091013590565b60008060408385031215614a84578182fd5b8235614a8f816155cd565b946020939093013593505050565b600060208284031215614aae578081fd5b8151610bac816155e2565b60008060408385031215614acb578182fd5b505080516020909101519092909150565b60008060008060608587031215614af1578182fd5b8435935060208501359250604085013567ffffffffffffffff80821115614b16578384fd5b818701915087601f830112614b29578384fd5b813581811115614b37578485fd5b886020828501011115614b48578485fd5b95989497505060200194505050565b600060208284031215614b68578081fd5b610bac8383614963565b600060208284031215614b83578081fd5b813567ffffffffffffffff80821115614b9a578283fd5b9083019060808286031215614bad578283fd5b604051608081018181108382111715614bc257fe5b604052823582811115614bd3578485fd5b614bdf878286016148fe565b825250614bee602084016148e8565b6020820152614bff604084016149b1565b6040820152606083013582811115614c15578485fd5b614c21878286016148fe565b60608301525095945050505050565b600060808284031215614c41578081fd5b6040516080810181811067ffffffffffffffff82111715614c5e57fe5b6040528251614c6c816155cd565b81526020830151614c7c816155f0565b602082015260408301516bffffffffffffffffffffffff81168114614c9f578283fd5b604082015260608301516fffffffffffffffffffffffffffffffff81168114614cc6578283fd5b60608201529392505050565b600060208284031215614ce3578081fd5b5035919050565b600060208284031215614cfb578081fd5b5051919050565b60008060408385031215614d14578182fd5b82359150614d246020840161499e565b90509250929050565b60008060008060808587031215614d42578182fd5b843593506020808601359350604080870135614d5d816155e2565b9350606087013567ffffffffffffffff80821115614d79578485fd5b818901915089601f830112614d8c578485fd5b813581811115614d9857fe5b614da585868302016155a9565b8181528581019250838601610140808402860188018e1015614dc5578889fd5b8895505b83861015614e6f5780828f031215614ddf578889fd5b614de8816155a9565b82358152614df78984016148e8565b89820152878301358882015260608301356060820152614e19608084016148f3565b608082015260a0838101359082015260c0808401359082015260e0614e3f8185016149b1565b90820152610100838101359082015261012080840135908201528552600195909501949387019390810190614dc9565b505080965050505050505092959194509250565b600080600060608486031215614e97578081fd5b8335925060208401359150614eae6040850161499e565b90509250925092565b600080600080600060a08688031215614ece578283fd5b505083359560208501359550604085013594606081013594506080013592509050565b600060208284031215614f02578081fd5b8135610bac816155f0565b60008151808452815b81811015614f3257602081850181015186830182015201614f16565b81811115614f435782602083870101525b50601f01601f19169290920160200192915050565b606093841b6bffffffffffffffffffffffff19908116825260e89390931b7fffffff0000000000000000000000000000000000000000000000000000000000166014820152921b166017820152602b0190565b90815260200190565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b039586168152938516602085015291909316604083015263ffffffff9092166060820152901515608082015260a00190565b60006001600160a01b038088168352861515602084015285604084015280851660608401525060a060808301526124f660a0830184614f0d565b6001600160a01b03929092168252602082015260400190565b6001600160a01b0394909416845260208401929092526040830152606082015260800190565b6001600160a01b039690961686526020860194909452604085019290925260608401521515608083015260a082015260c00190565b901515815260200190565b97885260208801969096526001600160a01b0394909416604087015260608601929092526080850152151560a084015260c083015260e08201526101000190565b600060208252610bac6020830184614f0d565b60208082526018908201527f616d6f756e74206f7574206c657373207468616e206d696e0000000000000000604082015260600190565b60208082526003908201526210cc4d60ea1b604082015260600190565b60208082526003908201526204332360ec1b604082015260600190565b60208082526003908201526221991b60e91b604082015260600190565b6020808252601a908201527f616d6f756e7420696e2067726561746572207468616e206d6178000000000000604082015260600190565b602080825260029082015261219960f11b604082015260600190565b60208082526003908201526221989b60e91b604082015260600190565b60208082526027908201527f507269636520746f6f206c6f772072656c617469766520746f20556e6973776160408201527f7020747761702e00000000000000000000000000000000000000000000000000606082015260800190565b60208082526003908201526204331360ec1b604082015260600190565b60208082526003908201526243313360e81b604082015260600190565b60208082526028908201527f507269636520746f6f20686967682072656c617469766520746f20556e69737760408201527f617020747761702e000000000000000000000000000000000000000000000000606082015260800190565b60208082526003908201526243323360e81b604082015260600190565b60208082526003908201526243323560e81b604082015260600190565b60208082526003908201526243313160e81b604082015260600190565b60208082526003908201526208662760eb1b604082015260600190565b60208082526003908201526243323160e81b604082015260600190565b602080825260029082015261433160f01b604082015260600190565b60208082526003908201526243313560e81b604082015260600190565b60208082526003908201526221989960e91b604082015260600190565b602080825260029082015261433760f01b604082015260600190565b60208082526003908201526210cc8d60ea1b604082015260600190565b60208082526003908201526221991960e91b604082015260600190565b60208082526003908201526243313960e81b604082015260600190565b602080825260029082015261433960f01b604082015260600190565b60208082526003908201526243313760e81b604082015260600190565b60208082526003908201526243323760e81b604082015260600190565b602080825260029082015261086760f31b604082015260600190565b60006020825282516080602084015261550c60a0840182614f0d565b90506001600160a01b03602085015116604084015260ff60408501511660608401526060840151601f1984830301608085015261340a8282614f0d565b918252602082015260400190565b938452602084019290925215156040830152606082015260800190565b9283526020830191909152604082015260600190565b63ffffffff91909116815260200190565b60ff91909116815260200190565b60405181810167ffffffffffffffff811182821017156155c557fe5b604052919050565b6001600160a01b0381168114610b2257600080fd5b8015158114610b2257600080fd5b63ffffffff81168114610b2257600080fdfe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e63654f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365416464726573733a20756e61626c6520746f2073656e642076616c75652c20726563697069656e74206d6179206861766520726576657274656445434453413a20696e76616c6964207369676e6174757265202773272076616c756545434453413a20696e76616c6964207369676e6174757265202776272076616c756545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa26469706673582212205588e36b593aca521cd7221641031ca4fe125d2300af7c70ba2abc8ce18bf28564736f6c6343000706003300000000000000000000000064187ae08781b09368e6253f9e94951243a493d500000000000000000000000065d66c76447ccb45daf1e8044e918fa786a483a1000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f98400000000000000000000000082c427adfdf2d245ec51d8046b41c4ee87f0d29c00000000000000000000000067c083ae303741372f0f321bf9cad567cfefe2dc000000000000000000000000a1cab67a4383312718a5799eaa127906e9d4b19e0000000000000000000000000000000000000000000000000000000000000e1000000000000000000000000000000000000000000000000002c68af0bb140000
Deployed Bytecode
0x60806040526004361061036f5760003560e01c80637f07b130116101c6578063cae74029116100f7578063e9c3cb4f11610095578063f5d278e41161006f578063f5d278e41461095e578063f73e19c314610973578063fa461e3314610993578063fc5b73ff146109b3576103e1565b8063e9c3cb4f14610914578063f101d92f14610929578063f2fde38b1461093e576103e1565b8063d2dd9f79116100d1578063d2dd9f79146108ac578063d33219b4146108cc578063dcbab608146108e1578063dd62ed3e146108f4576103e1565b8063cae740291461087a578063cfa70b181461088f578063d0e30db0146108a4576103e1565b8063a457c2d711610164578063b52b7ff01161013e578063b52b7ff014610810578063bdd438b814610830578063c245168914610850578063c45a015514610865576103e1565b8063a457c2d7146107b0578063a9059cbb146107d0578063b24f719b146107f0576103e1565b80638f8b8dbc116101a05780638f8b8dbc1461074657806395d89b41146107665780639ff69a511461077b578063a319b29f1461079b576103e1565b80637f07b1301461070757806388626eb81461071c5780638da5cb5b14610731576103e1565b80633d65fdac116102a057806366a91b761161023e57806370a082311161021857806370a082311461069d578063715018a6146106bd5780637bcdc16e146106d25780637dc0d1d0146106f2576103e1565b806366a91b761461065e57806367b8c345146106735780636c1040a914610688576103e1565b80634d76e6fc1161027a5780634d76e6fc146105ef578063502e1a1614610604578063533092ef1461062457806363bbc4b614610649576103e1565b80633d65fdac146105a55780633dcb0c5d146105c55780633fc8cef3146105da576103e1565b8063313ce5671161030d578063392e53cd116102e7578063392e53cd1461052e5780633950935114610543578063395ebb69146105635780633d3a62ee14610585576103e1565b8063313ce567146104e257806333194c0a146105045780633644e51514610519576103e1565b806318160ddd1161034957806318160ddd1461045e57806323b872dd14610480578063281e78d1146104a05780632e1a7d4d146104c2576103e1565b806306fdde03146103e6578063095ea7b3146104115780630ca514cd1461043e576103e1565b366103e157336001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc21614806103ba575060055461010090046001600160a01b031633145b6103df5760405162461bcd60e51b81526004016103d69061547e565b60405180910390fd5b005b600080fd5b3480156103f257600080fd5b506103fb6109c6565b604051610408919061511f565b60405180910390f35b34801561041d57600080fd5b5061043161042c366004614a72565b610a5d565b60405161040891906150d3565b34801561044a57600080fd5b506103df610459366004614cd2565b610a7b565b34801561046a57600080fd5b50610473610b25565b6040516104089190614fab565b34801561048c57600080fd5b5061043161049b366004614a32565b610b2b565b3480156104ac57600080fd5b506104b5610bb3565b6040516104089190614fb4565b3480156104ce57600080fd5b506103df6104dd366004614cd2565b610bd7565b3480156104ee57600080fd5b506104f7610cab565b604051610408919061559b565b34801561051057600080fd5b50610473610cb4565b34801561052557600080fd5b50610473610cd8565b34801561053a57600080fd5b50610431610ce7565b34801561054f57600080fd5b5061043161055e366004614a72565b610cf8565b34801561056f57600080fd5b50610578610d46565b604051610408919061558a565b34801561059157600080fd5b506103df6105a0366004614cd2565b610d4c565b3480156105b157600080fd5b506103df6105c0366004614cd2565b610ee4565b3480156105d157600080fd5b506104b5610f0a565b3480156105e657600080fd5b506104b5610f1e565b3480156105fb57600080fd5b506104b5610f42565b34801561061057600080fd5b5061043161061f366004614a72565b610f66565b34801561063057600080fd5b50610639610f86565b6040516104089493929190615078565b34801561065557600080fd5b50610473610fa2565b34801561066a57600080fd5b50610473610fa8565b34801561067f57600080fd5b50610473610fae565b34801561069457600080fd5b50610473610fb4565b3480156106a957600080fd5b506104736106b83660046149c2565b610fd8565b3480156106c957600080fd5b506103df610ff7565b3480156106de57600080fd5b506103df6106ed366004614cd2565b6110c2565b3480156106fe57600080fd5b506104b5611196565b34801561071357600080fd5b506104b56111ba565b34801561072857600080fd5b506104316111de565b34801561073d57600080fd5b506104b56111e8565b34801561075257600080fd5b506103df610761366004614ef1565b6111f7565b34801561077257600080fd5b506103fb6112d7565b34801561078757600080fd5b506103df610796366004614cd2565b611338565b3480156107a757600080fd5b506103df611409565b3480156107bc57600080fd5b506104316107cb366004614a72565b6114ca565b3480156107dc57600080fd5b506104316107eb366004614a72565b611532565b3480156107fc57600080fd5b506103df61080b366004614d2d565b611546565b34801561081c57600080fd5b506103df61082b366004614e83565b61184f565b34801561083c57600080fd5b506103df61084b366004614cd2565b611976565b34801561085c57600080fd5b50610431611a53565b34801561087157600080fd5b506104b5611a5d565b34801561088657600080fd5b50610473611a81565b34801561089b57600080fd5b50610473611a87565b6103df611a93565b3480156108b857600080fd5b506103df6108c73660046149c2565b611b3e565b3480156108d857600080fd5b506104b5611d25565b6103df6108ef366004614eb7565b611d49565b34801561090057600080fd5b5061047361090f3660046149fa565b611e0f565b34801561092057600080fd5b50610473611e3a565b34801561093557600080fd5b50610473611e40565b34801561094a57600080fd5b506103df6109593660046149c2565b611e46565b34801561096a57600080fd5b50610578611f68565b34801561097f57600080fd5b5061047361098e366004614cd2565b611f74565b34801561099f57600080fd5b506103df6109ae366004614adc565b611f7f565b6103df6109c1366004614d02565b612025565b60038054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610a525780601f10610a2757610100808354040283529160200191610a52565b820191906000526020600020905b815481529060010190602001808311610a3557829003601f168201915b505050505090505b90565b6000610a71610a6a612172565b8484612176565b5060015b92915050565b610a83612172565b6001600160a01b0316610a946111e8565b6001600160a01b031614610aef576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600a54640100000000900460ff16610b195760405162461bcd60e51b81526004016103d6906151f7565b610b2281612262565b50565b60025490565b6000610b38848484612297565b610ba884610b44612172565b610ba385604051806060016040528060288152602001615734602891396001600160a01b038a16600090815260016020526040812090610b82612172565b6001600160a01b0316815260208101919091526040016000205491906123f2565b612176565b5060015b9392505050565b7f000000000000000000000000a1cab67a4383312718a5799eaa127906e9d4b19e81565b60026006541415610c2f576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b60026006556000610c3f82612489565b90506000610c5033848460006124b4565b9050610c5c3382612501565b336001600160a01b03167f02f25270a4d87bea75db541cdfe559334a275b4a233520ed6c0a2429667cca94848484604051610c9993929190615574565b60405180910390a25050600160065550565b60055460ff1690565b7f000000000000000000000000000000000000000000000000000000000000011e81565b6000610ce26125eb565b905090565b600a54640100000000900460ff1681565b6000610a71610d05612172565b84610ba38560016000610d16612172565b6001600160a01b03908116825260208083019390935260409182016000908120918c1681529252902054906126b5565b6101a481565b60026006541415610da4576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b6002600681905550600560019054906101000a90046001600160a01b03166001600160a01b031663ff9475256040518163ffffffff1660e01b8152600401602060405180830381600087803b158015610dfc57600080fd5b505af1158015610e10573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e349190614a9d565b610e505760405162461bcd60e51b81526004016103d6906153ee565b600f5460ff16610e725760405162461bcd60e51b81526004016103d6906152aa565b6000610e8582610e80610b25565b61270f565b90506000610e93824761271b565b9050610e9f3384612727565b610ea93382612501565b336001600160a01b03167fe9ab9870b9093d99f8e981919f65ad09b7ae90ff80f1031639af9e0357eb9ed68483604051610c99929190615549565b33600090815260106020908152604080832093835292905220805460ff19166001179055565b60055461010090046001600160a01b031681565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b7f00000000000000000000000082c427adfdf2d245ec51d8046b41c4ee87f0d29c81565b601060209081526000928352604080842090915290825290205460ff1681565b600080600080610f94612823565b935093509350935090919293565b600e5481565b600b5481565b600d5481565b7f000000000000000000000000000000000000000000000000000000000000011e90565b6001600160a01b0381166000908152602081905260409020545b919050565b610fff612172565b6001600160a01b03166110106111e8565b6001600160a01b03161461106b576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6007546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a36007805473ffffffffffffffffffffffffffffffffffffffff19169055565b6110ca612172565b6001600160a01b03166110db6111e8565b6001600160a01b031614611136576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600081116111565760405162461bcd60e51b81526004016103d69061540b565b600b8190556040517f28e0e4ee0b14d4b056ce88e1bcd890ccd32b22e213723c8765901381b5eae7059061118b908390614fab565b60405180910390a150565b7f00000000000000000000000065d66c76447ccb45daf1e8044e918fa786a483a181565b7f000000000000000000000000f1b99e3e573a1a9c5e6b2ce818b617f0e664e86b81565b6000610ce261291a565b6007546001600160a01b031690565b6111ff612172565b6001600160a01b03166112106111e8565b6001600160a01b03161461126b576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60b48163ffffffff1610156112925760405162461bcd60e51b81526004016103d690615169565b600a805463ffffffff191663ffffffff83161790556040517f1cd9c7f99a5530a38c8f2b387dcc78e8a76cb5b203e0c4316a66777d993dee359061118b90839061558a565b60048054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610a525780601f10610a2757610100808354040283529160200191610a52565b611340612172565b6001600160a01b03166113516111e8565b6001600160a01b0316146113ac576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6702c68af0bb1400008111156113d45760405162461bcd60e51b81526004016103d6906153d1565b60098190556040517f829c71710efa317bbdb8e5c4ca2b6d2551b7c2d7d37ea199975807eb3f5c0e7c9061118b908390614fab565b600a54640100000000900460ff166114335760405162461bcd60e51b81526004016103d6906151f7565b600f8054600160ff19909116179055600554604051634bf7d4a160e11b81526101009091046001600160a01b0316906397efa94290611496907f000000000000000000000000000000000000000000000000000000000000011e90600401614fab565b600060405180830381600087803b1580156114b057600080fd5b505af11580156114c4573d6000803e3d6000fd5b50505050565b6000610a716114d7612172565b84610ba3856040518060600160405280602581526020016157c66025913960016000611501612172565b6001600160a01b03908116825260208083019390935260409182016000908120918d168152925290205491906123f2565b6000610a7161153f612172565b8484612297565b61154e612172565b6001600160a01b031661155f6111e8565b6001600160a01b0316146115ba576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600a54640100000000900460ff166115e45760405162461bcd60e51b81526004016103d6906151f7565b600083116116045760405162461bcd60e51b81526004016103d690615398565b61160c612a90565b8061161a575061161a61291a565b6116365760405162461bcd60e51b81526004016103d690615444565b6116408383612ab1565b42600d55600e839055805184906000908390829061165a57fe5b602002602001015160600151905060008360008151811061167757fe5b602002602001015160600151905060008460008151811061169457fe5b602002602001015160800151905080151586151514156116c65760405162461bcd60e51b81526004016103d690615324565b60005b85518110156117ef578581815181106116de57fe5b60200260200101516060015192508115158682815181106116fb57fe5b6020026020010151608001511515146117265760405162461bcd60e51b81526004016103d690615427565b8615611751578383101561174c5760405162461bcd60e51b81526004016103d690615341565b611771565b838311156117715760405162461bcd60e51b81526004016103d690615341565b829350611792858988848151811061178557fe5b6020026020010151612c71565b85818151811061179e57fe5b6020026020010151604001518511156117e2576117db8682815181106117c057fe5b602002602001015160400151866130e390919063ffffffff16565b94506117e7565b6117ef565b6001016116c9565b507fbbc3ba742efe346cfdf333000069964e0ee3087c68da267dac977d299f2366fb8560008151811061181e57fe5b60200260200101516000015189888a60405161183d9493929190615557565b60405180910390a15050505050505050565b600260065414156118a7576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b600260065560006118b784612489565b90506119287f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc27f000000000000000000000000f1b99e3e573a1a9c5e6b2ce818b617f0e664e86b84848760018a6040516020016119149190614fab565b60405160208183030381529060405261313b565b336001600160a01b03167fa13b272c1cf13ba724064d3d4809d9f557aab8da2bb582cba031a2f57e728e9d8583604051611963929190615549565b60405180910390a2505060016006555050565b61197e612172565b6001600160a01b031661198f6111e8565b6001600160a01b0316146119ea576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600081118015611a025750670de0b6b3a76400008111155b611a1e5760405162461bcd60e51b81526004016103d6906154d4565b600c8190556040517f789e4b8ad1c375952cea7f07c9b3b6619a84b406432b948246cecb8ced96b9fa9061118b908390614fab565b6000610ce2612a90565b7f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f98481565b60085481565b6702c68af0bb14000081565b60026006541415611aeb576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b600260065534600080611aff3384836131bc565b91509150336001600160a01b03167f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a158383604051610c99929190615549565b336001600160a01b037f00000000000000000000000067c083ae303741372f0f321bf9cad567cfefe2dc1614611b865760405162461bcd60e51b81526004016103d6906153b5565b600a54640100000000900460ff16611bb05760405162461bcd60e51b81526004016103d6906151f7565b600560019054906101000a90046001600160a01b03166001600160a01b0316639d4c94426040518163ffffffff1660e01b815260040160206040518083038186803b158015611bfe57600080fd5b505afa158015611c12573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c3691906149de565b6001600160a01b03166342842e0e30837f000000000000000000000000000000000000000000000000000000000000011e6040518463ffffffff1660e01b8152600401611c8593929190614fc8565b600060405180830381600087803b158015611c9f57600080fd5b505af1158015611cb3573d6000803e3d6000fd5b50505050611cc16000612262565b806001600160a01b03167fae97956757017853415251f661bfe857898f44ddb9c90b2483065719b84b0c697f000000000000000000000000000000000000000000000000000000000000011e604051611d1a9190614fab565b60405180910390a250565b7f00000000000000000000000067c083ae303741372f0f321bf9cad567cfefe2dc81565b336001600160a01b037f000000000000000000000000a1cab67a4383312718a5799eaa127906e9d4b19e1614611d915760405162461bcd60e51b81526004016103d69061528d565b600a54640100000000900460ff1615611dbc5760405162461bcd60e51b81526004016103d69061535e565b611dc581612262565b34611dd1816000613230565b600d849055600e839055611de8338783600061325f565b611df233866133b9565b5050600a805464ff00000000191664010000000017905550505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60095481565b600c5481565b611e4e612172565b6001600160a01b0316611e5f6111e8565b6001600160a01b031614611eba576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b038116611eff5760405162461bcd60e51b81526004018080602001828103825260268152602001806156486026913960400191505060405180910390fd5b6007546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a36007805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0392909216919091179055565b600a5463ffffffff1681565b6000610a7582612489565b6000841380611f8e5750600083135b611f9757600080fd5b6000611fa582840184614b72565b90506000806000611fb984600001516133c3565b925092509250611feb7f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f9848484846133f4565b506000808913611ffb5787611ffd565b885b905061201a8560200151858585858a606001518b60400151613413565b505050505050505050565b6002600654141561207d576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b600260065560008061208d6138ec565b9150915061209b8482613230565b60006120a8858484613906565b5090506121237f000000000000000000000000f1b99e3e573a1a9c5e6b2ce818b617f0e664e86b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc286846120fc8a346130e3565b60008b60405160200161210f9190614fab565b604051602081830303815290604052613995565b336001600160a01b03167f5d85169ff8329e90f3225f9798e0eba54d00c55d3bbfe201a0d1606febb23a8e868360405161215e929190615549565b60405180910390a250506001600655505050565b3390565b6001600160a01b0383166121bb5760405162461bcd60e51b81526004018080602001828103825260248152602001806157a26024913960400191505060405180910390fd5b6001600160a01b0382166122005760405162461bcd60e51b815260040180806020018281038252602281526020018061566e6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b60088190556040517f29600e2e028c8c5c2b112d021938e0d0237d8fafcbb20394c56cf9fa4661ca279061118b908390614fab565b6001600160a01b0383166122dc5760405162461bcd60e51b815260040180806020018281038252602581526020018061577d6025913960400191505060405180910390fd5b6001600160a01b0382166123215760405162461bcd60e51b81526004018080602001828103825260238152602001806156036023913960400191505060405180910390fd5b61232c8383836125e6565b61236981604051806060016040528060268152602001615690602691396001600160a01b03861660009081526020819052604090205491906123f2565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461239890826126b5565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600081848411156124815760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561244657818101518382015260200161242e565b50505050905090810190601f1680156124735780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b600080612494612823565b9350505050610bac6124a4610b25565b6124ae8386613a0c565b90613a45565b6000806124bf6138ec565b91505060006124d086610e80610b25565b905060006124de828461271b565b90506124ec88878388613a65565b6124f68888612727565b979650505050505050565b80471015612556576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604482015290519081900360640190fd5b6040516000906001600160a01b0384169083908381818185875af1925050503d80600081146125a1576040519150601f19603f3d011682016040523d82523d6000602084013e6125a6565b606091505b50509050806125e65760405162461bcd60e51b815260040180806020018281038252603a8152602001806156b6603a913960400191505060405180910390fd5b505050565b60007f0000000000000000000000000000000000000000000000000000000000000001612616613b94565b141561264357507fff40743a0440aa739a394eca66c0780128b20b3a645f0ed4fbf890877a2020c9610a5a565b6126ae7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f738468bb255b753fdddfb8b2099bcac9a3102fae0e921c4c5fd2a21a7f1ad3d07fad7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a5613b98565b9050610a5a565b600082820183811015610bac576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6000610bac8383613a45565b6000610bac8284613a0c565b6001600160a01b03821661276c5760405162461bcd60e51b815260040180806020018281038252602181526020018061575c6021913960400191505060405180910390fd5b612778826000836125e6565b6127b581604051806060016040528060228152602001615626602291396001600160a01b03851660009081526020819052604090205491906123f2565b6001600160a01b0383166000908152602081905260409020556002546127db9082613bfa565b6002556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b600554604051634632752560e11b8152600091829182918291829161010090046001600160a01b031690638c64ea4a90612881907f000000000000000000000000000000000000000000000000000000000000011e90600401614fab565b60806040518083038186803b15801561289957600080fd5b505afa1580156128ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128d19190614c30565b805160208201516040830151606090930151919863ffffffff90911697506bffffffffffffffffffffffff90921695506fffffffffffffffffffffffffffffffff169350915050565b600a5460405163cce79bd560e01b815260009182916001600160a01b037f00000000000000000000000065d66c76447ccb45daf1e8044e918fa786a483a1169163cce79bd5916129de917f00000000000000000000000082c427adfdf2d245ec51d8046b41c4ee87f0d29c917f000000000000000000000000f1b99e3e573a1a9c5e6b2ce818b617f0e664e86b917f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc29163ffffffff90911690600190600401614fec565b60206040518083038186803b1580156129f657600080fd5b505afa158015612a0a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a2e9190614cea565b90506000612a47600e5483613a4590919063ffffffff16565b90506000670de0b6b3a76400008211612a7157612a6c670de0b6b3a7640000836130e3565b612a83565b612a8382670de0b6b3a76400006130e3565b600c541115935050505090565b6000612aa9600b54600d54613c5790919063ffffffff16565b421015905090565b600a5460405163cce79bd560e01b81526000916001600160a01b037f00000000000000000000000065d66c76447ccb45daf1e8044e918fa786a483a1169163cce79bd591612b71917f00000000000000000000000082c427adfdf2d245ec51d8046b41c4ee87f0d29c917f000000000000000000000000f1b99e3e573a1a9c5e6b2ce818b617f0e664e86b917f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc29163ffffffff1690600190600401614fec565b60206040518083038186803b158015612b8957600080fd5b505afa158015612b9d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bc19190614cea565b90508115612c2657612c02670de0b6b3a7640000612bfc612bf5600954670de0b6b3a7640000613c5790919063ffffffff16565b8490613caf565b90613d1b565b831115612c215760405162461bcd60e51b81526004016103d6906152c7565b6125e6565b612c52670de0b6b3a7640000612bfc612bf5600954670de0b6b3a76400006130e390919063ffffffff16565b8310156125e65760405162461bcd60e51b81526004016103d690615230565b806080015115612ca4578060600151821115612c9f5760405162461bcd60e51b81526004016103d69061549a565b612cc8565b8060600151821015612cc85760405162461bcd60e51b81526004016103d69061537b565b612cda81602001518260c00151613d7a565b60007fc8aea8e60353611f3ed5409dad2d3173390bd252431198e7300eda67fefb66b1826000015183602001518460400151856060015186608001518760a001518860c00151604051602001612d379897969594939291906150de565b6040516020818303038152906040528051906020012090506000612d5a82613dee565b90506000612d78828560e00151866101000151876101200151613e3a565b905083602001516001600160a01b0316816001600160a01b031614612daf5760405162461bcd60e51b81526004016103d690615461565b428460a001511015612dd35760405162461bcd60e51b81526004016103d690615186565b8360400151861015612de757604084018690525b6000612e0c670de0b6b3a7640000612bfc888860400151613caf90919063ffffffff16565b9050846080015115612f575760208501516040516323b872dd60e01b81526001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216916323b872dd91612e6c919030908690600401614fc8565b602060405180830381600087803b158015612e8657600080fd5b505af1158015612e9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ebe9190614a9d565b50604051632e1a7d4d60e01b81526001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc21690632e1a7d4d90612f0b908490600401614fab565b600060405180830381600087803b158015612f2557600080fd5b505af1158015612f39573d6000803e3d6000fd5b50505050612f528560200151866040015183600061325f565b613085565b612f6c85602001518660400151836000613a65565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b158015612fc757600080fd5b505af1158015612fdb573d6000803e3d6000fd5b50505050602086015160405163a9059cbb60e01b81527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316925063a9059cbb9161303191859060040161505f565b602060405180830381600087803b15801561304b57600080fd5b505af115801561305f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130839190614a9d565b505b7f68c36f17c620d197a81d3aeff305f83abf3bb29943a38cd6efc299041238652d856020015186600001518760400151886060015189608001518b6040516130d29695949392919061509e565b60405180910390a150505050505050565b80820382811115610a75576040805162461bcd60e51b815260206004820152601560248201527f64732d6d6174682d7375622d756e646572666c6f770000000000000000000000604482015290519081900360640190fd5b60006131908530600060405180608001604052808c8c8f60405160200161316493929190614f58565b60408051601f1981840301815291815290825233602083015260ff8a1690820152606001879052613faf565b9050838111156131b25760405162461bcd60e51b81526004016103d6906151c0565b5050505050505050565b6000806000806131ca6138ec565b915091506131d88682613230565b6000806131e6888585613906565b909250905060006132086131fa8a846130e3565b85613203610b25565b61411c565b90506132168a848b8b61325f565b6132208a826133b9565b9199919850909650505050505050565b60085461323d8284613c57565b111561325b5760405162461bcd60e51b81526004016103d690615213565b5050565b600554604051630728cf2360e31b81526101009091046001600160a01b03169063394679189084906132ba907f000000000000000000000000000000000000000000000000000000000000011e908890600090600401615574565b6020604051808303818588803b1580156132d357600080fd5b505af11580156132e7573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061330c9190614cea565b50806114c45760405163a9059cbb60e01b81526001600160a01b037f000000000000000000000000f1b99e3e573a1a9c5e6b2ce818b617f0e664e86b169063a9059cbb90613360908790879060040161505f565b602060405180830381600087803b15801561337a57600080fd5b505af115801561338e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133b29190614a9d565b5050505050565b61325b828261416b565b600080806133d1848261425b565b92506133de846014614327565b90506133eb84601761425b565b91509193909250565b600061340a856134058686866143e3565b614439565b95945050505050565b60008160ff16600181111561342457fe5b600181111561342f57fe5b14156136665760008280602001905181019061344b9190614b57565b6040516370a0823160e01b81529091506001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc21690632e1a7d4d9082906370a08231906134a2903090600401614fb4565b60206040518083038186803b1580156134ba57600080fd5b505afa1580156134ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134f29190614cea565b6040518263ffffffff1660e01b815260040161350e9190614fab565b600060405180830381600087803b15801561352857600080fd5b505af115801561353c573d6000803e3d6000fd5b5050505061355088826000015160016131bc565b5050600061355f88888861445c565b60405163a9059cbb60e01b81529091506001600160a01b037f000000000000000000000000f1b99e3e573a1a9c5e6b2ce818b617f0e664e86b169063a9059cbb906135b0908490899060040161505f565b602060405180830381600087803b1580156135ca57600080fd5b505af11580156135de573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136029190614a9d565b50886001600160a01b03167fc355ebece16d7e85e486911f0cde1074bc4bd3fec251c88cdddc7076d3e99adb864760405161363e929190615549565b60405180910390a2471561365f5761365f6001600160a01b038a1647612501565b50506138e3565b60018160ff16600181111561367757fe5b600181111561368257fe5b14156138e35760008280602001905181019061369e9190614b57565b9050600061374e8983600001517f000000000000000000000000f1b99e3e573a1a9c5e6b2ce818b617f0e664e86b6001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016136f79190614fb4565b60206040518083038186803b15801561370f57600080fd5b505afa158015613723573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137479190614cea565b60016124b4565b9050600061375d89898961445c565b90507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0876040518263ffffffff1660e01b81526004016000604051808303818588803b1580156137ba57600080fd5b505af11580156137ce573d6000803e3d6000fd5b505060405163a9059cbb60e01b81526001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216935063a9059cbb9250613821915084908a9060040161505f565b602060405180830381600087803b15801561383b57600080fd5b505af115801561384f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138739190614a9d565b50600061388083886130e3565b90508a6001600160a01b03167f6f3269a64126ef2a1959892f3d921e81865181e09a7f72f55d3a49550c53b48d88836040516138bd929190615549565b60405180910390a280156138de576138de6001600160a01b038c1682612501565b505050505b50505050505050565b6000806000806138fa612823565b96509450505050509091565b60008060008061391461449a565b9050600086158015613924575085155b80156139365750613933610b25565b15155b905080156139565760405162461bcd60e51b81526004016103d6906151a3565b61397761396d6139668985613a0c565b8890613c57565b6124ae8a8a613a0c565b925060006139858484613a0c565b9399939850929650505050505050565b60006139ea8530600060405180608001604052808d8c8e6040516020016139be93929190614f58565b60408051601f1981840301815291815290825233602083015260ff8a16908201526060018790526145d1565b9050838110156131b25760405162461bcd60e51b81526004016103d690615132565b6000670de0b6b3a7640000613a36613a248585613caf565b6002670de0b6b3a76400005b04613c57565b81613a3d57fe5b049392505050565b600081613a36613a5d85670de0b6b3a7640000613caf565b600285613a30565b80613b0e576040516323b872dd60e01b81526001600160a01b037f000000000000000000000000f1b99e3e573a1a9c5e6b2ce818b617f0e664e86b16906323b872dd90613aba90879030908890600401614fc8565b602060405180830381600087803b158015613ad457600080fd5b505af1158015613ae8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b0c9190614a9d565b505b600554604051638632cb0360e01b81526101009091046001600160a01b031690638632cb0390613b66907f000000000000000000000000000000000000000000000000000000000000011e9087908790600401615574565b600060405180830381600087803b158015613b8057600080fd5b505af11580156131b2573d6000803e3d6000fd5b4690565b6000838383613ba5613b94565b3060405160200180868152602001858152602001848152602001838152602001826001600160a01b03168152602001955050505050506040516020818303038152906040528051906020012090509392505050565b600082821115613c51576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b80820182811015610a75576040805162461bcd60e51b815260206004820152601460248201527f64732d6d6174682d6164642d6f766572666c6f77000000000000000000000000604482015290519081900360640190fd5b6000811580613cca57505080820282828281613cc757fe5b04145b610a75576040805162461bcd60e51b815260206004820152601460248201527f64732d6d6174682d6d756c2d6f766572666c6f77000000000000000000000000604482015290519081900360640190fd5b6000808211613d71576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b818381613a3d57fe5b6001600160a01b038216600090815260106020908152604080832084845290915290205460ff1615613dbe5760405162461bcd60e51b81526004016103d6906154b7565b6001600160a01b03909116600090815260106020908152604080832093835292905220805460ff19166001179055565b6000613df86125eb565b82604051602001808061190160f01b81525060020183815260200182815260200192505050604051602081830303815290604052805190602001209050919050565b60007f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0821115613e9b5760405162461bcd60e51b81526004018080602001828103825260228152602001806156f06022913960400191505060405180910390fd5b8360ff16601b1480613eb057508360ff16601c145b613eeb5760405162461bcd60e51b81526004018080602001828103825260228152602001806157126022913960400191505060405180910390fd5b600060018686868660405160008152602001604052604051808581526020018460ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa158015613f47573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661340a576040805162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604482015290519081900360640190fd5b600080600080613fc285600001516133c3565b919450925090506001600160a01b0380841690831610600080613fe685878661445c565b6001600160a01b031663128acb088b85613fff8f614710565b6000036001600160a01b038e1615614017578d61403d565b876140365773fffd8963efd1fc6a506488495d951d5263988d2561403d565b6401000276a45b8d60405160200161404e91906154f0565b6040516020818303038152906040526040518663ffffffff1660e01b815260040161407d959493929190615025565b6040805180830381600087803b15801561409657600080fd5b505af11580156140aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140ce9190614ab9565b91509150600080846140e45782846000036140ea565b83836000035b915091508a6001600160a01b03166000141561410c578c811461410c57600080fd5b509b9a5050505050505050505050565b60008061413361412c8587613c57565b8690613a45565b905082156141625761415a614150670de0b6b3a7640000836130e3565b6124ae8584613a0c565b915050610bac565b50929392505050565b6001600160a01b0382166141c6576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b6141d2600083836125e6565b6002546141df90826126b5565b6002556001600160a01b03821660009081526020819052604090205461420590826126b5565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6000818260140110156142b5576040805162461bcd60e51b815260206004820152601260248201527f746f416464726573735f6f766572666c6f770000000000000000000000000000604482015290519081900360640190fd5b816014018351101561430e576040805162461bcd60e51b815260206004820152601560248201527f746f416464726573735f6f75744f66426f756e64730000000000000000000000604482015290519081900360640190fd5b5001602001516c01000000000000000000000000900490565b600081826003011015614381576040805162461bcd60e51b815260206004820152601160248201527f746f55696e7432345f6f766572666c6f77000000000000000000000000000000604482015290519081900360640190fd5b81600301835110156143da576040805162461bcd60e51b815260206004820152601460248201527f746f55696e7432345f6f75744f66426f756e6473000000000000000000000000604482015290519081900360640190fd5b50016003015190565b6143eb6148c8565b826001600160a01b0316846001600160a01b03161115614409579192915b50604080516060810182526001600160a01b03948516815292909316602083015262ffffff169181019190915290565b60006144458383614726565b9050336001600160a01b03821614610a7557600080fd5b60006144927f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f98461448d8686866143e3565b614726565b949350505050565b60008061452e7f00000000000000000000000065d66c76447ccb45daf1e8044e918fa786a483a17f00000000000000000000000082c427adfdf2d245ec51d8046b41c4ee87f0d29c7f000000000000000000000000f1b99e3e573a1a9c5e6b2ce818b617f0e664e86b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26101a46000614822565b90506000600560019054906101000a90046001600160a01b03166001600160a01b031663978bbdb96040518163ffffffff1660e01b815260040160206040518083038186803b15801561458057600080fd5b505afa158015614594573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145b89190614cea565b90506145ca612710612bfc8484613caf565b9250505090565b6000806000806145e485600001516133c3565b919450925090506001600160a01b038083169084161060008061460886868661445c565b6001600160a01b031663128acb088b856146218f614710565b6001600160a01b038e1615614636578d61465c565b876146555773fffd8963efd1fc6a506488495d951d5263988d2561465c565b6401000276a45b8d60405160200161466d91906154f0565b6040516020818303038152906040526040518663ffffffff1660e01b815260040161469c959493929190615025565b6040805180830381600087803b1580156146b557600080fd5b505af11580156146c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146ed9190614ab9565b91509150826146fc57816146fe565b805b6000039b9a5050505050505050505050565b6000600160ff1b821061472257600080fd5b5090565b600081602001516001600160a01b031682600001516001600160a01b03161061474e57600080fd5b50805160208083015160409384015184516001600160a01b0394851681850152939091168385015262ffffff166060808401919091528351808403820181526080840185528051908301207fff0000000000000000000000000000000000000000000000000000000000000060a085015294901b6bffffffffffffffffffffffff191660a183015260b58201939093527fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b5460d5808301919091528251808303909101815260f5909101909152805191012090565b6040805163cce79bd560e01b81526001600160a01b0387811660048301528681166024830152858116604483015263ffffffff851660648301528315156084830152915160009289169163cce79bd59160a4808301926020929190829003018186803b15801561489157600080fd5b505afa1580156148a5573d6000803e3d6000fd5b505050506040513d60208110156148bb57600080fd5b5051979650505050505050565b604080516060810182526000808252602082018190529181019190915290565b8035610ff2816155cd565b8035610ff2816155e2565b600082601f83011261490e578081fd5b813567ffffffffffffffff81111561492257fe5b614935601f8201601f19166020016155a9565b818152846020838601011115614949578283fd5b816020850160208301379081016020019190915292915050565b600060208284031215614974578081fd5b6040516020810181811067ffffffffffffffff8211171561499157fe5b6040529151825250919050565b803562ffffff81168114610ff257600080fd5b803560ff81168114610ff257600080fd5b6000602082840312156149d3578081fd5b8135610bac816155cd565b6000602082840312156149ef578081fd5b8151610bac816155cd565b60008060408385031215614a0c578081fd5b8235614a17816155cd565b91506020830135614a27816155cd565b809150509250929050565b600080600060608486031215614a46578081fd5b8335614a51816155cd565b92506020840135614a61816155cd565b929592945050506040919091013590565b60008060408385031215614a84578182fd5b8235614a8f816155cd565b946020939093013593505050565b600060208284031215614aae578081fd5b8151610bac816155e2565b60008060408385031215614acb578182fd5b505080516020909101519092909150565b60008060008060608587031215614af1578182fd5b8435935060208501359250604085013567ffffffffffffffff80821115614b16578384fd5b818701915087601f830112614b29578384fd5b813581811115614b37578485fd5b886020828501011115614b48578485fd5b95989497505060200194505050565b600060208284031215614b68578081fd5b610bac8383614963565b600060208284031215614b83578081fd5b813567ffffffffffffffff80821115614b9a578283fd5b9083019060808286031215614bad578283fd5b604051608081018181108382111715614bc257fe5b604052823582811115614bd3578485fd5b614bdf878286016148fe565b825250614bee602084016148e8565b6020820152614bff604084016149b1565b6040820152606083013582811115614c15578485fd5b614c21878286016148fe565b60608301525095945050505050565b600060808284031215614c41578081fd5b6040516080810181811067ffffffffffffffff82111715614c5e57fe5b6040528251614c6c816155cd565b81526020830151614c7c816155f0565b602082015260408301516bffffffffffffffffffffffff81168114614c9f578283fd5b604082015260608301516fffffffffffffffffffffffffffffffff81168114614cc6578283fd5b60608201529392505050565b600060208284031215614ce3578081fd5b5035919050565b600060208284031215614cfb578081fd5b5051919050565b60008060408385031215614d14578182fd5b82359150614d246020840161499e565b90509250929050565b60008060008060808587031215614d42578182fd5b843593506020808601359350604080870135614d5d816155e2565b9350606087013567ffffffffffffffff80821115614d79578485fd5b818901915089601f830112614d8c578485fd5b813581811115614d9857fe5b614da585868302016155a9565b8181528581019250838601610140808402860188018e1015614dc5578889fd5b8895505b83861015614e6f5780828f031215614ddf578889fd5b614de8816155a9565b82358152614df78984016148e8565b89820152878301358882015260608301356060820152614e19608084016148f3565b608082015260a0838101359082015260c0808401359082015260e0614e3f8185016149b1565b90820152610100838101359082015261012080840135908201528552600195909501949387019390810190614dc9565b505080965050505050505092959194509250565b600080600060608486031215614e97578081fd5b8335925060208401359150614eae6040850161499e565b90509250925092565b600080600080600060a08688031215614ece578283fd5b505083359560208501359550604085013594606081013594506080013592509050565b600060208284031215614f02578081fd5b8135610bac816155f0565b60008151808452815b81811015614f3257602081850181015186830182015201614f16565b81811115614f435782602083870101525b50601f01601f19169290920160200192915050565b606093841b6bffffffffffffffffffffffff19908116825260e89390931b7fffffff0000000000000000000000000000000000000000000000000000000000166014820152921b166017820152602b0190565b90815260200190565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b039586168152938516602085015291909316604083015263ffffffff9092166060820152901515608082015260a00190565b60006001600160a01b038088168352861515602084015285604084015280851660608401525060a060808301526124f660a0830184614f0d565b6001600160a01b03929092168252602082015260400190565b6001600160a01b0394909416845260208401929092526040830152606082015260800190565b6001600160a01b039690961686526020860194909452604085019290925260608401521515608083015260a082015260c00190565b901515815260200190565b97885260208801969096526001600160a01b0394909416604087015260608601929092526080850152151560a084015260c083015260e08201526101000190565b600060208252610bac6020830184614f0d565b60208082526018908201527f616d6f756e74206f7574206c657373207468616e206d696e0000000000000000604082015260600190565b60208082526003908201526210cc4d60ea1b604082015260600190565b60208082526003908201526204332360ec1b604082015260600190565b60208082526003908201526221991b60e91b604082015260600190565b6020808252601a908201527f616d6f756e7420696e2067726561746572207468616e206d6178000000000000604082015260600190565b602080825260029082015261219960f11b604082015260600190565b60208082526003908201526221989b60e91b604082015260600190565b60208082526027908201527f507269636520746f6f206c6f772072656c617469766520746f20556e6973776160408201527f7020747761702e00000000000000000000000000000000000000000000000000606082015260800190565b60208082526003908201526204331360ec1b604082015260600190565b60208082526003908201526243313360e81b604082015260600190565b60208082526028908201527f507269636520746f6f20686967682072656c617469766520746f20556e69737760408201527f617020747761702e000000000000000000000000000000000000000000000000606082015260800190565b60208082526003908201526243323360e81b604082015260600190565b60208082526003908201526243323560e81b604082015260600190565b60208082526003908201526243313160e81b604082015260600190565b60208082526003908201526208662760eb1b604082015260600190565b60208082526003908201526243323160e81b604082015260600190565b602080825260029082015261433160f01b604082015260600190565b60208082526003908201526243313560e81b604082015260600190565b60208082526003908201526221989960e91b604082015260600190565b602080825260029082015261433760f01b604082015260600190565b60208082526003908201526210cc8d60ea1b604082015260600190565b60208082526003908201526221991960e91b604082015260600190565b60208082526003908201526243313960e81b604082015260600190565b602080825260029082015261433960f01b604082015260600190565b60208082526003908201526243313760e81b604082015260600190565b60208082526003908201526243323760e81b604082015260600190565b602080825260029082015261086760f31b604082015260600190565b60006020825282516080602084015261550c60a0840182614f0d565b90506001600160a01b03602085015116604084015260ff60408501511660608401526060840151601f1984830301608085015261340a8282614f0d565b918252602082015260400190565b938452602084019290925215156040830152606082015260800190565b9283526020830191909152604082015260600190565b63ffffffff91909116815260200190565b60ff91909116815260200190565b60405181810167ffffffffffffffff811182821017156155c557fe5b604052919050565b6001600160a01b0381168114610b2257600080fd5b8015158114610b2257600080fd5b63ffffffff81168114610b2257600080fdfe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e63654f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365416464726573733a20756e61626c6520746f2073656e642076616c75652c20726563697069656e74206d6179206861766520726576657274656445434453413a20696e76616c6964207369676e6174757265202773272076616c756545434453413a20696e76616c6964207369676e6174757265202776272076616c756545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa26469706673582212205588e36b593aca521cd7221641031ca4fe125d2300af7c70ba2abc8ce18bf28564736f6c63430007060033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000064187ae08781b09368e6253f9e94951243a493d500000000000000000000000065d66c76447ccb45daf1e8044e918fa786a483a1000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f98400000000000000000000000082c427adfdf2d245ec51d8046b41c4ee87f0d29c00000000000000000000000067c083ae303741372f0f321bf9cad567cfefe2dc000000000000000000000000a1cab67a4383312718a5799eaa127906e9d4b19e0000000000000000000000000000000000000000000000000000000000000e1000000000000000000000000000000000000000000000000002c68af0bb140000
-----Decoded View---------------
Arg [0] : _wSqueethController (address): 0x64187ae08781B09368e6253F9E94951243A493D5
Arg [1] : _oracle (address): 0x65D66c76447ccB45dAf1e8044e918fA786A483A1
Arg [2] : _weth (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Arg [3] : _uniswapFactory (address): 0x1F98431c8aD98523631AE4a59f267346ea31F984
Arg [4] : _ethWSqueethPool (address): 0x82c427AdFDf2d245Ec51D8046b41c4ee87F0d29C
Arg [5] : _timelock (address): 0x67c083aE303741372F0f321Bf9cAD567CFEFE2DC
Arg [6] : _crabMigration (address): 0xa1CAB67a4383312718a5799Eaa127906e9d4B19E
Arg [7] : _hedgeTimeThreshold (uint256): 3600
Arg [8] : _hedgePriceThreshold (uint256): 200000000000000000
-----Encoded View---------------
9 Constructor Arguments found :
Arg [0] : 00000000000000000000000064187ae08781b09368e6253f9e94951243a493d5
Arg [1] : 00000000000000000000000065d66c76447ccb45daf1e8044e918fa786a483a1
Arg [2] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [3] : 0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f984
Arg [4] : 00000000000000000000000082c427adfdf2d245ec51d8046b41c4ee87f0d29c
Arg [5] : 00000000000000000000000067c083ae303741372f0f321bf9cad567cfefe2dc
Arg [6] : 000000000000000000000000a1cab67a4383312718a5799eaa127906e9d4b19e
Arg [7] : 0000000000000000000000000000000000000000000000000000000000000e10
Arg [8] : 00000000000000000000000000000000000000000000000002c68af0bb140000
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.