-
Notifications
You must be signed in to change notification settings - Fork 645
Expand file tree
/
Copy pathStateView.sol
More file actions
109 lines (95 loc) · 3.72 KB
/
StateView.sol
File metadata and controls
109 lines (95 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {StateLibrary} from "@uniswap/v4-core/src/libraries/StateLibrary.sol";
import {PoolId} from "@uniswap/v4-core/src/types/PoolId.sol";
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {Position} from "@uniswap/v4-core/src/libraries/Position.sol";
import {ImmutableState} from "../base/ImmutableState.sol";
import {IStateView} from "../interfaces/IStateView.sol";
/// @notice A view only contract wrapping the StateLibrary.sol library for reading storage in v4-core.
/// @dev The contract is intended for offchain clients. Use StateLibrary.sol directly if reading state onchain.
contract StateView is ImmutableState, IStateView {
using StateLibrary for IPoolManager;
constructor(IPoolManager _poolManager) ImmutableState(_poolManager) {}
/// @inheritdoc IStateView
function getSlot0(PoolId poolId)
external
view
returns (uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee)
{
return poolManager.getSlot0(poolId);
}
/// @inheritdoc IStateView
function getTickInfo(PoolId poolId, int24 tick)
external
view
returns (
uint128 liquidityGross,
int128 liquidityNet,
uint256 feeGrowthOutside0X128,
uint256 feeGrowthOutside1X128
)
{
return poolManager.getTickInfo(poolId, tick);
}
/// @inheritdoc IStateView
function getTickLiquidity(PoolId poolId, int24 tick)
external
view
returns (uint128 liquidityGross, int128 liquidityNet)
{
return poolManager.getTickLiquidity(poolId, tick);
}
/// @inheritdoc IStateView
function getTickFeeGrowthOutside(PoolId poolId, int24 tick)
external
view
returns (uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128)
{
return poolManager.getTickFeeGrowthOutside(poolId, tick);
}
/// @inheritdoc IStateView
function getFeeGrowthGlobals(PoolId poolId)
external
view
returns (uint256 feeGrowthGlobal0, uint256 feeGrowthGlobal1)
{
return poolManager.getFeeGrowthGlobals(poolId);
}
/// @inheritdoc IStateView
function getLiquidity(PoolId poolId) external view returns (uint128 liquidity) {
return poolManager.getLiquidity(poolId);
}
/// @inheritdoc IStateView
function getTickBitmap(PoolId poolId, int16 tick) external view returns (uint256 tickBitmap) {
return poolManager.getTickBitmap(poolId, tick);
}
/// @inheritdoc IStateView
function getPositionInfo(PoolId poolId, address owner, int24 tickLower, int24 tickUpper, bytes32 salt)
external
view
returns (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128)
{
return poolManager.getPositionInfo(poolId, owner, tickLower, tickUpper, salt);
}
/// @inheritdoc IStateView
function getPositionInfo(PoolId poolId, bytes32 positionId)
external
view
returns (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128)
{
return poolManager.getPositionInfo(poolId, positionId);
}
/// @inheritdoc IStateView
function getPositionLiquidity(PoolId poolId, bytes32 positionId) external view returns (uint128 liquidity) {
return poolManager.getPositionLiquidity(poolId, positionId);
}
/// @inheritdoc IStateView
function getFeeGrowthInside(PoolId poolId, int24 tickLower, int24 tickUpper)
external
view
returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128)
{
return poolManager.getFeeGrowthInside(poolId, tickLower, tickUpper);
}
}