all files / contracts/test/ MockUniswapV3Pool.sol

96.55% Statements 28/29
81.25% Branches 13/16
91.67% Functions 11/12
96.55% Lines 28/29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112                                            454×                             338× 338×                                               33×     33×     33× 33× 33×       905× 903×   902× 902× 902×   902× 902×   902× 902× 902×             410× 409× 408× 407×                  
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
 
import "../vendor/TickMath.sol";
 
interface IUniswapV3PoolDeployer {
    function parameters() external view returns (
            address factory,
            address token0,
            address token1,
            uint24 fee,
            int24 tickSpacing
        );
}
 
contract MockUniswapV3Pool {
    address public immutable factory;
    address public immutable token0;
    address public immutable token1;
    uint24 public immutable fee;
 
    constructor() {
        (factory, token0, token1, fee,) = IUniswapV3PoolDeployer(msg.sender).parameters();
    }
 
 
 
 
 
    uint160 currSqrtPriceX96;
    int24 currTwap;
    bool throwOld;
    bool throwNotInitiated;
    bool throwOther;
    bool throwEmpty;
 
    function mockSetTwap(uint160 sqrtPriceX96) public {
        currSqrtPriceX96 = sqrtPriceX96;
        currTwap = TickMath.getTickAtSqrtRatio(sqrtPriceX96);
    }
 
    function initialize(uint160 sqrtPriceX96) external {
        mockSetTwap(sqrtPriceX96);
    }
 
    function mockSetThrowOld(bool val) external {
        throwOld = val;
    }
 
    function mockSetThrowNotInitiated(bool val) external {
        throwNotInitiated = val;
    }
 
    function mockSetThrowOther(bool val) external {
        throwOther = val;
    }
 
    function mockSetThrowEmpty(bool val) external {
        throwEmpty = val;
    }
 
 
    function observations(uint256) external pure returns (uint32, int56, uint160, bool) {
        return (0, 0, 0, true);
    }
 
    function slot0() external view returns (uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked) {
        sqrtPriceX96 = currSqrtPriceX96;
 
        // These fields are tested with the real uniswap core contracts:
        observationIndex = observationCardinality = observationCardinalityNext = 1;
 
        // Not used in Euler tests:
        tick = 0;
        feeProtocol = 0;
        unlocked = false;
    }
 
    function observe(uint32[] calldata secondsAgos) external view returns (int56[] memory tickCumulatives, uint160[] memory liquidityCumulatives) {
        require(!throwOld, "OLD");
        require (!throwOther, "OTHER");
 
        Erequire(secondsAgos.length == 2, "uniswap-pool-mock/unsupported-args-1");
        Erequire(secondsAgos[1] == 0, "uniswap-pool-mock/unsupported-args-2");
        Erequire(secondsAgos[0] > 0, "uniswap-pool-mock/unsupported-args-3");
 
        tickCumulatives = new int56[](2);
        liquidityCumulatives = new uint160[](2);
 
        tickCumulatives[0] = 0;
        tickCumulatives[1] = int56(currTwap) * int56(uint56(secondsAgos[0]));
        liquidityCumulatives[0] = liquidityCumulatives[1] = 0;
    }
 
 
 
    function increaseObservationCardinalityNext(uint16) external {
        // This function is tested with the real uniswap core contracts
        require (!throwNotInitiated, "LOK");
        require (!throwOther, "OTHER");
        require (!throwEmpty);
        throwNotInitiated = throwNotInitiated; // suppress visibility warning
    }
 
 
    uint128 public liquidity = 100;
 
    function mockSetLiquidity(uint128 newLiquidity) external {
        liquidity = newLiquidity;
    }
}