More Info
Private Name Tags
ContractCreator
TokenTracker
Latest 25 from a total of 59 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Withdraw | 18370719 | 326 days ago | IN | 0 ETH | 0.00622277 | ||||
Withdraw | 17510022 | 447 days ago | IN | 0 ETH | 0.00401206 | ||||
Withdraw | 17497244 | 449 days ago | IN | 0 ETH | 0.00692064 | ||||
Readjust Liquidi... | 16993841 | 520 days ago | IN | 0 ETH | 0.01344583 | ||||
Withdraw | 16749851 | 554 days ago | IN | 0 ETH | 0.03554855 | ||||
Deposit | 16658773 | 567 days ago | IN | 3.9569847 ETH | 0.00519188 | ||||
Deposit | 16628256 | 571 days ago | IN | 6.0921489 ETH | 0.00943044 | ||||
Withdraw | 16441931 | 597 days ago | IN | 0 ETH | 0.01446344 | ||||
Withdraw | 16440418 | 597 days ago | IN | 0 ETH | 0.00705699 | ||||
Transfer | 16439812 | 597 days ago | IN | 0 ETH | 0.00039458 | ||||
Transfer | 16439809 | 597 days ago | IN | 0 ETH | 0.00081608 | ||||
Withdraw | 16408000 | 602 days ago | IN | 0 ETH | 0.0075565 | ||||
Transfer | 16306448 | 616 days ago | IN | 0 ETH | 0.0007286 | ||||
Transfer | 16305636 | 616 days ago | IN | 0 ETH | 0.00073154 | ||||
Readjust Liquidi... | 16287392 | 619 days ago | IN | 0 ETH | 0.00559356 | ||||
Readjust Liquidi... | 16287379 | 619 days ago | IN | 0 ETH | 0.00961602 | ||||
Deposit | 16241234 | 625 days ago | IN | 1.3714789 ETH | 0.00589813 | ||||
Withdraw | 16087782 | 647 days ago | IN | 0 ETH | 0.00468332 | ||||
Deposit | 16049976 | 652 days ago | IN | 0.0294166 ETH | 0.00303936 | ||||
Withdraw | 16026446 | 655 days ago | IN | 0 ETH | 0.00673106 | ||||
Deposit | 16005706 | 658 days ago | IN | 2.5 ETH | 0.00350106 | ||||
Withdraw | 16005693 | 658 days ago | IN | 0 ETH | 0.00796125 | ||||
Deposit | 16005550 | 658 days ago | IN | 5.0181369 ETH | 0.00329564 | ||||
Withdraw | 15992538 | 660 days ago | IN | 0 ETH | 0.00589616 | ||||
Deposit | 15991822 | 660 days ago | IN | 0.12129812 ETH | 0.00596598 |
Latest 25 internal transactions (View All)
Advanced mode:
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
18370719 | 326 days ago | 0.13228856 ETH | ||||
18370719 | 326 days ago | 0.13228856 ETH | ||||
17510022 | 447 days ago | 0.09487491 ETH | ||||
17510022 | 447 days ago | 0.09487491 ETH | ||||
17497244 | 449 days ago | 0.02485218 ETH | ||||
17497244 | 449 days ago | 0.02485218 ETH | ||||
16749851 | 554 days ago | 9.47941459 ETH | ||||
16749851 | 554 days ago | 9.47941459 ETH | ||||
16658773 | 567 days ago | 3.9569847 ETH | ||||
16628256 | 571 days ago | 0.00000001 ETH | ||||
16628256 | 571 days ago | 6.09214888 ETH | ||||
16441931 | 597 days ago | 0.10018713 ETH | ||||
16441931 | 597 days ago | 0.10018713 ETH | ||||
16440418 | 597 days ago | 2.58307439 ETH | ||||
16440418 | 597 days ago | 2.58307439 ETH | ||||
16408000 | 602 days ago | 0.00966368 ETH | ||||
16408000 | 602 days ago | 0.00966368 ETH | ||||
16241234 | 625 days ago | 1.3714789 ETH | ||||
16087782 | 647 days ago | 0.36916696 ETH | ||||
16087782 | 647 days ago | 0.36916696 ETH | ||||
16049976 | 652 days ago | 0.0294166 ETH | ||||
16026446 | 655 days ago | 4.47131373 ETH | ||||
16026446 | 655 days ago | 4.47131373 ETH | ||||
16005706 | 658 days ago | 2.5 ETH | ||||
16005693 | 658 days ago | 5.01812984 ETH |
Loading...
Loading
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0x3C5bD133...f19978765 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
UnipilotPassiveVault
Compiler Version
v0.7.6+commit.7338295f
Optimization Enabled:
Yes with 10 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
//SPDX-License-Identifier: MIT pragma solidity 0.7.6; pragma abicoder v2; import "./libraries/TransferHelper.sol"; import "./interfaces/external/IWETH9.sol"; import "./interfaces/IUnipilotVault.sol"; import "./interfaces/IUnipilotStrategy.sol"; import "./interfaces/IUnipilotFactory.sol"; import "./libraries/UniswapLiquidityManagement.sol"; import "./libraries/UniswapPoolActions.sol"; import "@openzeppelin/contracts/drafts/ERC20Permit.sol"; /// @title Unipilot Passive Vault /// @author 0xMudassir & 721Orbit /// @notice Passive liquidity managment contract that handles liquidity of any Uniswap V3 pool & earn fees /// @dev UnipilotPassiveVault always maintains 2 range orders on Uniswap V3, /// base order: The main liquidity range -- where the majority of LP capital sits /// limit order: A single token range -- depending on which token it holds more of after the base order was placed. /// @dev The vault readjustment function can be called by anyone to ensure /// the liquidity of vault remains in the most optimum range contract UnipilotPassiveVault is ERC20Permit, IUnipilotVault { using LowGasSafeMath for uint256; using UniswapPoolActions for IUniswapV3Pool; using UniswapLiquidityManagement for IUniswapV3Pool; IERC20 private immutable token0; IERC20 private immutable token1; uint24 private immutable fee; int24 private immutable tickSpacing; address private immutable WETH; IUnipilotFactory private immutable unipilotFactory; TicksData public ticksData; IUniswapV3Pool private pool; uint96 private _unlocked = 1; modifier nonReentrant() { require(_unlocked == 1); _unlocked = 2; _; _unlocked = 1; } modifier checkDeviation() { (, address strategy, , , ) = getProtocolDetails(); IUnipilotStrategy(strategy).checkDeviation(address(pool)); _; } constructor( address _pool, address _unipilotFactory, address _WETH, string memory _name, string memory _symbol ) ERC20Permit(_name) ERC20(_name, _symbol) { WETH = _WETH; unipilotFactory = IUnipilotFactory(_unipilotFactory); pool = IUniswapV3Pool(_pool); token0 = IERC20(pool.token0()); token1 = IERC20(pool.token1()); fee = pool.fee(); tickSpacing = pool.tickSpacing(); } receive() external payable {} fallback() external payable {} /// @inheritdoc IUnipilotVault function deposit( uint256 amount0Desired, uint256 amount1Desired, address recipient ) external payable override nonReentrant returns ( uint256 lpShares, uint256 amount0, uint256 amount1 ) { require(amount0Desired > 0 && amount1Desired > 0); address sender = _msgSender(); uint256 totalSupply = totalSupply(); (lpShares, amount0, amount1) = pool.computeLpShares( false, amount0Desired, amount1Desired, _balance0(), _balance1(), totalSupply, ticksData ); pay(address(token0), sender, address(this), amount0); pay(address(token1), sender, address(this), amount1); if (totalSupply == 0) { setPassivePositions(amount0, amount1); } else { (uint256 amount0Base, uint256 amount1Base) = pool.mintLiquidity( ticksData.baseTickLower, ticksData.baseTickUpper, amount0, amount1 ); pool.mintLiquidity( ticksData.rangeTickLower, ticksData.rangeTickUpper, amount0.sub(amount0Base), amount1.sub(amount1Base) ); } refundETH(); _mint(recipient, lpShares); emit Deposit(sender, recipient, amount0, amount1, lpShares); } /// @inheritdoc IUnipilotVault function withdraw( uint256 liquidity, address recipient, bool refundAsETH ) external override nonReentrant checkDeviation returns (uint256 amount0, uint256 amount1) { require(liquidity > 0); uint256 liquidityShare = FullMath.mulDiv( liquidity, 1e18, totalSupply() ); (uint256 base0, uint256 base1) = burnAndCollect( ticksData.baseTickLower, ticksData.baseTickUpper, liquidityShare ); (uint256 range0, uint256 range1) = burnAndCollect( ticksData.rangeTickLower, ticksData.rangeTickUpper, liquidityShare ); amount0 = base0.add(range0); amount1 = base1.add(range1); uint256 unusedAmount0 = FullMath.mulDiv( _balance0().sub(amount0), liquidity, totalSupply() ); uint256 unusedAmount1 = FullMath.mulDiv( _balance1().sub(amount1), liquidity, totalSupply() ); amount0 = amount0.add(unusedAmount0); amount1 = amount1.add(unusedAmount1); if (amount0 > 0) { transferFunds(refundAsETH, recipient, address(token0), amount0); } if (amount1 > 0) { transferFunds(refundAsETH, recipient, address(token1), amount1); } (base0, base1) = pool.mintLiquidity( ticksData.baseTickLower, ticksData.baseTickUpper, _balance0(), _balance1() ); (range0, range1) = pool.mintLiquidity( ticksData.rangeTickLower, ticksData.rangeTickUpper, _balance0(), _balance1() ); _burn(msg.sender, liquidity); emit Withdraw(recipient, liquidity, amount0, amount1); emit CompoundFees(base0.add(range0), base1.add(range1)); } /// @inheritdoc IUnipilotVault function readjustLiquidity() external override nonReentrant checkDeviation { ( uint256 baseAmount0, uint256 baseAmount1, uint256 baseFees0, uint256 baseFees1 ) = pool.burnLiquidity( ticksData.baseTickLower, ticksData.baseTickUpper, address(this) ); ( uint256 rangeAmount0, uint256 rangeAmount1, uint256 rangeFees0, uint256 rangeFees1 ) = pool.burnLiquidity( ticksData.rangeTickLower, ticksData.rangeTickUpper, address(this) ); transferFeesToIF( true, baseFees0.add(rangeFees0), baseFees1.add(rangeFees1) ); uint256 amount0 = baseAmount0.add(rangeAmount0); uint256 amount1 = baseAmount1.add(rangeAmount1); if (amount0 == 0 || amount1 == 0) { bool zeroForOne = amount0 > 0 ? true : false; (, , , , uint8 swapPercentage) = getProtocolDetails(); int256 amountSpecified = zeroForOne ? int256(FullMath.mulDiv(amount0, swapPercentage, 100)) : int256(FullMath.mulDiv(amount1, swapPercentage, 100)); pool.swapToken(address(this), zeroForOne, amountSpecified); } /// @dev to add remaining amounts in contract other than position liquidity amount0 = _balance0(); amount1 = _balance1(); setPassivePositions(amount0, amount1); } /// @inheritdoc IUnipilotVault function uniswapV3MintCallback( uint256 amount0Owed, uint256 amount1Owed, bytes calldata data ) external override { _verifyCallback(); address recipient = msg.sender; address payer = abi.decode(data, (address)); if (amount0Owed > 0) pay(address(token0), payer, recipient, amount0Owed); if (amount1Owed > 0) pay(address(token1), payer, recipient, amount1Owed); } /// @inheritdoc IUnipilotVault function uniswapV3SwapCallback( int256 amount0, int256 amount1, bytes calldata data ) external override { _verifyCallback(); require(amount0 > 0 || amount1 > 0); bool zeroForOne = abi.decode(data, (bool)); if (zeroForOne) pay(address(token0), address(this), msg.sender, uint256(amount0)); else pay(address(token1), address(this), msg.sender, uint256(amount1)); } /// @notice Calculates the vault's total holdings of TOKEN0 and TOKEN1 - in /// other words, how much of each token the vault would hold if it withdrew /// all its liquidity from Uniswap. /// @dev Updates the position and return the updated reserves, fees & liquidity. /// @return amount0 Amount of token0 in the unipilot vault /// @return amount1 Amount of token1 in the unipilot vault /// @return fees0 Total amount of fees collected by unipilot positions in terms of token0 /// @return fees1 Total amount of fees collected by unipilot positions in terms of token1 /// @return baseLiquidity The total liquidity of the base position /// @return rangeLiquidity The total liquidity of the range position function getPositionDetails() external returns ( uint256 amount0, uint256 amount1, uint256 fees0, uint256 fees1, uint128 baseLiquidity, uint128 rangeLiquidity ) { return pool.getTotalAmounts(false, ticksData); } /// @notice Returns unipilot vault details /// @return The first of the two tokens of the pool, sorted by address /// @return The second of the two tokens of the pool, sorted by address /// @return The pool's fee in hundredths of a bip, i.e. 1e-6 /// @return The address of the Uniswap V3 Pool function getVaultInfo() external view returns ( address, address, uint24, address ) { return (address(token0), address(token1), fee, address(pool)); } /// @dev Amount of token0 held as unused balance. function _balance0() internal view returns (uint256) { return token0.balanceOf(address(this)); } /// @dev Amount of token1 held as unused balance. function _balance1() internal view returns (uint256) { return token1.balanceOf(address(this)); } /// @notice Verify that caller should be the address of a valid Uniswap V3 Pool function _verifyCallback() internal view { require(msg.sender == address(pool)); } function getProtocolDetails() internal view returns ( address governance, address strategy, address indexFund, uint8 indexFundPercentage, uint8 swapPercentage ) { return unipilotFactory.getUnipilotDetails(); } function setPassivePositions( uint256 _amount0Desired, uint256 _amount1Desired ) internal returns (uint256 amount0, uint256 amount1) { Tick memory ticks; ( ticks.baseTickLower, ticks.baseTickUpper, ticks.bidTickLower, ticks.bidTickUpper, ticks.rangeTickLower, ticks.rangeTickUpper ) = _getTicksFromUniStrategy(address(pool)); (amount0, amount1) = pool.mintLiquidity( ticks.baseTickLower, ticks.baseTickUpper, _amount0Desired, _amount1Desired ); ticksData.baseTickLower = ticks.baseTickLower; ticksData.baseTickUpper = ticks.baseTickUpper; uint256 remainingAmount0 = _amount0Desired.sub(amount0); uint256 remainingAmount1 = _amount1Desired.sub(amount1); uint128 rangeLiquidity; if (remainingAmount0 > 0 || remainingAmount1 > 0) { uint128 range0 = pool.getLiquidityForAmounts( remainingAmount0, remainingAmount1, ticks.bidTickLower, ticks.bidTickUpper ); uint128 range1 = pool.getLiquidityForAmounts( remainingAmount0, remainingAmount1, ticks.rangeTickLower, ticks.rangeTickUpper ); /// @dev only one range position will ever have liquidity (if any) if (range1 < range0) { rangeLiquidity = range0; ticksData.rangeTickLower = ticks.bidTickLower; ticksData.rangeTickUpper = ticks.bidTickUpper; } else if (range0 < range1) { ticksData.rangeTickLower = ticks.rangeTickLower; ticksData.rangeTickUpper = ticks.rangeTickUpper; rangeLiquidity = range1; } } if (rangeLiquidity > 0) { (uint256 _rangeAmount0, uint256 _rangeAmount1) = pool.mintLiquidity( ticksData.rangeTickLower, ticksData.rangeTickUpper, remainingAmount0, remainingAmount1 ); amount0 = amount0.add(_rangeAmount0); amount1 = amount1.add(_rangeAmount1); } } /// @dev Burn all the liquidity of unipilot positions, collects up to a /// maximum amount of fees owed to position to the vault address & /// tranfer fees percentage to index fund. function burnAndCollect( int24 tickLower, int24 tickUpper, uint256 liquidityShare ) internal returns (uint256 burnt0, uint256 burnt1) { (burnt0, burnt1) = pool.burnUserLiquidity( tickLower, tickUpper, liquidityShare, address(this) ); (uint256 fees0, uint256 fees1) = pool.collectPendingFees( address(this), tickLower, tickUpper ); transferFeesToIF(false, fees0, fees1); } /// @dev fetches the new ticks for base and range positions function _getTicksFromUniStrategy(address _pool) internal returns ( int24 baseTickLower, int24 baseTickUpper, int24 bidTickLower, int24 bidTickUpper, int24 rangeTickLower, int24 rangeTickUpper ) { (, address strategy, , , ) = getProtocolDetails(); return IUnipilotStrategy(strategy).getTicks(_pool); } /// @dev method to transfer unipilot earned fees to Index Fund function transferFeesToIF( bool isReadjustLiquidity, uint256 fees0, uint256 fees1 ) internal { (, , address indexFund, uint8 percentage, ) = getProtocolDetails(); if (fees0 > 0) TransferHelper.safeTransfer( address(token0), indexFund, FullMath.mulDiv(fees0, percentage, 100) ); if (fees1 > 0) TransferHelper.safeTransfer( address(token1), indexFund, FullMath.mulDiv(fees1, percentage, 100) ); emit FeesSnapshot(isReadjustLiquidity, fees0, fees1); } function transferFunds( bool refundAsETH, address recipient, address token, uint256 amount ) internal { if (refundAsETH && token == WETH) { unwrapWETH9(amount, recipient); } else { TransferHelper.safeTransfer(token, recipient, amount); } } /// @param token The token to pay /// @param payer The entity that must pay /// @param recipient The entity that will receive payment /// @param value The amount to pay function pay( address token, address payer, address recipient, uint256 value ) internal { if (token == WETH && address(this).balance >= value) { // pay with WETH9 IWETH9(WETH).deposit{ value: value }(); // wrap only what is needed to pay IWETH9(WETH).transfer(recipient, value); } else if (payer == address(this)) { // pay with tokens already in the contract (for the exact input multihop case) TransferHelper.safeTransfer(token, recipient, value); } else { // pull payment TransferHelper.safeTransferFrom(token, payer, recipient, value); } } /// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH. /// @param balanceWETH9 The amount of WETH9 to unwrap /// @param recipient The address receiving ETH function unwrapWETH9(uint256 balanceWETH9, address recipient) internal { IWETH9(WETH).withdraw(balanceWETH9); TransferHelper.safeTransferETH(recipient, balanceWETH9); } /// @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() internal { if (address(this).balance > 0) TransferHelper.safeTransferETH(msg.sender, address(this).balance); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.6.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; //import "../interfaces/external/IERC20.sol"; library TransferHelper { /// @notice Transfers tokens from the targeted address to the given destination /// @notice Errors with 'STF' if transfer fails /// @param token The contract address of the token to be transferred /// @param from The originating address from which the tokens will be transferred /// @param to The destination address of the transfer /// @param value The amount to be transferred function safeTransferFrom( address token, address from, address to, uint256 value ) internal { (bool success, bytes memory data) = token.call( abi.encodeWithSelector( IERC20.transferFrom.selector, from, to, value ) ); require( success && (data.length == 0 || abi.decode(data, (bool))), "STF" ); } /// @notice Transfers tokens from msg.sender to a recipient /// @dev Errors with ST if transfer fails /// @param token The contract address of the token which will be transferred /// @param to The recipient of the transfer /// @param value The value of the transfer function safeTransfer( address token, address to, uint256 value ) internal { (bool success, bytes memory data) = token.call( abi.encodeWithSelector(IERC20.transfer.selector, to, value) ); require( success && (data.length == 0 || abi.decode(data, (bool))), "ST" ); } /// @notice Approves the stipulated contract to spend the given allowance in the given token /// @dev Errors with 'SA' if transfer fails /// @param token The contract address of the token to be approved /// @param to The target of the approval /// @param value The amount of the given token the target will be allowed to spend function safeApprove( address token, address to, uint256 value ) internal { (bool success, bytes memory data) = token.call( abi.encodeWithSelector(IERC20.approve.selector, to, value) ); require( success && (data.length == 0 || abi.decode(data, (bool))), "SA" ); } /// @notice Transfers ETH to the recipient address /// @dev Fails with `STE` /// @param to The destination of the transfer /// @param value The value to be transferred function safeTransferETH(address to, uint256 value) internal { (bool success, ) = to.call{ value: value }(new bytes(0)); require(success, "STE"); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.7.6; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /// @title Interface for WETH9 interface IWETH9 is IERC20 { /// @notice Deposit ether to get wrapped ether function deposit() external payable; /// @notice Withdraw wrapped ether to get ether function withdraw(uint256) external; }
//SPDX-License-Identifier: MIT pragma solidity ^0.7.6; interface IUnipilotVault { struct ReadjustVars { uint256 fees0; uint256 fees1; int24 currentTick; int24 tickLower; int24 tickUpper; uint256 amount0Desired; uint256 amount1Desired; uint128 liquidity; uint256 amount0; uint256 amount1; bool zeroForOne; int256 amountSpecified; uint160 exactSqrtPriceImpact; uint160 sqrtPriceLimitX96; } struct TicksData { int24 baseTickLower; int24 baseTickUpper; int24 rangeTickLower; int24 rangeTickUpper; } struct Tick { int24 baseTickLower; int24 baseTickUpper; int24 bidTickLower; int24 bidTickUpper; int24 rangeTickLower; int24 rangeTickUpper; } struct Cache { uint256 totalSupply; uint256 liquidityShare; } event Deposit( address indexed depositor, address indexed recipient, uint256 amount0, uint256 amount1, uint256 lpShares ); event FeesSnapshot(bool isReadjustLiquidity, uint256 fees0, uint256 fees1); event Withdraw( address indexed recipient, uint256 shares, uint256 amount0, uint256 amount1 ); event PullLiquidity( uint256 reserves0, uint256 reserves1, uint256 fees0, uint256 fees1 ); event CompoundFees(uint256 amount0, uint256 amount1); /// @notice Deposits tokens in proportion to the Unipilot's current holdings & mints them /// `Unipilot`s LP token. /// @param amount0Desired Max amount of token0 to deposit /// @param amount1Desired Max amount of token1 to deposit /// @param recipient Recipient of shares /// @return lpShares Number of shares minted /// @return amount0 Amount of token0 deposited in vault /// @return amount1 Amount of token1 deposited in vault function deposit( uint256 amount0Desired, uint256 amount1Desired, address recipient ) external payable returns ( uint256 lpShares, uint256 amount0, uint256 amount1 ); /// @notice Withdraws the desired shares from the vault with accumulated user fees and transfers to recipient. /// @param recipient Recipient of tokens /// @param refundAsETH whether to recieve in WETH or ETH (only valid for WETH/ALT pairs) /// @return amount0 Amount of token0 sent to recipient /// @return amount1 Amount of token1 sent to recipient function withdraw( uint256 liquidity, address recipient, bool refundAsETH ) external returns (uint256 amount0, uint256 amount1); /// @notice Pull in tokens from sender. Called to `msg.sender` after minting liquidity to a position from IUniswapV3Pool#mint. /// @dev In the implementation you must pay to the pool for the minted liquidity. /// @param amount0Owed The amount of token0 due to the pool for the minted liquidity /// @param amount1Owed The amount of token1 due to the pool for the minted liquidity /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#mint call function uniswapV3MintCallback( uint256 amount0Owed, uint256 amount1Owed, bytes calldata data ) external; /// @notice Called to `msg.sender` after minting swaping from IUniswapV3Pool#swap. /// @dev In the implementation you must pay to the pool for swap. /// @param amount0Delta The amount of token0 due to the pool for the swap /// @param amount1Delta The amount of token1 due to the pool for the swap /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call function uniswapV3SwapCallback( int256 amount0Delta, int256 amount1Delta, bytes calldata data ) external; /// @notice Burns all position(s), collects any fees accrued and updates Unipilot's position(s) /// @dev mints all amounts to this position(s) (including earned fees) /// @dev For active vaults it can be called by the governance or operator, /// swaps imbalanced token and add all liquidity in base position. /// @dev For passive vaults it can be called by any user. /// Two positions are placed - a base position and a limit position. The base /// position is placed first with as much liquidity as possible. This position /// should use up all of one token, leaving only the other one. This excess /// amount is then placed as a single-sided bid or ask position. function readjustLiquidity() external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.6; pragma abicoder v2; interface IUnipilotStrategy { struct PoolStrategy { int24 baseThreshold; int24 rangeThreshold; int24 maxTwapDeviation; int24 readjustThreshold; uint32 twapDuration; int24 baseMultiplier; } event GovernanceUpdated(address oldGovernance, address newGovernance); event StrategyUpdated(PoolStrategy oldStrategy, PoolStrategy newStrategy); event MaxTwapDeviationUpdated(int24 oldDeviation, int24 newDeviation); event BaseTicksUpdated(int24 oldBaseTicks, int24 newBaseTicks); event RangeTicksUpdated(int24 oldRangeTicks, int24 newRangeTicks); event TwapDurationUpdated(uint32 oldDuration, uint32 newDuration); event ReadjustMultiplierUpdated(int24 oldMultiplier, int24 newMultiplier); function getTicks(address _pool) external returns ( int24 baseLower, int24 baseUpper, int24 bidLower, int24 bidUpper, int24 askLower, int24 askUpper ); function getTwap(address _pool) external view returns (int24); function getStrategy(address _pool) external view returns (PoolStrategy memory strategy); function getBaseThreshold(address _pool) external view returns (int24 baseThreshold); function twapDuration() external view returns (uint32); function maxTwapDeviation() external view returns (int24); function checkDeviation(address pool) external view; }
//SPDX-License-Identifier: MIT pragma solidity ^0.7.6; /// @title The interface for the Unipilot Factory interface IUnipilotFactory { /// @notice Emitted when a vault is created /// @param _tokenA The first token of the pool by address sort order /// @param _tokenB The second token of the pool by address sort order /// @param _fee The fee tier for which the vault is created /// @param _vault The address of the vault that is created event VaultCreated( address indexed _tokenA, address indexed _tokenB, uint24 _fee, address indexed _vault ); /// @notice Emitted when the governance of the factory is changed /// @param _oldGovernance The governance before the governance was changed /// @param _newGovernance The governance after the governance was changed event GovernanceChanged( address indexed _oldGovernance, address indexed _newGovernance ); /// @notice Creates a vault for the given two tokens and fee /// @param _tokenA The first token of the pool by address sort order /// @param _tokenB The second token of the pool by address sort order /// @param _fee The desired fee for the unipilot vault /// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. /// The call will revert if the vault already exists, the fee is invalid, or the token arguments /// are invalid. /// @return _vault The address of the newly created pool function createVault( address _tokenA, address _tokenB, uint24 _fee, uint160 _sqrtPriceX96, string memory _name, string memory _symbol ) external returns (address _vault); /// @notice Returns the vault address for a given uniswap v3 pair of tokens and a fee /// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order /// @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 vault The vault address function vaults( address tokenA, address tokenB, uint24 fee ) external view returns (address vault); /// @notice Returns the status for a given account that can recieve the vault reserves after pull liquidity /// @dev by default vault address will be whitelist as a recipient in order to resist IL /// @dev Only applicable for active vaults function isWhitelist(address recipient) external view returns (bool); /// @notice Used to give addresses of governance, strategy, indexFund /// @return governance address, strategy address, indexFund address function getUnipilotDetails() external view returns ( address, address, address, uint8, uint8 ); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import "./UniswapPoolActions.sol"; import "@uniswap/v3-core/contracts/libraries/TickMath.sol"; import "@uniswap/v3-core/contracts/libraries/SqrtPriceMath.sol"; import "@uniswap/v3-periphery/contracts/libraries/PositionKey.sol"; import "@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol"; import "../interfaces/IUnipilotVault.sol"; /// @title Liquidity and ticks functions /// @notice Provides functions for computing liquidity and ticks for token amounts and prices library UniswapLiquidityManagement { using LowGasSafeMath for uint256; struct Info { uint256 amount0Desired; uint256 amount1Desired; uint256 amount0; uint256 amount1; uint128 liquidity; int24 tickLower; int24 tickUpper; } /// @dev Wrapper around `LiquidityAmounts.getAmountsForLiquidity()`. /// @param pool Uniswap V3 pool /// @param liquidity The liquidity being valued /// @param _tickLower The lower tick of the range /// @param _tickUpper The upper tick of the range /// @return amounts of token0 and token1 that corresponds to liquidity function getAmountsForLiquidity( IUniswapV3Pool pool, uint128 liquidity, int24 _tickLower, int24 _tickUpper ) internal view returns (uint256, uint256) { (uint160 sqrtRatioX96, , , , , , ) = pool.slot0(); return LiquidityAmounts.getAmountsForLiquidity( sqrtRatioX96, TickMath.getSqrtRatioAtTick(_tickLower), TickMath.getSqrtRatioAtTick(_tickUpper), liquidity ); } /// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmounts()`. /// @param pool Uniswap V3 pool /// @param amount0 The amount of token0 /// @param amount1 The amount of token1 /// @param _tickLower The lower tick of the range /// @param _tickUpper The upper tick of the range /// @return The maximum amount of liquidity that can be held amount0 and amount1 function getLiquidityForAmounts( IUniswapV3Pool pool, uint256 amount0, uint256 amount1, int24 _tickLower, int24 _tickUpper ) internal view returns (uint128) { (uint160 sqrtRatioX96, , , , , , ) = pool.slot0(); return LiquidityAmounts.getLiquidityForAmounts( sqrtRatioX96, TickMath.getSqrtRatioAtTick(_tickLower), TickMath.getSqrtRatioAtTick(_tickUpper), amount0, amount1 ); } /// @dev Amount of liquidity in contract position. /// @param pool Uniswap V3 pool /// @param _tickLower The lower tick of the range /// @param _tickUpper The upper tick of the range /// @return liquidity stored in position function getPositionLiquidity( IUniswapV3Pool pool, int24 _tickLower, int24 _tickUpper ) internal view returns ( uint128 liquidity, uint128 tokensOwed0, uint128 tokensOwed1 ) { bytes32 positionKey = PositionKey.compute( address(this), _tickLower, _tickUpper ); (liquidity, , , tokensOwed0, tokensOwed1) = pool.positions(positionKey); } /// @dev Rounds tick down towards negative infinity so that it's a multiple /// of `tickSpacing`. function floor(int24 tick, int24 tickSpacing) internal pure returns (int24) { int24 compressed = tick / tickSpacing; if (tick < 0 && tick % tickSpacing != 0) compressed--; return compressed * tickSpacing; } function getSqrtRatioX96AndTick(IUniswapV3Pool pool) internal view returns ( uint160 _sqrtRatioX96, int24 _tick, uint16 observationCardinality ) { (_sqrtRatioX96, _tick, , observationCardinality, , , ) = pool.slot0(); } /// @dev Calc base ticks depending on base threshold and tickspacing function getBaseTicks( int24 currentTick, int24 baseThreshold, int24 tickSpacing ) internal pure returns (int24 tickLower, int24 tickUpper) { int24 tickFloor = floor(currentTick, tickSpacing); tickLower = tickFloor - baseThreshold; tickUpper = tickFloor + baseThreshold; } function collectableAmountsInPosition( IUniswapV3Pool pool, int24 _lowerTick, int24 _upperTick ) internal view returns ( uint256, uint256, uint256, uint256 ) { ( uint128 liquidity, uint128 earnable0, uint128 earnable1 ) = getPositionLiquidity(pool, _lowerTick, _upperTick); (uint256 burnable0, uint256 burnable1) = UniswapLiquidityManagement .getAmountsForLiquidity(pool, liquidity, _lowerTick, _upperTick); return (burnable0, burnable1, earnable0, earnable1); } function computeLpShares( IUniswapV3Pool pool, bool isWhitelisted, uint256 amount0Max, uint256 amount1Max, uint256 balance0, uint256 balance1, uint256 totalSupply, IUnipilotVault.TicksData memory ticks ) internal returns ( uint256 shares, uint256 amount0, uint256 amount1 ) { ( uint256 res0, uint256 res1, uint256 fees0, uint256 fees1, , ) = getTotalAmounts(pool, isWhitelisted, ticks); uint256 reserve0 = res0.add(fees0).add(balance0); uint256 reserve1 = res1.add(fees1).add(balance1); // If total supply > 0, pool can't be empty assert(totalSupply == 0 || reserve0 != 0 || reserve1 != 0); (shares, amount0, amount1) = calculateShare( amount0Max, amount1Max, reserve0, reserve1, totalSupply ); } function getTotalAmounts( IUniswapV3Pool pool, bool isWhitelisted, IUnipilotVault.TicksData memory ticks ) internal returns ( uint256 amount0, uint256 amount1, uint256 fees0, uint256 fees1, uint128 baseLiquidity, uint128 rangeLiquidity ) { (amount0, amount1, fees0, fees1, baseLiquidity) = getReserves( pool, ticks.baseTickLower, ticks.baseTickUpper ); if (!isWhitelisted) { ( uint256 range0, uint256 range1, uint256 rangeFees0, uint256 rangeFees1, uint128 rangeliquidity ) = getReserves(pool, ticks.rangeTickLower, ticks.rangeTickUpper); amount0 = amount0.add(range0); amount1 = amount1.add(range1); fees0 = fees0.add(rangeFees0); fees1 = fees1.add(rangeFees1); rangeLiquidity = rangeliquidity; } } function getReserves( IUniswapV3Pool pool, int24 tickLower, int24 tickUpper ) internal returns ( uint256 amount0, uint256 amount1, uint256 fees0, uint256 fees1, uint128 liquidity ) { liquidity = UniswapPoolActions.updatePosition( pool, tickLower, tickUpper ); if (liquidity > 0) { (amount0, amount1, fees0, fees1) = collectableAmountsInPosition( pool, tickLower, tickUpper ); } } function calculateShare( uint256 amount0Max, uint256 amount1Max, uint256 reserve0, uint256 reserve1, uint256 totalSupply ) internal pure returns ( uint256 shares, uint256 amount0, uint256 amount1 ) { if (totalSupply == 0) { // For first deposit, just use the amounts desired amount0 = amount0Max; amount1 = amount1Max; shares = amount0 > amount1 ? amount0 : amount1; // max } else if (reserve0 == 0) { amount1 = amount1Max; shares = FullMath.mulDiv(amount1, totalSupply, reserve1); } else if (reserve1 == 0) { amount0 = amount0Max; shares = FullMath.mulDiv(amount0, totalSupply, reserve0); } else { amount0 = FullMath.mulDiv(amount1Max, reserve0, reserve1); if (amount0 < amount0Max) { amount1 = amount1Max; shares = FullMath.mulDiv(amount1, totalSupply, reserve1); } else { amount0 = amount0Max; amount1 = FullMath.mulDiv(amount0, reserve1, reserve0); shares = FullMath.mulDiv(amount0, totalSupply, reserve0); } } } /// @dev Gets ticks with proportion equivalent to desired amount /// @param pool Uniswap V3 pool /// @param amount0Desired The desired amount of token0 /// @param amount1Desired The desired amount of token1 /// @param baseThreshold The range for upper and lower ticks /// @param tickSpacing The pool tick spacing /// @return tickLower The lower tick of the range /// @return tickUpper The upper tick of the range function getPositionTicks( IUniswapV3Pool pool, uint256 amount0Desired, uint256 amount1Desired, int24 baseThreshold, int24 tickSpacing ) internal view returns (int24 tickLower, int24 tickUpper) { Info memory cache = Info(amount0Desired, amount1Desired, 0, 0, 0, 0, 0); // Get current price and tick from the pool (uint160 sqrtPriceX96, int24 currentTick, , , , , ) = pool.slot0(); //Calc base ticks (cache.tickLower, cache.tickUpper) = getBaseTicks( currentTick, baseThreshold, tickSpacing ); //Calc amounts of token0 and token1 that can be stored in base range (cache.amount0, cache.amount1) = getAmountsForTicks( pool, cache.amount0Desired, cache.amount1Desired, cache.tickLower, cache.tickUpper ); // //Liquidity that can be stored in base range cache.liquidity = getLiquidityForAmounts( pool, cache.amount0, cache.amount1, cache.tickLower, cache.tickUpper ); // //Get imbalanced token bool zeroGreaterOne = amountsDirection( cache.amount0Desired, cache.amount1Desired, cache.amount0, cache.amount1 ); //Calc new tick(upper or lower) for imbalanced token if (zeroGreaterOne) { uint160 nextSqrtPrice0 = SqrtPriceMath .getNextSqrtPriceFromAmount0RoundingUp( sqrtPriceX96, cache.liquidity, cache.amount0Desired, false ); cache.tickUpper = floor( TickMath.getTickAtSqrtRatio(nextSqrtPrice0), tickSpacing ); } else { uint160 nextSqrtPrice1 = SqrtPriceMath .getNextSqrtPriceFromAmount1RoundingDown( sqrtPriceX96, cache.liquidity, cache.amount1Desired, false ); cache.tickLower = floor( TickMath.getTickAtSqrtRatio(nextSqrtPrice1), tickSpacing ); } checkRange(cache.tickLower, cache.tickUpper); /// floor the tick again because one tick is still not valid tick due to + - baseThreshold tickLower = floor(cache.tickLower, tickSpacing); tickUpper = floor(cache.tickUpper, tickSpacing); } /// @dev Gets amounts of token0 and token1 that can be stored in range of upper and lower ticks /// @param pool Uniswap V3 pool /// @param amount0Desired The desired amount of token0 /// @param amount1Desired The desired amount of token1 /// @param _tickLower The lower tick of the range /// @param _tickUpper The upper tick of the range /// @return amount0 amounts of token0 that can be stored in range /// @return amount1 amounts of token1 that can be stored in range function getAmountsForTicks( IUniswapV3Pool pool, uint256 amount0Desired, uint256 amount1Desired, int24 _tickLower, int24 _tickUpper ) internal view returns (uint256 amount0, uint256 amount1) { uint128 liquidity = getLiquidityForAmounts( pool, amount0Desired, amount1Desired, _tickLower, _tickUpper ); (amount0, amount1) = getAmountsForLiquidity( pool, liquidity, _tickLower, _tickUpper ); } /// @dev Common checks for valid tick inputs. /// @param tickLower The lower tick of the range /// @param tickUpper The upper tick of the range function checkRange(int24 tickLower, int24 tickUpper) internal pure { require(tickLower < tickUpper, "TLU"); require(tickLower >= TickMath.MIN_TICK, "TLM"); require(tickUpper <= TickMath.MAX_TICK, "TUM"); } /// @dev Get imbalanced token /// @param amount0Desired The desired amount of token0 /// @param amount1Desired The desired amount of token1 /// @param amount0 Amounts of token0 that can be stored in base range /// @param amount1 Amounts of token1 that can be stored in base range /// @return zeroGreaterOne true if token0 is imbalanced. False if token1 is imbalanced function amountsDirection( uint256 amount0Desired, uint256 amount1Desired, uint256 amount0, uint256 amount1 ) internal pure returns (bool zeroGreaterOne) { zeroGreaterOne = amount0Desired.sub(amount0).mul(amount1Desired) > amount1Desired.sub(amount1).mul(amount0Desired) ? true : false; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import "./SafeCastExtended.sol"; import "./UniswapLiquidityManagement.sol"; import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; import "@uniswap/v3-core/contracts/libraries/FullMath.sol"; import "@uniswap/v3-core/contracts/libraries/LowGasSafeMath.sol"; /// @title Liquidity and ticks functions /// @notice Provides functions for computing liquidity and ticks for token amounts and prices library UniswapPoolActions { using LowGasSafeMath for uint256; using SafeCastExtended for uint256; using UniswapLiquidityManagement for IUniswapV3Pool; function updatePosition( IUniswapV3Pool pool, int24 tickLower, int24 tickUpper ) internal returns (uint128 liquidity) { (liquidity, , ) = pool.getPositionLiquidity(tickLower, tickUpper); if (liquidity > 0) { pool.burn(tickLower, tickUpper, 0); } } function burnLiquidity( IUniswapV3Pool pool, int24 tickLower, int24 tickUpper, address recipient ) internal returns ( uint256 amount0, uint256 amount1, uint256 fees0, uint256 fees1 ) { (uint128 liquidity, , ) = pool.getPositionLiquidity( tickLower, tickUpper ); if (liquidity > 0) { (amount0, amount1) = pool.burn(tickLower, tickUpper, liquidity); if (amount0 > 0 || amount1 > 0) { (uint256 collect0, uint256 collect1) = pool.collect( recipient, tickLower, tickUpper, type(uint128).max, type(uint128).max ); (fees0, fees1) = (collect0.sub(amount0), collect1.sub(amount1)); } } } function burnUserLiquidity( IUniswapV3Pool pool, int24 tickLower, int24 tickUpper, uint256 userSharePercentage, address recipient ) internal returns (uint256 amount0, uint256 amount1) { (uint128 liquidity, , ) = pool.getPositionLiquidity( tickLower, tickUpper ); uint256 liquidityRemoved = FullMath.mulDiv( uint256(liquidity), userSharePercentage, 1e18 ); (amount0, amount1) = pool.burn( tickLower, tickUpper, liquidityRemoved.toUint128() ); if (amount0 > 0 || amount1 > 0) { (amount0, amount0) = pool.collect( recipient, tickLower, tickUpper, amount0.toUint128(), amount1.toUint128() ); } } function mintLiquidity( IUniswapV3Pool pool, int24 tickLower, int24 tickUpper, uint256 amount0Desired, uint256 amount1Desired ) internal returns (uint256 amount0, uint256 amount1) { uint128 liquidity = pool.getLiquidityForAmounts( amount0Desired, amount1Desired, tickLower, tickUpper ); if (liquidity > 0) { (amount0, amount1) = pool.mint( address(this), tickLower, tickUpper, liquidity, abi.encode(address(this)) ); } } function swapToken( IUniswapV3Pool pool, address recipient, bool zeroForOne, int256 amountSpecified ) internal { (uint160 sqrtPriceX96, , ) = pool.getSqrtRatioX96AndTick(); uint160 exactSqrtPriceImpact = (sqrtPriceX96 * (1e5 / 2)) / 1e6; uint160 sqrtPriceLimitX96 = zeroForOne ? sqrtPriceX96 - exactSqrtPriceImpact : sqrtPriceX96 + exactSqrtPriceImpact; pool.swap( recipient, zeroForOne, amountSpecified, sqrtPriceLimitX96, abi.encode(zeroForOne) ); } function collectPendingFees( IUniswapV3Pool pool, address recipient, int24 tickLower, int24 tickUpper ) internal returns (uint256 collect0, uint256 collect1) { updatePosition(pool, tickLower, tickUpper); (collect0, collect1) = pool.collect( recipient, tickLower, tickUpper, type(uint128).max, type(uint128).max ); } function rerangeLiquidity( IUniswapV3Pool pool, int24 baseThreshold, int24 tickSpacing, uint256 balance0, uint256 balance1 ) internal returns (int24 tickLower, int24 tickUpper) { (tickLower, tickUpper) = pool.getPositionTicks( balance0, balance1, baseThreshold, tickSpacing ); mintLiquidity(pool, tickLower, tickUpper, balance0, balance1); } }
// SPDX-License-Identifier: MIT pragma solidity >=0.6.5 <0.8.0; import "../token/ERC20/ERC20.sol"; import "./IERC20Permit.sol"; import "../cryptography/ECDSA.sol"; import "../utils/Counters.sol"; import "./EIP712.sol"; /** * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. * * _Available since v3.4._ */ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { using Counters for Counters.Counter; mapping (address => Counters.Counter) private _nonces; // solhint-disable-next-line var-name-mixedcase bytes32 private immutable _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); /** * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`. * * It's a good idea to use the same `name` that is defined as the ERC20 token name. */ constructor(string memory name) EIP712(name, "1") { } /** * @dev See {IERC20Permit-permit}. */ function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public virtual override { // solhint-disable-next-line not-rely-on-time require(block.timestamp <= deadline, "ERC20Permit: expired deadline"); bytes32 structHash = keccak256( abi.encode( _PERMIT_TYPEHASH, owner, spender, value, _nonces[owner].current(), deadline ) ); bytes32 hash = _hashTypedDataV4(structHash); address signer = ECDSA.recover(hash, v, r, s); require(signer == owner, "ERC20Permit: invalid signature"); _nonces[owner].increment(); _approve(owner, spender, value); } /** * @dev See {IERC20Permit-nonces}. */ function nonces(address owner) public view override returns (uint256) { return _nonces[owner].current(); } /** * @dev See {IERC20Permit-DOMAIN_SEPARATOR}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view override returns (bytes32) { return _domainSeparatorV4(); } }
// 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 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: BUSL-1.1 pragma solidity >=0.5.0; import './LowGasSafeMath.sol'; import './SafeCast.sol'; import './FullMath.sol'; import './UnsafeMath.sol'; import './FixedPoint96.sol'; /// @title Functions based on Q64.96 sqrt price and liquidity /// @notice Contains the math that uses square root of price as a Q64.96 and liquidity to compute deltas library SqrtPriceMath { using LowGasSafeMath for uint256; using SafeCast for uint256; /// @notice Gets the next sqrt price given a delta of token0 /// @dev Always rounds up, because in the exact output case (increasing price) we need to move the price at least /// far enough to get the desired output amount, and in the exact input case (decreasing price) we need to move the /// price less in order to not send too much output. /// The most precise formula for this is liquidity * sqrtPX96 / (liquidity +- amount * sqrtPX96), /// if this is impossible because of overflow, we calculate liquidity / (liquidity / sqrtPX96 +- amount). /// @param sqrtPX96 The starting price, i.e. before accounting for the token0 delta /// @param liquidity The amount of usable liquidity /// @param amount How much of token0 to add or remove from virtual reserves /// @param add Whether to add or remove the amount of token0 /// @return The price after adding or removing amount, depending on add function getNextSqrtPriceFromAmount0RoundingUp( uint160 sqrtPX96, uint128 liquidity, uint256 amount, bool add ) internal pure returns (uint160) { // we short circuit amount == 0 because the result is otherwise not guaranteed to equal the input price if (amount == 0) return sqrtPX96; uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION; if (add) { uint256 product; if ((product = amount * sqrtPX96) / amount == sqrtPX96) { uint256 denominator = numerator1 + product; if (denominator >= numerator1) // always fits in 160 bits return uint160(FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator)); } return uint160(UnsafeMath.divRoundingUp(numerator1, (numerator1 / sqrtPX96).add(amount))); } else { uint256 product; // if the product overflows, we know the denominator underflows // in addition, we must check that the denominator does not underflow require((product = amount * sqrtPX96) / amount == sqrtPX96 && numerator1 > product); uint256 denominator = numerator1 - product; return FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator).toUint160(); } } /// @notice Gets the next sqrt price given a delta of token1 /// @dev Always rounds down, because in the exact output case (decreasing price) we need to move the price at least /// far enough to get the desired output amount, and in the exact input case (increasing price) we need to move the /// price less in order to not send too much output. /// The formula we compute is within <1 wei of the lossless version: sqrtPX96 +- amount / liquidity /// @param sqrtPX96 The starting price, i.e., before accounting for the token1 delta /// @param liquidity The amount of usable liquidity /// @param amount How much of token1 to add, or remove, from virtual reserves /// @param add Whether to add, or remove, the amount of token1 /// @return The price after adding or removing `amount` function getNextSqrtPriceFromAmount1RoundingDown( uint160 sqrtPX96, uint128 liquidity, uint256 amount, bool add ) internal pure returns (uint160) { // if we're adding (subtracting), rounding down requires rounding the quotient down (up) // in both cases, avoid a mulDiv for most inputs if (add) { uint256 quotient = ( amount <= type(uint160).max ? (amount << FixedPoint96.RESOLUTION) / liquidity : FullMath.mulDiv(amount, FixedPoint96.Q96, liquidity) ); return uint256(sqrtPX96).add(quotient).toUint160(); } else { uint256 quotient = ( amount <= type(uint160).max ? UnsafeMath.divRoundingUp(amount << FixedPoint96.RESOLUTION, liquidity) : FullMath.mulDivRoundingUp(amount, FixedPoint96.Q96, liquidity) ); require(sqrtPX96 > quotient); // always fits 160 bits return uint160(sqrtPX96 - quotient); } } /// @notice Gets the next sqrt price given an input amount of token0 or token1 /// @dev Throws if price or liquidity are 0, or if the next price is out of bounds /// @param sqrtPX96 The starting price, i.e., before accounting for the input amount /// @param liquidity The amount of usable liquidity /// @param amountIn How much of token0, or token1, is being swapped in /// @param zeroForOne Whether the amount in is token0 or token1 /// @return sqrtQX96 The price after adding the input amount to token0 or token1 function getNextSqrtPriceFromInput( uint160 sqrtPX96, uint128 liquidity, uint256 amountIn, bool zeroForOne ) internal pure returns (uint160 sqrtQX96) { require(sqrtPX96 > 0); require(liquidity > 0); // round to make sure that we don't pass the target price return zeroForOne ? getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountIn, true) : getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountIn, true); } /// @notice Gets the next sqrt price given an output amount of token0 or token1 /// @dev Throws if price or liquidity are 0 or the next price is out of bounds /// @param sqrtPX96 The starting price before accounting for the output amount /// @param liquidity The amount of usable liquidity /// @param amountOut How much of token0, or token1, is being swapped out /// @param zeroForOne Whether the amount out is token0 or token1 /// @return sqrtQX96 The price after removing the output amount of token0 or token1 function getNextSqrtPriceFromOutput( uint160 sqrtPX96, uint128 liquidity, uint256 amountOut, bool zeroForOne ) internal pure returns (uint160 sqrtQX96) { require(sqrtPX96 > 0); require(liquidity > 0); // round to make sure that we pass the target price return zeroForOne ? getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountOut, false) : getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountOut, false); } /// @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 ) internal 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 ) internal 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); } /// @notice Helper that gets signed token0 delta /// @param sqrtRatioAX96 A sqrt price /// @param sqrtRatioBX96 Another sqrt price /// @param liquidity The change in liquidity for which to compute the amount0 delta /// @return amount0 Amount of token0 corresponding to the passed liquidityDelta between the two prices function getAmount0Delta( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, int128 liquidity ) internal pure returns (int256 amount0) { return liquidity < 0 ? -getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(-liquidity), false).toInt256() : getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(liquidity), true).toInt256(); } /// @notice Helper that gets signed token1 delta /// @param sqrtRatioAX96 A sqrt price /// @param sqrtRatioBX96 Another sqrt price /// @param liquidity The change in liquidity for which to compute the amount1 delta /// @return amount1 Amount of token1 corresponding to the passed liquidityDelta between the two prices function getAmount1Delta( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, int128 liquidity ) internal pure returns (int256 amount1) { return liquidity < 0 ? -getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(-liquidity), false).toInt256() : getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(liquidity), true).toInt256(); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; library PositionKey { /// @dev Returns the key of the position in the core library function compute( address owner, int24 tickLower, int24 tickUpper ) internal pure returns (bytes32) { return keccak256(abi.encodePacked(owner, tickLower, tickUpper)); } }
// 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/FixedPoint96.sol'; /// @title Liquidity amount functions /// @notice Provides functions for computing liquidity amounts from token amounts and prices library LiquidityAmounts { /// @notice Downcasts uint256 to uint128 /// @param x The uint258 to be downcasted /// @return y The passed value, downcasted to uint128 function toUint128(uint256 x) private pure returns (uint128 y) { require((y = uint128(x)) == x); } /// @notice Computes the amount of liquidity received for a given amount of token0 and price range /// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower)) /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount0 The amount0 being sent in /// @return liquidity The amount of returned liquidity function getLiquidityForAmount0( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96); return toUint128(FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96)); } /// @notice Computes the amount of liquidity received for a given amount of token1 and price range /// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)). /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount1 The amount1 being sent in /// @return liquidity The amount of returned liquidity function getLiquidityForAmount1( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount1 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return toUint128(FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtRatioBX96 - sqrtRatioAX96)); } /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current /// pool prices and the prices at the tick boundaries /// @param sqrtRatioX96 A sqrt price representing the current pool prices /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount0 The amount of token0 being sent in /// @param amount1 The amount of token1 being sent in /// @return liquidity The maximum amount of liquidity received function getLiquidityForAmounts( uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); if (sqrtRatioX96 <= sqrtRatioAX96) { liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0); } else if (sqrtRatioX96 < sqrtRatioBX96) { uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0); uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1); liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1; } else { liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1); } } /// @notice Computes the amount of token0 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount0 The amount of token0 function getAmount0ForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return FullMath.mulDiv( uint256(liquidity) << FixedPoint96.RESOLUTION, sqrtRatioBX96 - sqrtRatioAX96, sqrtRatioBX96 ) / sqrtRatioAX96; } /// @notice Computes the amount of token1 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount1 The amount of token1 function getAmount1ForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96); } /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current /// pool prices and the prices at the tick boundaries /// @param sqrtRatioX96 A sqrt price representing the current pool prices /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount0 The amount of token0 /// @return amount1 The amount of token1 function getAmountsForLiquidity( uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0, uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); if (sqrtRatioX96 <= sqrtRatioAX96) { amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } else if (sqrtRatioX96 < sqrtRatioBX96) { amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity); amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity); } else { amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. * * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing * all math on `uint256` and `int256` and then downcasting. */ library SafeCastExtended { /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits */ function toUint128(uint256 value) internal pure returns (uint128) { require(value < 2**128, "SafeCast: value doesn't fit in 128 bits"); return uint128(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits */ function toUint64(uint256 value) internal pure returns (uint64) { require(value < 2**64, "SafeCast: value doesn't fit in 64 bits"); return uint64(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits */ function toUint32(uint256 value) internal pure returns (uint32) { require(value < 2**32, "SafeCast: value doesn't fit in 32 bits"); return uint32(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits */ function toUint16(uint256 value) internal pure returns (uint16) { require(value < 2**16, "SafeCast: value doesn't fit in 16 bits"); return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits. */ function toUint8(uint256 value) internal pure returns (uint8) { require(value < 2**8, "SafeCast: value doesn't fit in 8 bits"); return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. */ function toUint256(int256 value) internal pure returns (uint256) { require(value >= 0, "SafeCast: value must be positive"); return uint256(value); } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v3.1._ */ function toInt128(int256 value) internal pure returns (int128) { require( value >= -2**127 && value < 2**127, "SafeCast: value doesn't fit in 128 bits" ); return int128(value); } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v3.1._ */ function toInt64(int256 value) internal pure returns (int64) { require( value >= -2**63 && value < 2**63, "SafeCast: value doesn't fit in 64 bits" ); return int64(value); } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v3.1._ */ function toInt32(int256 value) internal pure returns (int32) { require( value >= -2**31 && value < 2**31, "SafeCast: value doesn't fit in 32 bits" ); return int32(value); } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v3.1._ */ function toInt16(int256 value) internal pure returns (int16) { require( value >= -2**15 && value < 2**15, "SafeCast: value doesn't fit in 16 bits" ); return int16(value); } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits. * * _Available since v3.1._ */ function toInt8(int256 value) internal pure returns (int8) { require( value >= -2**7 && value < 2**7, "SafeCast: value doesn't fit in 8 bits" ); return int8(value); } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. */ function toInt256(uint256 value) internal pure returns (int256) { require(value < 2**255, "SafeCast: value doesn't fit in an int256"); return int256(value); } }
// 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.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.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.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 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: 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 Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over `owner`'s tokens, * given `owner`'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for `permit`, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT 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: MIT pragma solidity ^0.7.0; import "../math/SafeMath.sol"; /** * @title Counters * @author Matt Condon (@shrugs) * @dev Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number * of elements in a mapping, issuing ERC721 ids, or counting request ids. * * Include with `using Counters for Counters.Counter;` * Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the {SafeMath} * overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never * directly accessed. */ library Counters { using SafeMath for uint256; struct Counter { // This variable should never be directly accessed by users of the library: interactions must be restricted to // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add // this feature: see https://github.com/ethereum/solidity/issues/4637 uint256 _value; // default: 0 } function current(Counter storage counter) internal view returns (uint256) { return counter._value; } function increment(Counter storage counter) internal { // The {SafeMath} overflow check can be skipped here, see the comment at the top counter._value += 1; } function decrement(Counter storage counter) internal { counter._value = counter._value.sub(1); } }
// 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.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: 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; } }
{ "metadata": { "bytecodeHash": "none" }, "optimizer": { "enabled": true, "runs": 10 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_pool","type":"address"},{"internalType":"address","name":"_unipilotFactory","type":"address"},{"internalType":"address","name":"_WETH","type":"address"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"}],"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":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"CompoundFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"depositor","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lpShares","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"isReadjustLiquidity","type":"bool"},{"indexed":false,"internalType":"uint256","name":"fees0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fees1","type":"uint256"}],"name":"FeesSnapshot","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"reserves0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"reserves1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fees0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fees1","type":"uint256"}],"name":"PullLiquidity","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":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"Withdraw","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","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":"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":[{"internalType":"uint256","name":"amount0Desired","type":"uint256"},{"internalType":"uint256","name":"amount1Desired","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"lpShares","type":"uint256"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getPositionDetails","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"fees0","type":"uint256"},{"internalType":"uint256","name":"fees1","type":"uint256"},{"internalType":"uint128","name":"baseLiquidity","type":"uint128"},{"internalType":"uint128","name":"rangeLiquidity","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getVaultInfo","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint24","name":"","type":"uint24"},{"internalType":"address","name":"","type":"address"}],"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":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"readjustLiquidity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ticksData","outputs":[{"internalType":"int24","name":"baseTickLower","type":"int24"},{"internalType":"int24","name":"baseTickUpper","type":"int24"},{"internalType":"int24","name":"rangeTickLower","type":"int24"},{"internalType":"int24","name":"rangeTickUpper","type":"int24"}],"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":"uint256","name":"amount0Owed","type":"uint256"},{"internalType":"uint256","name":"amount1Owed","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"uniswapV3MintCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0","type":"int256"},{"internalType":"int256","name":"amount1","type":"int256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"uniswapV3SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"bool","name":"refundAsETH","type":"bool"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Deployed Bytecode
0x6080604052600436106101085760003560e01c8062ebf5dd1461011157806306fdde0314610148578063095ea7b31461016a57806318160ddd1461019757806323b872dd146101b9578063313ce567146101d95780633644e515146101fb578063395093511461021057806370a08231146102305780637ecebe00146102505780637f98aa71146102705780638dbdbe6d1461029557806395d89b41146102b7578063a457c2d7146102cc578063a9059cbb146102ec578063ac2dc5621461030c578063c869623214610331578063d348799714610358578063d505accf14610378578063dd62ed3e14610398578063fa021656146103b8578063fa461e33146103cd5761010f565b3661010f57005b005b34801561011d57600080fd5b5061013161012c366004613e18565b6103ed565b60405161013f929190613f87565b60405180910390f35b34801561015457600080fd5b5061015d61071f565b60405161013f9190613f34565b34801561017657600080fd5b5061018a610185366004613cda565b6107b6565b60405161013f9190613ee3565b3480156101a357600080fd5b506101ac6107d4565b60405161013f9190613f06565b3480156101c557600080fd5b5061018a6101d4366004613c2a565b6107da565b3480156101e557600080fd5b506101ee610862565b60405161013f9190613fdf565b34801561020757600080fd5b506101ac61086b565b34801561021c57600080fd5b5061018a61022b366004613cda565b61087a565b34801561023c57600080fd5b506101ac61024b366004613b62565b6108c8565b34801561025c57600080fd5b506101ac61026b366004613b62565b6108e7565b34801561027c57600080fd5b50610285610908565b60405161013f9493929190613e9a565b6102a86102a3366004613e59565b61097f565b60405161013f93929190613f95565b3480156102c357600080fd5b5061015d610bda565b3480156102d857600080fd5b5061018a6102e7366004613cda565b610c3b565b3480156102f857600080fd5b5061018a610307366004613cda565b610ca3565b34801561031857600080fd5b50610321610cb7565b60405161013f9493929190613f0f565b34801561033d57600080fd5b50610346610ce0565b60405161013f96959493929190613fab565b34801561036457600080fd5b5061010f610373366004613db0565b610d6b565b34801561038457600080fd5b5061010f610393366004613c6a565b610df0565b3480156103a457600080fd5b506101ac6103b3366004613b7e565b610fa7565b3480156103c457600080fd5b5061010f610fd2565b3480156103d957600080fd5b5061010f6103e8366004613db0565b6111f4565b600080600860149054906101000a90046001600160601b03166001600160601b031660011461041b57600080fd5b600880546001600160a01b0316600160a11b179055600061043a61128e565b505060085460405163051bb83360e01b81529294506001600160a01b03808616945063051bb833936104729350911690600401613e86565b60006040518083038186803b15801561048a57600080fd5b505afa15801561049e573d6000803e3d6000fd5b50505050600086116104af57600080fd5b60006104cb87670de0b6b3a76400006104c66107d4565b611338565b60075490915060009081906104ef90600281810b9163010000009004900b856113e7565b6007549193509150600090819061051c90600160301b8104600290810b91600160481b9004900b876113e7565b909250905061052b8483611441565b97506105378382611441565b965060006105596105508a61054a611451565b906114f0565b8d6104c66107d4565b9050600061057561056c8a61054a611500565b8e6104c66107d4565b90506105818a83611441565b995061058d8982611441565b985089156105c1576105c18b8d7f000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca8d61154f565b88156105f3576105f38b8d7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28c61154f565b60075461062e90600281810b9163010000009004900b610611611451565b610619611500565b6008546001600160a01b0316939291906115b2565b600754919750955061065890600160301b8104600290810b91600160481b9004900b610611611451565b9094509250610667338e611714565b8b6001600160a01b03167f02f25270a4d87bea75db541cdfe559334a275b4a233520ed6c0a2429667cca948e8c8c6040516106a493929190613f95565b60405180910390a27f2fb985eb745b9e89bb1ab82e0f8ceb6bf94d4d60aed7e8196540c50161a5fe916106d78786611441565b6106e18786611441565b6040516106ef929190613f87565b60405180910390a15050600880546001600160a01b0316600160a01b179055509599949850939650505050505050565b60038054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107ab5780601f10610780576101008083540402835291602001916107ab565b820191906000526020600020905b81548152906001019060200180831161078e57829003601f168201915b505050505090505b90565b60006107ca6107c36117fe565b8484611802565b5060015b92915050565b60025490565b60006107e78484846118ee565b610857846107f36117fe565b6108528560405180606001604052806028815260200161411b602891396001600160a01b038a166000908152600160205260408120906108316117fe565b6001600160a01b031681526020810191909152604001600020549190611a37565b611802565b5060015b9392505050565b60055460ff1690565b6000610875611ace565b905090565b60006107ca6108876117fe565b8461085285600160006108986117fe565b6001600160a01b03908116825260208083019390935260409182016000908120918c168152925290205490611b98565b6001600160a01b0381166000908152602081905260409020545b919050565b6001600160a01b03811660009081526006602052604081206107ce90611bf0565b6008547f000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca917f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2917f0000000000000000000000000000000000000000000000000000000000000bb8916001600160a01b0390911690565b6000806000600860149054906101000a90046001600160601b03166001600160601b03166001146109af57600080fd5b600880546001600160a01b0316600160a11b17905585158015906109d35750600085115b6109dc57600080fd5b60006109e66117fe565b905060006109f26107d4565b9050610a7560008989610a03611451565b610a0b611500565b60408051608081018252600754600281810b810b810b835263010000008204810b810b810b6020840152600160301b8204810b810b810b93830193909352600160481b9004820b820b90910b60608201526008546001600160a01b03169594939291908890611bf4565b91965094509250610aa87f000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca833087611c90565b610ad47f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2833086611c90565b80610aea57610ae38484611e18565b5050610b56565b6007546008546000918291610b1b916001600160a01b0390911690600281810b9163010000009004900b89896115b2565b6007549193509150610b5190600160301b8104600290810b91600160481b9004900b610b4789866114f0565b61061989866114f0565b505050505b610b5e6120aa565b610b6886866120bc565b856001600160a01b0316826001600160a01b03167f4e2ca0515ed1aef1395f66b5303bb5d6f1bf9d61a353fa53f73f8ac9973fa9f6868689604051610baf93929190613f95565b60405180910390a35050600880546001600160a01b0316600160a01b17905591959094509092509050565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107ab5780601f10610780576101008083540402835291602001916107ab565b60006107ca610c486117fe565b84610852856040518060600160405280602581526020016141cd6025913960016000610c726117fe565b6001600160a01b03908116825260208083019390935260409182016000908120918d16815292529020549190611a37565b60006107ca610cb06117fe565b84846118ee565b600754600281810b9163010000008104820b91600160301b8204810b91600160481b9004900b84565b60408051608081018252600754600281810b810b810b835263010000008204810b810b810b6020840152600160301b8204810b810b810b93830193909352600160481b9004820b820b90910b606082015260085460009182918291829182918291610d58916001600160a01b0390911690839061219a565b949b939a50919850965094509092509050565b610d73612231565b336000610d8283850185613b62565b90508515610db657610db67f000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca828489611c90565b8415610de857610de87f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2828488611c90565b505050505050565b83421115610e45576040805162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e65000000604482015290519081900360640190fd5b6001600160a01b03871660009081526006602052604081207f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c990899089908990610e8e90611bf0565b8960405160200180878152602001866001600160a01b03168152602001856001600160a01b0316815260200184815260200183815260200182815260200196505050505050506040516020818303038152906040528051906020012090506000610ef782612248565b90506000610f0782878787612294565b9050896001600160a01b0316816001600160a01b031614610f6f576040805162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e61747572650000604482015290519081900360640190fd5b6001600160a01b038a166000908152600660205260409020610f9090612403565b610f9b8a8a8a611802565b50505050505050505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b600854600160a01b90046001600160601b0316600114610ff157600080fd5b600880546001600160a01b0316600160a11b179055600061101061128e565b505060085460405163051bb83360e01b81529294506001600160a01b03808616945063051bb833936110489350911690600401613e86565b60006040518083038186803b15801561106057600080fd5b505afa158015611074573d6000803e3d6000fd5b505060075460085460009350839250829182916110ac916001600160a01b0390911690600281810b9163010000009004900b3061240c565b60075460085494985092965090945092506000918291829182916110f0916001600160a01b031690600160301b8104600290810b91600160481b9004900b3061240c565b9296509094509250905061111860016111098885611441565b6111138885611441565b6125c0565b60006111248986611441565b905060006111328986611441565b905081158061113f575080155b156111b2576000808311611154576000611157565b60015b9050600061116361128e565b9450505050506000826111845761117f848360ff166064611338565b611193565b611193858360ff166064611338565b6008549091506111ae906001600160a01b0316308584612690565b5050505b6111ba611451565b91506111c4611500565b90506111d08282611e18565b5050600880546001600160a01b0316600160a01b1790555050505050505050505050565b6111fc612231565b600084138061120b5750600083135b61121457600080fd5b600061122282840184613d05565b9050801561125b576112567f000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca303388611c90565b611287565b6112877f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2303387611c90565b5050505050565b60008060008060007f00000000000000000000000006c2ae330c57a6320b2de720971ebd09003c7a016001600160a01b03166338d772806040518163ffffffff1660e01b815260040160a06040518083038186803b1580156112ef57600080fd5b505afa158015611303573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113279190613bb6565b945094509450945094509091929394565b600080806000198587098686029250828110908390030390508061136e576000841161136357600080fd5b50829004905061085b565b80841161137a57600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6008546000908190611405906001600160a01b03168686863061280c565b60085491935091506000908190611427906001600160a01b03163089896129d9565b91509150611437600083836125c0565b5050935093915050565b808201828110156107ce57600080fd5b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca16906370a08231906114a0903090600401613e86565b60206040518083038186803b1580156114b857600080fd5b505afa1580156114cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108759190613e00565b808203828111156107ce57600080fd5b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216906370a08231906114a0903090600401613e86565b83801561158d57507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316826001600160a01b0316145b156115a15761159c8184612aa0565b6115ac565b6115ac828483612b2c565b50505050565b600080806115cc6001600160a01b03891686868a8a612c73565b90506001600160801b03811615611709576040805130602080830182905283518084038201815283850194859052633c8a7d8d60e01b9094526044830182815260028c810b60648601528b900b60848501526001600160801b03861660a485015260a060c48501908152855160e486015285516001600160a01b038f1696633c8a7d8d968f958f958b959394909392610104019185019080838360005b83811015611681578181015183820152602001611669565b50505050905090810190601f1680156116ae5780820380516001836020036101000a031916815260200191505b5096505050505050506040805180830381600087803b1580156116d057600080fd5b505af11580156116e4573d6000803e3d6000fd5b505050506040513d60408110156116fa57600080fd5b50805160209091015190935091505b509550959350505050565b6001600160a01b0382166117595760405162461bcd60e51b81526004018080602001828103825260218152602001806141636021913960400191505060405180910390fd5b61176582600083612d05565b6117a281604051806060016040528060228152602001614046602291396001600160a01b0385166000908152602081905260409020549190611a37565b6001600160a01b0383166000908152602081905260409020556002546117c89082612d0a565b6002556040805182815290516000916001600160a01b038516916000805160206141438339815191529181900360200190a35050565b3390565b6001600160a01b0383166118475760405162461bcd60e51b81526004018080602001828103825260248152602001806141a96024913960400191505060405180910390fd5b6001600160a01b03821661188c5760405162461bcd60e51b81526004018080602001828103825260228152602001806140686022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166119335760405162461bcd60e51b81526004018080602001828103825260258152602001806141846025913960400191505060405180910390fd5b6001600160a01b0382166119785760405162461bcd60e51b81526004018080602001828103825260238152602001806140236023913960400191505060405180910390fd5b611983838383612d05565b6119c08160405180606001604052806026815260200161408a602691396001600160a01b0386166000908152602081905260409020549190611a37565b6001600160a01b0380851660009081526020819052604080822093909355908416815220546119ef9082611b98565b6001600160a01b0380841660008181526020818152604091829020949094558051858152905191939287169260008051602061414383398151915292918290030190a3505050565b60008184841115611ac65760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611a8b578181015183820152602001611a73565b50505050905090810190601f168015611ab85780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b60007f0000000000000000000000000000000000000000000000000000000000000001611af9612d67565b1415611b2657507fc312d2c0fab2e8642ade3288751f3e795d946c199d0f4862cfe0a5a2b83daaf96107b3565b611b917f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7fac496a38f672083c5fe3f70ce63b58b836c8923462162865a6880f741b1117db7fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6612d6b565b90506107b3565b60008282018381101561085b576040805162461bcd60e51b815260206004820152601b60248201527a536166654d6174683a206164646974696f6e206f766572666c6f7760281b604482015290519081900360640190fd5b5490565b6000806000806000806000611c0a8f8f8a61219a565b505093509350935093506000611c338c611c2d858861144190919063ffffffff16565b90611441565b90506000611c458c611c2d8786611441565b90508a1580611c5357508115155b80611c5d57508015155b611c6357fe5b611c708f8f84848f612dcd565b809950819a50829b50505050505050505050985098509895505050505050565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316846001600160a01b0316148015611cd15750804710155b15611df0577f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b158015611d3157600080fd5b505af1158015611d45573d6000803e3d6000fd5b505060405163a9059cbb60e01b81526001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216935063a9059cbb9250611d98915085908590600401613eca565b602060405180830381600087803b158015611db257600080fd5b505af1158015611dc6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dea9190613d21565b506115ac565b6001600160a01b038316301415611e0c5761159c848383612b2c565b6115ac84848484612e61565b600080611e23613ad5565b600854611e38906001600160a01b0316612fb1565b600290810b810b60a088015290810b810b608087015290810b810b606086015290810b810b604085015290810b810b6020840181905291810b900b808352600854611e91926001600160a01b03909116919088886115b2565b825160078054602086015162ffffff19909116600293840b62ffffff9081169190911765ffffff000000191663010000009290940b160291909117905590935091506000611edf86856114f0565b90506000611eed86856114f0565b9050600080831180611eff5750600082115b156120385760408401516060850151600854600092611f2d926001600160a01b039092169187918791612c73565b608086015160a0870151600854929350600092611f59926001600160a01b039091169188918891612c73565b9050816001600160801b0316816001600160801b03161015611fcb576040860151600780546060890151600290810b62ffffff908116600160481b0262ffffff60481b199590920b16600160301b0262ffffff60301b1990921691909117929092169190911790559091508190612035565b806001600160801b0316826001600160801b031610156120355760808601516007805460a0890151600290810b62ffffff908116600160481b0262ffffff60481b199590920b16600160301b0262ffffff60301b1990921691909117929092169190911790559150815b50505b6001600160801b0381161561209f57600754600854600091829161207f916001600160a01b0390911690600160301b8104600290810b91600160481b9004900b88886115b2565b909250905061208e8883611441565b975061209a8782611441565b965050505b505050509250929050565b47156120ba576120ba334761305e565b565b6001600160a01b038216612117576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b61212360008383612d05565b6002546121309082611b98565b6002556001600160a01b0382166000908152602081905260409020546121569082611b98565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391926000805160206141438339815191529281900390910190a35050565b6000806000806000806121b6898860000151896020015161314d565b939950919750955093509150876122255760008060008060006121e28e8d604001518e6060015161314d565b9398509196509450925090506121f88b86611441565b9a506122048a85611441565b99506122108984611441565b985061221c8883611441565b97509450505050505b93975093979195509350565b6008546001600160a01b031633146120ba57600080fd5b6000612252611ace565b82604051602001808061190160f01b81525060020183815260200182815260200192505050604051602081830303815290604052805190602001209050919050565b60006fa2a8918ca85bafe22016d0b997e4df60600160ff1b038211156122eb5760405162461bcd60e51b81526004018080602001828103825260228152602001806140d76022913960400191505060405180910390fd5b8360ff16601b148061230057508360ff16601c145b61233b5760405162461bcd60e51b81526004018080602001828103825260228152602001806140f96022913960400191505060405180910390fd5b600060018686868660405160008152602001604052604051808581526020018460ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa158015612397573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166123fa576040805162461bcd60e51b815260206004820152601860248201527745434453413a20696e76616c6964207369676e617475726560401b604482015290519081900360640190fd5b95945050505050565b80546001019055565b6000808080806124266001600160a01b038a168989613192565b50909150506001600160801b038116156125b4576040805163a34123a760e01b815260028a810b600483015289900b60248201526001600160801b038316604482015281516001600160a01b038c169263a34123a792606480820193918290030181600087803b15801561249957600080fd5b505af11580156124ad573d6000803e3d6000fd5b505050506040513d60408110156124c357600080fd5b5080516020909101519095509350841515806124df5750600084115b156125b457604080516309e3d67b60e31b81526001600160a01b03888116600483015260028b810b60248401528a900b60448301526001600160801b0360648301819052608483015282516000938493928e1692634f1eb3d89260a4808301939282900301818787803b15801561255557600080fd5b505af1158015612569573d6000803e3d6000fd5b505050506040513d604081101561257f57600080fd5b5080516020909101516001600160801b0391821693501690506125a282886114f0565b6125ac82886114f0565b909550935050505b50945094509450949050565b6000806125cb61128e565b509350935050506000841115612614576126147f000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca8361260f878560ff166064611338565b612b2c565b821561264e5761264e7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28361260f868560ff166064611338565b7ff8994d9c768d599c5c6e92d52cd9cc24762cd773384c7a4612796773c56a86a685858560405161268193929190613eee565b60405180910390a15050505050565b60006126a4856001600160a01b0316613230565b505090506000620f42408261c350026001600160a01b0316816126c357fe5b0490506000846126d5578183016126d9565b8183035b9050866001600160a01b031663128acb08878787858a6040516020018082151581526020019150506040516020818303038152906040526040518663ffffffff1660e01b815260040180866001600160a01b031681526020018515158152602001848152602001836001600160a01b0316815260200180602001828103825283818151815260200191508051906020019080838360005b83811015612788578181015183820152602001612770565b50505050905090810190601f1680156127b55780820380516001836020036101000a031916815260200191505b5096505050505050506040805180830381600087803b1580156127d757600080fd5b505af11580156127eb573d6000803e3d6000fd5b505050506040513d604081101561280157600080fd5b505050505050505050565b600080806128246001600160a01b0389168888613192565b505090506000612846826001600160801b031687670de0b6b3a7640000611338565b9050886001600160a01b031663a34123a78989612862856132b2565b6040518463ffffffff1660e01b8152600401808460020b81526020018360020b8152602001826001600160801b0316815260200193505050506040805180830381600087803b1580156128b457600080fd5b505af11580156128c8573d6000803e3d6000fd5b505050506040513d60408110156128de57600080fd5b5080516020909101519094509250831515806128fa5750600083115b156129cd57886001600160a01b0316634f1eb3d8868a8a61291a896132b2565b612923896132b2565b6040518663ffffffff1660e01b815260040180866001600160a01b031681526020018560020b81526020018460020b8152602001836001600160801b03168152602001826001600160801b03168152602001955050505050506040805180830381600087803b15801561299557600080fd5b505af11580156129a9573d6000803e3d6000fd5b505050506040513d60408110156129bf57600080fd5b50516001600160801b031693505b50509550959350505050565b6000806129e78685856132fa565b50604080516309e3d67b60e31b81526001600160a01b038781166004830152600287810b602484015286900b60448301526001600160801b03606483018190526084830152825190891692634f1eb3d89260a480820193918290030181600087803b158015612a5557600080fd5b505af1158015612a69573d6000803e3d6000fd5b505050506040513d6040811015612a7f57600080fd5b5080516020909101516001600160801b039182169891169650945050505050565b604051632e1a7d4d60e01b81526001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc21690632e1a7d4d90612aec908590600401613f06565b600060405180830381600087803b158015612b0657600080fd5b505af1158015612b1a573d6000803e3d6000fd5b50505050612b28818361305e565b5050565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b1781529251825160009485949389169392918291908083835b60208310612ba85780518252601f199092019160209182019101612b89565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612c0a576040519150601f19603f3d011682016040523d82523d6000602084013e612c0f565b606091505b5091509150818015612c3d575080511580612c3d5750808060200190516020811015612c3a57600080fd5b50515b611287576040805162461bcd60e51b815260206004820152600260248201526114d560f21b604482015290519081900360640190fd5b600080866001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b158015612caf57600080fd5b505afa158015612cc3573d6000803e3d6000fd5b505050506040513d60e0811015612cd957600080fd5b50519050612cfa81612cea866133b3565b612cf3866133b3565b89896136da565b979650505050505050565b505050565b600082821115612d61576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b4690565b6000838383612d78612d67565b3060405160200180868152602001858152602001848152602001838152602001826001600160a01b03168152602001955050505050506040516020818303038152906040528051906020012090509392505050565b6000808083612df1575086905085808211612de85780612dea565b815b9250612e56565b85612e03575085612dea818587611338565b84612e1657879150612dea828588611338565b612e21878787611338565b915087821015612e38575085612dea818587611338565b879150612e46828688611338565b9050612e53828588611338565b92505b955095509592505050565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b178152925182516000948594938a169392918291908083835b60208310612ee55780518252601f199092019160209182019101612ec6565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612f47576040519150601f19603f3d011682016040523d82523d6000602084013e612f4c565b606091505b5091509150818015612f7a575080511580612f7a5750808060200190516020811015612f7757600080fd5b50515b610de8576040805162461bcd60e51b815260206004820152600360248201526229aa2360e91b604482015290519081900360640190fd5b6000806000806000806000612fc461128e565b505060405163802036f560e01b8152919350506001600160a01b038316915063802036f590612ff7908b90600401613e86565b60c060405180830381600087803b15801561301157600080fd5b505af1158015613025573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130499190613d3d565b949d939c50919a509850965090945092505050565b604080516000808252602082019092526001600160a01b0384169083906040518082805190602001908083835b602083106130aa5780518252601f19909201916020918201910161308b565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d806000811461310c576040519150601f19603f3d011682016040523d82523d6000602084013e613111565b606091505b5050905080612d05576040805162461bcd60e51b815260206004820152600360248201526253544560e81b604482015290519081900360640190fd5b60008060008060006131608888886132fa565b90506001600160801b038116156131875761317c88888861379c565b929750909550935091505b939792965093509350565b6000806000806131a33087876137e8565b9050866001600160a01b031663514ea4bf826040518263ffffffff1660e01b81526004018082815260200191505060a06040518083038186803b1580156131e957600080fd5b505afa1580156131fd573d6000803e3d6000fd5b505050506040513d60a081101561321357600080fd5b508051606082015160809092015190999198509650945050505050565b6000806000836001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b15801561326e57600080fd5b505afa158015613282573d6000803e3d6000fd5b505050506040513d60e081101561329857600080fd5b508051602082015160609092015190969195509350915050565b6000600160801b82106132f65760405162461bcd60e51b81526004018080602001828103825260278152602001806140b06027913960400191505060405180910390fd5b5090565b60006133106001600160a01b0385168484613192565b50909150506001600160801b0381161561085b57836001600160a01b031663a34123a7848460006040518463ffffffff1660e01b8152600401808460020b81526020018360020b815260200182815260200193505050506040805180830381600087803b15801561338057600080fd5b505af1158015613394573d6000803e3d6000fd5b505050506040513d60408110156133aa57600080fd5b50509392505050565b60008060008360020b126133ca578260020b6133d2565b8260020b6000035b9050620d89e8811115613410576040805162461bcd60e51b81526020600482015260016024820152601560fa1b604482015290519081900360640190fd5b60006001821661342457600160801b613436565b6ffffcb933bd6fad37aa2d162d1a5940015b6001600160881b031690506002821615613460576ffff97272373d413259a46990580e213a0260801c5b600482161561347f576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b600882161561349e576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b60108216156134bd576fffcb9843d60f6159c9db58835c9266440260801c5b60208216156134dc576fff973b41fa98c081472e6896dfb254c00260801c5b60408216156134fb576fff2ea16466c96a3843ec78b326b528610260801c5b608082161561351a576ffe5dee046a99a2a811c461f1969c30530260801c5b61010082161561353a576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b61020082161561355a576ff987a7253ac413176f2b074cf7815e540260801c5b61040082161561357a576ff3392b0822b70005940c7a398e4b70f30260801c5b61080082161561359a576fe7159475a2c29b7443b29c7fa6e889d90260801c5b6110008216156135ba576fd097f3bdfd2022b8845ad8f792aa58250260801c5b6120008216156135da576fa9f746462d870fdf8a65dc1f90e061e50260801c5b6140008216156135fa576f70d869a156d2a1b890bb3df62baf32f70260801c5b61800082161561361a576f31be135f97d08fd981231505542fcfa60260801c5b6201000082161561363b576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b6202000082161561365b576e5d6af8dedb81196699c329225ee6040260801c5b6204000082161561367a576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615613697576b048a170391f7dc42444e8fa20260801c5b60008460020b13156136b25780600019816136ae57fe5b0490505b600160201b8106156136c55760016136c8565b60005b60ff16602082901c0192505050919050565b6000836001600160a01b0316856001600160a01b031611156136fa579293925b846001600160a01b0316866001600160a01b0316116137255761371e858585613839565b90506123fa565b836001600160a01b0316866001600160a01b0316101561378757600061374c878686613839565b9050600061375b87898661389c565b9050806001600160801b0316826001600160801b03161061377c578061377e565b815b925050506123fa565b61379285858461389c565b9695505050505050565b60008060008060008060006137b28a8a8a613192565b9250925092506000806137c78c868d8d6138e1565b9099509750506001600160801b039283169550501691505093509350935093565b6040805160609490941b6001600160601b031916602080860191909152600293840b60e890811b60348701529290930b90911b60378401528051808403601a018152603a9093019052815191012090565b6000826001600160a01b0316846001600160a01b03161115613859579192915b600061387c856001600160a01b0316856001600160a01b0316600160601b611338565b90506123fa61389784838888036001600160a01b0316611338565b613978565b6000826001600160a01b0316846001600160a01b031611156138bc579192915b6138d961389783600160601b8787036001600160a01b0316611338565b949350505050565b6000806000866001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e06040518083038186803b15801561391f57600080fd5b505afa158015613933573d6000803e3d6000fd5b505050506040513d60e081101561394957600080fd5b505190506139698161395a876133b3565b613963876133b3565b8961398e565b92509250505b94509492505050565b806001600160801b03811681146108e257600080fd5b600080836001600160a01b0316856001600160a01b031611156139af579293925b846001600160a01b0316866001600160a01b0316116139da576139d3858585613a29565b915061396f565b836001600160a01b0316866001600160a01b03161015613a13576139ff868585613a29565b9150613a0c858785613a92565b905061396f565b613a1e858585613a92565b905094509492505050565b6000826001600160a01b0316846001600160a01b03161115613a49579192915b836001600160a01b0316613a82606060ff16846001600160801b0316901b8686036001600160a01b0316866001600160a01b0316611338565b81613a8957fe5b04949350505050565b6000826001600160a01b0316846001600160a01b03161115613ab2579192915b6138d9826001600160801b03168585036001600160a01b0316600160601b611338565b6040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a081019190915290565b60008083601f840112613b1b578182fd5b5081356001600160401b03811115613b31578182fd5b602083019150836020828501011115613b4957600080fd5b9250929050565b8051600281900b81146108e257600080fd5b600060208284031215613b73578081fd5b813561085b81613fed565b60008060408385031215613b90578081fd5b8235613b9b81613fed565b91506020830135613bab81613fed565b809150509250929050565b600080600080600060a08688031215613bcd578081fd5b8551613bd881613fed565b6020870151909550613be981613fed565b6040870151909450613bfa81613fed565b6060870151909350613c0b81614013565b6080870151909250613c1c81614013565b809150509295509295909350565b600080600060608486031215613c3e578283fd5b8335613c4981613fed565b92506020840135613c5981613fed565b929592945050506040919091013590565b600080600080600080600060e0888a031215613c84578182fd5b8735613c8f81613fed565b96506020880135613c9f81613fed565b955060408801359450606088013593506080880135613cbd81614013565b9699959850939692959460a0840135945060c09093013592915050565b60008060408385031215613cec578182fd5b8235613cf781613fed565b946020939093013593505050565b600060208284031215613d16578081fd5b813561085b81614005565b600060208284031215613d32578081fd5b815161085b81614005565b60008060008060008060c08789031215613d55578182fd5b613d5e87613b50565b9550613d6c60208801613b50565b9450613d7a60408801613b50565b9350613d8860608801613b50565b9250613d9660808801613b50565b9150613da460a08801613b50565b90509295509295509295565b60008060008060608587031215613dc5578182fd5b843593506020850135925060408501356001600160401b03811115613de8578283fd5b613df487828801613b0a565b95989497509550505050565b600060208284031215613e11578081fd5b5051919050565b600080600060608486031215613e2c578081fd5b833592506020840135613e3e81613fed565b91506040840135613e4e81614005565b809150509250925092565b600080600060608486031215613e6d578081fd5b83359250602084013591506040840135613e4e81613fed565b6001600160a01b0391909116815260200190565b6001600160a01b039485168152928416602084015262ffffff919091166040830152909116606082015260800190565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b92151583526020830191909152604082015260600190565b90815260200190565b600294850b815292840b602084015290830b604083015290910b606082015260800190565b6000602080835283518082850152825b81811015613f6057858101830151858201604001528201613f44565b81811115613f715783604083870101525b50601f01601f1916929092016040019392505050565b918252602082015260400190565b9283526020830191909152604082015260600190565b9586526020860194909452604085019290925260608401526001600160801b0390811660808401521660a082015260c00190565b60ff91909116815260200190565b6001600160a01b038116811461400257600080fd5b50565b801515811461400257600080fd5b60ff8116811461400257600080fdfe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636553616665436173743a2076616c756520646f65736e27742066697420696e20313238206269747345434453413a20696e76616c6964207369676e6174757265202773272076616c756545434453413a20696e76616c6964207369676e6174757265202776272076616c756545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef45524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa164736f6c6343000706000a
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 26 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|---|---|---|---|---|
ETH | 100.00% | $10.28 | 4.3841 | $45.07 |
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.