Skip to content

Commit

Permalink
Fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
zZoMROT committed Feb 3, 2025
1 parent fa5a935 commit 1e51db0
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions contracts/UniV4Helper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ pragma solidity 0.8.23;

import "@uniswap/v3-core/contracts/libraries/BitMath.sol";

interface IHooks {}

interface IPosManager {
type Currency is address;
struct PoolKey {
Currency currency0;
Currency currency1;
address currency0;
address currency1;
uint24 fee;
int24 tickSpacing;
IHooks hooks;
Expand All @@ -35,31 +32,31 @@ interface IPoolManager {
}

contract UniV4Helper {
uint256 private constant TICKS_OFFSET = 4;
bytes32 private constant POOLS_SLOT = bytes32(uint256(6));
uint256 private constant _TICKS_OFFSET = 4;
bytes32 private constant _POOLS_SLOT = bytes32(uint256(6));

int24 private constant _MIN_TICK = -887272;
int24 private constant _MAX_TICK = -_MIN_TICK;

IPoolManager private immutable poolManager;
IStateView private immutable stateView;
IPosManager private immutable posManager;
IPoolManager private immutable _POOL_MANAGER;
IStateView private immutable _STATE_VIEW;
IPosManager private immutable _POS_MANAGER;

constructor(IPoolManager _poolManager, IStateView _stateView, IPosManager _posManager) {
poolManager = _poolManager;
stateView = _stateView;
posManager = _posManager;
_POOL_MANAGER = _poolManager;
_STATE_VIEW = _stateView;
_POS_MANAGER = _posManager;
}

function _getTickInfoSlot(IStateView.PoolId poolId, int24 tick) internal pure returns (bytes32) {
bytes32 stateSlot = keccak256(abi.encodePacked(IStateView.PoolId.unwrap(poolId), POOLS_SLOT));
bytes32 ticksMappingSlot = bytes32(uint256(stateSlot) + TICKS_OFFSET);
bytes32 stateSlot = keccak256(abi.encodePacked(IStateView.PoolId.unwrap(poolId), _POOLS_SLOT));
bytes32 ticksMappingSlot = bytes32(uint256(stateSlot) + _TICKS_OFFSET);
return keccak256(abi.encodePacked(int256(tick), ticksMappingSlot));
}

function getTicks(IStateView.PoolId poolId, int24 tickRange) external view returns (bytes[] memory ticks) {
int24 tickSpacing = posManager.poolKeys(bytes25(IStateView.PoolId.unwrap(poolId))).tickSpacing;
(,int24 tick,,) = stateView.getSlot0(poolId);
int24 tickSpacing = _POS_MANAGER.poolKeys(bytes25(IStateView.PoolId.unwrap(poolId))).tickSpacing;
(,int24 tick,,) = _STATE_VIEW.getSlot0(poolId);

tickRange *= tickSpacing;
int24 fromTick = tick - tickRange;
Expand All @@ -78,7 +75,7 @@ contract UniV4Helper {
int16 endPos = int16((toTick / tickSpacing) >> 8);

for (; pos <= endPos; pos++) {
uint256 bm = stateView.getTickBitmap(poolId, pos);
uint256 bm = _STATE_VIEW.getTickBitmap(poolId, pos);

while (bm != 0) {
uint8 bit = BitMath.leastSignificantBit(bm);
Expand All @@ -93,7 +90,7 @@ contract UniV4Helper {
ticks = new bytes[](counter);
for (uint256 i = 0; i < counter; i++) {
bytes32 slot = _getTickInfoSlot(poolId, initTicks[i]);
bytes32[] memory data = poolManager.extsload(slot, 3);
bytes32[] memory data = _POOL_MANAGER.extsload(slot, 3);
ticks[i] = abi.encodePacked(data[0], data[1], data[2], initTicks[i]);
}
return(ticks);
Expand Down

0 comments on commit 1e51db0

Please sign in to comment.