Skip to content

Instantly share code, notes, and snippets.

@gigamesh
Created June 9, 2024 20:45
Show Gist options
  • Save gigamesh/a3913588ff950b940756491a8dfadd72 to your computer and use it in GitHub Desktop.
Save gigamesh/a3913588ff950b940756491a8dfadd72 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.2;
import {INonfungiblePositionManager} from "./interfaces/INonfungiblePositionManager.sol";
import {TickMath} from "./libraries/TickMath.sol";
import {LiquidityAmounts} from "./libraries/LiquidityAmounts.sol";
import {console} from "forge-std/Test.sol";
contract UniswapLiqAmounts {
function getTokenAmount(uint256 id) external view returns (uint256) {
INonfungiblePositionManager positionManager = INonfungiblePositionManager(
0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1
);
int24 tickLower;
int24 tickUpper;
uint128 liquidity;
(, , , , , tickLower, tickUpper, liquidity, , , , ) = positionManager
.positions(id);
uint160 sqrtRatioAX96 = TickMath.getSqrtPriceAtTick(tickLower);
uint160 sqrtRatioBX96 = TickMath.getSqrtPriceAtTick(tickUpper);
return
LiquidityAmounts.getAmount1ForLiquidity(
sqrtRatioAX96,
sqrtRatioBX96,
liquidity
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment