//SPDX-License-Identifier: Unlicense

pragma solidity ^0.7.6;

import '@uniswap/v3-periphery/contracts/libraries/OracleLibrary.sol';
import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol';
import 'hardhat/console.sol';

contract Calc {
    IUniswapV3Factory factory = IUniswapV3Factory(0x1F98431c8aD98523631AE4a59f267346ea31F984);

    function getQuote(address tokenA, uint amountA, address tokenB, uint24 fee) public view returns (uint256 amountB) {
        (int24 tick,) = OracleLibrary.consult(factory.getPool(tokenA, tokenB, fee), 60);
        return OracleLibrary.getQuoteAtTick(tick, uint128(amountA), tokenA, tokenB);
    }

    function getQuoteHandleFee(address tokenA, uint amountA, address tokenB, uint24 fee) public view returns (uint256 amountB) {
        (int24 tick,) = OracleLibrary.consult(factory.getPool(tokenA, tokenB, fee), 60);
        return OracleLibrary.getQuoteAtTick(tick, uint128(amountA) * (1_000_000 - fee) / 1_000_000, tokenA, tokenB);
    }

    function calc1(uint num1, uint24 fee) public pure returns (uint256 rst1) {
        return num1 * (1_000_000 - fee);
    }

    function calc2(uint num2, uint24 fee) public pure returns (uint256 rst2) {
        return num2 * (1_000_000 - fee) / 1_000_000;
    }
}
