getter.gno
9.13 Kb · 264 lines
1package position
2
3import (
4 rotree "gno.land/p/nt/bptree/rotree/v0"
5)
6
7// GetPositions returns a read-only view of all positions.
8//
9// Returns:
10// - positions: read-only tree keyed by decimal position ID; callers paginate with IterateByOffset
11func GetPositions() *rotree.ReadOnlyTree {
12 return getImplementation().GetPositions()
13}
14
15// IsBurned reports whether the position's empty-position marker is set.
16//
17// Parameters:
18// - positionId: position NFT token ID
19//
20// Returns:
21// - burned: whether the position's empty-position marker is set
22// - err: non-nil when positionId cannot be resolved
23func IsBurned(positionId uint64) (bool, error) {
24 return getImplementation().IsBurned(positionId)
25}
26
27// IsInRange reports whether a position's ticks contain the current pool tick.
28//
29// Parameters:
30// - positionId: position NFT token ID
31//
32// Returns:
33// - inRange: whether the position is currently in range
34// - err: non-nil when positionId cannot be resolved or the associated pool tick cannot be read
35func IsInRange(positionId uint64) (bool, error) {
36 return getImplementation().IsInRange(positionId)
37}
38
39// GetPositionTokenBalances calculates the current token0/token1 balances for
40// a position from its liquidity, tick range, and pool price.
41//
42// These are derived balances, not permanently stored token amounts.
43//
44// Parameters:
45// - positionId: position NFT token ID
46//
47// Returns:
48// - balance0: current token0 balance
49// - balance1: current token1 balance
50// - err: non-nil when positionId cannot be resolved
51func GetPositionTokenBalances(positionId uint64) (int64, int64, error) {
52 return getImplementation().GetPositionTokenBalances(positionId)
53}
54
55// GetPositionToken0Balance returns the token0 balance associated with a position.
56//
57// Parameters:
58// - positionId: position NFT token ID
59//
60// Returns:
61// - balance: token0 balance
62// - err: non-nil when positionId cannot be resolved
63func GetPositionToken0Balance(positionId uint64) (int64, error) {
64 balance0, _, err := GetPositionTokenBalances(positionId)
65 if err != nil {
66 return 0, err
67 }
68
69 return balance0, nil
70}
71
72// GetPositionToken1Balance returns the token1 balance associated with a position.
73//
74// Parameters:
75// - positionId: position NFT token ID
76//
77// Returns:
78// - balance: token1 balance
79// - err: non-nil when positionId cannot be resolved
80func GetPositionToken1Balance(positionId uint64) (int64, error) {
81 _, balance1, err := GetPositionTokenBalances(positionId)
82 if err != nil {
83 return 0, err
84 }
85
86 return balance1, nil
87}
88
89// GetPositionFeeGrowthInside0LastX128 returns the last fee-growth checkpoint inside the position's range for token0.
90//
91// Parameters:
92// - positionId: position NFT token ID whose token0 fee-growth checkpoint is queried
93//
94// Returns:
95// - feeGrowthInside0LastX128: token0 fee-growth checkpoint, represented as a decimal string
96// - err: non-nil when positionId cannot be resolved
97func GetPositionFeeGrowthInside0LastX128(positionId uint64) (string, error) {
98 return getImplementation().GetPositionFeeGrowthInside0LastX128(positionId)
99}
100
101// GetPositionFeeGrowthInside1LastX128 returns the last fee-growth checkpoint inside the position's range for token1.
102//
103// Parameters:
104// - positionId: position NFT token ID whose token1 fee-growth checkpoint is queried
105//
106// Returns:
107// - feeGrowthInside1LastX128: token1 fee-growth checkpoint, represented as a decimal string
108// - err: non-nil when positionId cannot be resolved
109func GetPositionFeeGrowthInside1LastX128(positionId uint64) (string, error) {
110 return getImplementation().GetPositionFeeGrowthInside1LastX128(positionId)
111}
112
113// GetPositionFeeGrowthInsideLastX128 returns the last fee-growth checkpoints inside the position's range for both tokens.
114//
115// Parameters:
116// - positionId: position NFT token ID whose fee-growth checkpoints are queried
117//
118// Returns:
119// - feeGrowthInside0LastX128: token0 fee-growth checkpoint, represented as a decimal string
120// - feeGrowthInside1LastX128: token1 fee-growth checkpoint, represented as a decimal string
121// - err: non-nil when positionId cannot be resolved
122func GetPositionFeeGrowthInsideLastX128(positionId uint64) (string, string, error) {
123 return getImplementation().GetPositionFeeGrowthInsideLastX128(positionId)
124}
125
126// GetPositionLiquidity returns the stored liquidity amount of a position.
127//
128// Parameters:
129// - positionId: position NFT token ID whose liquidity is queried
130//
131// Returns:
132// - liquidity: position liquidity, represented as a decimal string
133// - err: non-nil when positionId cannot be resolved
134func GetPositionLiquidity(positionId uint64) (string, error) {
135 return getImplementation().GetPositionLiquidity(positionId)
136}
137
138// GetPositionOperator returns the approved operator address for a position.
139//
140// Parameters:
141// - positionId: position NFT token ID whose operator is queried
142//
143// Returns:
144// - operator: approved operator address; the zero address means no operator is set
145// - err: non-nil when positionId cannot be resolved
146func GetPositionOperator(positionId uint64) (address, error) {
147 return getImplementation().GetPositionOperator(positionId)
148}
149
150// GetPositionPoolKey returns the pool key associated with a position.
151//
152// Parameters:
153// - positionId: position NFT token ID whose pool association is queried
154//
155// Returns:
156// - poolKey: canonical pool key used by the position
157// - err: non-nil when positionId cannot be resolved
158func GetPositionPoolKey(positionId uint64) (string, error) {
159 return getImplementation().GetPositionPoolKey(positionId)
160}
161
162// GetPositionTickLower returns the lower tick boundary of a position.
163//
164// Parameters:
165// - positionId: position NFT token ID whose lower tick is queried
166//
167// Returns:
168// - tickLower: lower tick boundary of the position's price range
169// - err: non-nil when positionId cannot be resolved
170func GetPositionTickLower(positionId uint64) (int32, error) {
171 return getImplementation().GetPositionTickLower(positionId)
172}
173
174// GetPositionTickUpper returns the upper tick boundary of a position.
175//
176// Parameters:
177// - positionId: position NFT token ID whose upper tick is queried
178//
179// Returns:
180// - tickUpper: upper tick boundary of the position's price range
181// - err: non-nil when positionId cannot be resolved
182func GetPositionTickUpper(positionId uint64) (int32, error) {
183 return getImplementation().GetPositionTickUpper(positionId)
184}
185
186// GetPositionTicks returns the lower and upper tick boundaries of a position.
187//
188// Parameters:
189// - positionId: position NFT token ID whose tick range is queried
190//
191// Returns:
192// - tickLower: lower tick boundary of the position's price range
193// - tickUpper: upper tick boundary of the position's price range
194// - err: non-nil when positionId cannot be resolved
195func GetPositionTicks(positionId uint64) (int32, int32, error) {
196 return getImplementation().GetPositionTicks(positionId)
197}
198
199// GetPositionTokensOwed0 returns the token0 amount accrued and owed to a position.
200//
201// Parameters:
202// - positionId: position NFT token ID whose token0 debt is queried
203//
204// Returns:
205// - tokensOwed0: token0 amount currently owed to the position
206// - err: non-nil when positionId cannot be resolved
207func GetPositionTokensOwed0(positionId uint64) (int64, error) {
208 return getImplementation().GetPositionTokensOwed0(positionId)
209}
210
211// GetPositionTokensOwed1 returns the token1 amount accrued and owed to a position.
212//
213// Parameters:
214// - positionId: position NFT token ID whose token1 debt is queried
215//
216// Returns:
217// - tokensOwed1: token1 amount currently owed to the position
218// - err: non-nil when positionId cannot be resolved
219func GetPositionTokensOwed1(positionId uint64) (int64, error) {
220 return getImplementation().GetPositionTokensOwed1(positionId)
221}
222
223// GetPositionTokensOwed returns the token0 and token1 amounts accrued and owed to a position.
224//
225// Parameters:
226// - positionId: position NFT token ID whose accrued token debt is queried
227//
228// Returns:
229// - tokensOwed0: token0 amount currently owed to the position
230// - tokensOwed1: token1 amount currently owed to the position
231// - err: non-nil when positionId cannot be resolved
232func GetPositionTokensOwed(positionId uint64) (int64, int64, error) {
233 return getImplementation().GetPositionTokensOwed(positionId)
234}
235
236// GetUnclaimedFee returns the unclaimed fees for both tokens of a position as decimal strings.
237//
238// Parameters:
239// - positionId: position NFT token ID whose unclaimed fees are queried
240//
241// Returns:
242// - fee0: unclaimed token0 fee amount, represented as a decimal string
243// - fee1: unclaimed token1 fee amount, represented as a decimal string
244// - err: non-nil when positionId or the associated pool fee-growth data cannot be resolved
245func GetUnclaimedFee(positionId uint64) (string, string, error) {
246 fee0, fee1, err := getImplementation().GetUnclaimedFee(positionId)
247 if err != nil {
248 return "", "", err
249 }
250
251 return fee0.ToString(), fee1.ToString(), nil
252}
253
254// GetPositionOwner returns the owner address of a position NFT.
255//
256// Parameters:
257// - positionId: position NFT token ID whose owner is queried
258//
259// Returns:
260// - owner: address that owns the position NFT
261// - err: non-nil when the NFT owner lookup fails
262func GetPositionOwner(positionId uint64) (address, error) {
263 return getImplementation().GetPositionOwner(positionId)
264}