Calc.sol 873 B

123456789101112131415161718192021222324
  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) * (100000 - fee) / 100000;
  10. }
  11. function calc1(uint num1, uint24 fee) public view returns (uint256 rst1) {
  12. return num1 * fee;
  13. }
  14. function calc2(uint num2, uint24 fee) public view returns (uint256 rst2) {
  15. return num2 * fee / 100000;
  16. }
  17. }