Calc.sol 1.2 KB

1234567891011121314151617181920212223242526272829
  1. pragma solidity ^0.7.6;
  2. import '@uniswap/v3-periphery/contracts/libraries/OracleLibrary.sol';
  3. import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol';
  4. import 'hardhat/console.sol';
  5. contract Calc {
  6. IUniswapV3Factory factory = IUniswapV3Factory(0x1F98431c8aD98523631AE4a59f267346ea31F984);
  7. function getQuote(address tokenA, uint amountA, address tokenB, uint24 fee) public view returns (uint256 amountB) {
  8. (int24 tick,) = OracleLibrary.consult(factory.getPool(tokenA, tokenB, fee), 60);
  9. return OracleLibrary.getQuoteAtTick(tick, uint128(amountA), tokenA, tokenB);
  10. }
  11. function getQuoteHandleFee(address tokenA, uint amountA, address tokenB, uint24 fee) public view returns (uint256 amountB) {
  12. (int24 tick,) = OracleLibrary.consult(factory.getPool(tokenA, tokenB, fee), 60);
  13. return OracleLibrary.getQuoteAtTick(tick, uint128(amountA) * (1_000_000 - fee) / 1_000_000, tokenA, tokenB);
  14. }
  15. function calc1(uint num1, uint24 fee) public pure returns (uint256 rst1) {
  16. return num1 * (1_000_000 - fee);
  17. }
  18. function calc2(uint num2, uint24 fee) public pure returns (uint256 rst2) {
  19. return num2 * (1_000_000 - fee) / 1_000_000;
  20. }
  21. }