Search Apps Documentation Source Content File Folder Download Copy Actions Download

getter.gno

11.87 Kb ยท 314 lines
  1package pool
  2
  3import (
  4	u256 "gno.land/p/gnoswap/uint256"
  5)
  6
  7// GetPoolCount returns the total number of pools.
  8func GetPoolCount() int {
  9	return getImplementation().GetPoolCount()
 10}
 11
 12// GetPoolPaths returns a paginated list of pool paths.
 13func GetPoolPaths(offset, count int) []string {
 14	return getImplementation().GetPoolPaths(offset, count)
 15}
 16
 17// ExistsPoolPath checks if a pool exists at the given path.
 18func ExistsPoolPath(poolPath string) bool {
 19	return getImplementation().ExistsPoolPath(poolPath)
 20}
 21
 22// GetBalances returns the balances of the pool.
 23func GetBalances(poolPath string) (string, string) {
 24	return getImplementation().GetBalanceToken0(poolPath), getImplementation().GetBalanceToken1(poolPath)
 25}
 26
 27// GetBalanceToken0 returns the balance of token0 in the pool.
 28func GetBalanceToken0(poolPath string) string {
 29	return getImplementation().GetBalanceToken0(poolPath)
 30}
 31
 32// GetBalanceToken1 returns the balance of token1 in the pool.
 33func GetBalanceToken1(poolPath string) string {
 34	return getImplementation().GetBalanceToken1(poolPath)
 35}
 36
 37// GetFee returns the fee tier of the pool.
 38func GetFee(poolPath string) uint32 {
 39	return getImplementation().GetFee(poolPath)
 40}
 41
 42// GetFeeAmountTickSpacings returns all fee tier to tick spacing mappings.
 43func GetFeeAmountTickSpacings() map[uint32]int32 {
 44	return getImplementation().GetFeeAmountTickSpacings()
 45}
 46
 47// GetFeeAmountTickSpacing returns the tick spacing for a given fee tier.
 48func GetFeeAmountTickSpacing(fee uint32) (spacing int32) {
 49	return getImplementation().GetFeeAmountTickSpacing(fee)
 50}
 51
 52// GetFeeGrowthGlobal0X128 returns the global fee growth for token0.
 53func GetFeeGrowthGlobal0X128(poolPath string) string {
 54	return getImplementation().GetFeeGrowthGlobal0X128(poolPath)
 55}
 56
 57// GetFeeGrowthGlobal1X128 returns the global fee growth for token1.
 58func GetFeeGrowthGlobal1X128(poolPath string) string {
 59	return getImplementation().GetFeeGrowthGlobal1X128(poolPath)
 60}
 61
 62// GetFeeGrowthGlobalX128 returns the global fee growth for both tokens.
 63func GetFeeGrowthGlobalX128(poolPath string) (*u256.Uint, *u256.Uint) {
 64	feeGrowthGlobal0, feeGrowthGlobal1 := getImplementation().GetFeeGrowthGlobalX128(poolPath)
 65	return feeGrowthGlobal0.Clone(), feeGrowthGlobal1.Clone()
 66}
 67
 68// GetFeeGrowthGlobals returns the global fee growth for both tokens.
 69func GetFeeGrowthGlobals(poolPath string) (string, string) {
 70	feeGrowthGlobal0, feeGrowthGlobal1 := getImplementation().GetFeeGrowthGlobalX128(poolPath)
 71	return feeGrowthGlobal0.ToString(), feeGrowthGlobal1.ToString()
 72}
 73
 74// GetLiquidity returns the current liquidity in the pool.
 75func GetLiquidity(poolPath string) string {
 76	return getImplementation().GetLiquidity(poolPath)
 77}
 78
 79// GetMaxLiquidityPerTick returns the maximum liquidity per tick for the pool.
 80func GetMaxLiquidityPerTick(poolPath string) string {
 81	return getImplementation().GetMaxLiquidityPerTick(poolPath)
 82}
 83
 84// GetObservation returns observation data for calculating time-weighted averages.
 85func GetObservation(poolPath string, secondsAgo int64) (tickCumulative int64, liquidityCumulative, secondsPerLiquidityCumulativeX128 string, blockTimestamp int64) {
 86	return getImplementation().GetObservation(poolPath, secondsAgo)
 87}
 88
 89// GetPoolCreationFee returns the current pool creation fee.
 90func GetPoolCreationFee() int64 {
 91	return getImplementation().GetPoolCreationFee()
 92}
 93
 94// GetPositionFeeGrowthInside0LastX128 returns the last recorded fee growth inside for token0.
 95func GetPositionFeeGrowthInside0LastX128(poolPath, key string) string {
 96	return getImplementation().GetPositionFeeGrowthInside0LastX128(poolPath, key)
 97}
 98
 99// GetPositionFeeGrowthInside1LastX128 returns the last recorded fee growth inside for token1.
100func GetPositionFeeGrowthInside1LastX128(poolPath, key string) string {
101	return getImplementation().GetPositionFeeGrowthInside1LastX128(poolPath, key)
102}
103
104// GetPositionFeeGrowthInsideLastX128 returns the last recorded fee growth inside for both tokens.
105func GetPositionFeeGrowthInsideLastX128(poolPath, key string) (*u256.Uint, *u256.Uint) {
106	feeGrowthInside0, feeGrowthInside1 := getImplementation().GetPositionFeeGrowthInsideLastX128(poolPath, key)
107	return feeGrowthInside0.Clone(), feeGrowthInside1.Clone()
108}
109
110// GetPositionFeeGrowthInsideLasts returns the last recorded fee growth inside for both tokens.
111func GetPositionFeeGrowthInsideLasts(poolPath, key string) (string, string) {
112	feeGrowthInside0, feeGrowthInside1 := getImplementation().GetPositionFeeGrowthInsideLastX128(poolPath, key)
113	return feeGrowthInside0.ToString(), feeGrowthInside1.ToString()
114}
115
116// GetPoolPositionCount returns the number of positions in a pool.
117func GetPoolPositionCount(poolPath string) int {
118	return getImplementation().GetPoolPositionCount(poolPath)
119}
120
121// GetPoolPositionKeys returns a paginated list of position keys in a pool.
122func GetPoolPositionKeys(poolPath string, offset, count int) []string {
123	return getImplementation().GetPoolPositionKeys(poolPath, offset, count)
124}
125
126// GetPositionLiquidity returns the liquidity of a position.
127func GetPositionLiquidity(poolPath, key string) *u256.Uint {
128	return getImplementation().GetPositionLiquidity(poolPath, key)
129}
130
131// GetPositionTokensOwed0 returns the amount of token0 owed to a position.
132func GetPositionTokensOwed0(poolPath, key string) string {
133	return getImplementation().GetPositionTokensOwed0(poolPath, key)
134}
135
136// GetPositionTokensOwed1 returns the amount of token1 owed to a position.
137func GetPositionTokensOwed1(poolPath, key string) string {
138	return getImplementation().GetPositionTokensOwed1(poolPath, key)
139}
140
141// GetPositionTokensOwedInfos returns the amount of tokens owed for both tokens.
142func GetPositionTokensOwed(poolPath, key string) (string, string) {
143	return getImplementation().GetPositionTokensOwed0(poolPath, key), getImplementation().GetPositionTokensOwed1(poolPath, key)
144}
145
146// GetProtocolFeesToken0 returns accumulated protocol fees for token0.
147func GetProtocolFeesToken0(poolPath string) string {
148	return getImplementation().GetProtocolFeesToken0(poolPath)
149}
150
151// GetProtocolFeesToken1 returns accumulated protocol fees for token1.
152func GetProtocolFeesToken1(poolPath string) string {
153	return getImplementation().GetProtocolFeesToken1(poolPath)
154}
155
156// GetProtocolFeesTokens returns the accumulated protocol fees for both tokens.
157func GetProtocolFeesTokens(poolPath string) (string, string) {
158	return getImplementation().GetProtocolFeesToken0(poolPath), getImplementation().GetProtocolFeesToken1(poolPath)
159}
160
161// GetSlot0FeeProtocol returns the protocol fee rate from slot0.
162func GetSlot0FeeProtocol(poolPath string) uint8 {
163	return getImplementation().GetSlot0FeeProtocol(poolPath)
164}
165
166// GetSlot0SqrtPriceX96 returns the current sqrt price from slot0.
167func GetSlot0SqrtPriceX96(poolPath string) *u256.Uint {
168	return getImplementation().GetSlot0SqrtPriceX96(poolPath)
169}
170
171// GetSlot0Tick returns the current tick from slot0.
172func GetSlot0Tick(poolPath string) int32 {
173	return getImplementation().GetSlot0Tick(poolPath)
174}
175
176// GetSlot0Unlocked returns the locked status from slot0.
177func GetSlot0Unlocked(poolPath string) bool {
178	return getImplementation().GetSlot0Unlocked(poolPath)
179}
180
181// GetTickCumulativeOutside returns the tick cumulative value outside a tick.
182func GetTickCumulativeOutside(poolPath string, tick int32) int64 {
183	return getImplementation().GetTickCumulativeOutside(poolPath, tick)
184}
185
186// GetTickFeeGrowthOutside0X128 returns fee growth outside for token0 at a tick.
187func GetTickFeeGrowthOutside0X128(poolPath string, tick int32) string {
188	return getImplementation().GetTickFeeGrowthOutside0X128(poolPath, tick)
189}
190
191// GetTickFeeGrowthOutside1X128 returns fee growth outside for token1 at a tick.
192func GetTickFeeGrowthOutside1X128(poolPath string, tick int32) string {
193	return getImplementation().GetTickFeeGrowthOutside1X128(poolPath, tick)
194}
195
196// GetTickFeeGrowthOutsideX128 returns fee growth outside for both tokens at a tick.
197func GetTickFeeGrowthOutsideX128(poolPath string, tick int32) (*u256.Uint, *u256.Uint) {
198	feeGrowthOutside0, feeGrowthOutside1 := getImplementation().GetTickFeeGrowthOutsideX128(poolPath, tick)
199	return feeGrowthOutside0.Clone(), feeGrowthOutside1.Clone()
200}
201
202// GetTickFeeGrowthOutsides returns fee growth outside for both tokens at a tick.
203func GetTickFeeGrowthOutsides(poolPath string, tick int32) (string, string) {
204	feeGrowthOutside0, feeGrowthOutside1 := getImplementation().GetTickFeeGrowthOutsideX128(poolPath, tick)
205	return feeGrowthOutside0.ToString(), feeGrowthOutside1.ToString()
206}
207
208// GetTickInitialized returns whether a tick is initialized.
209func GetTickInitialized(poolPath string, tick int32) bool {
210	return getImplementation().GetTickInitialized(poolPath, tick)
211}
212
213// GetInitializedTicksInRange returns initialized ticks within the given range.
214func GetInitializedTicksInRange(poolPath string, tickLower, tickUpper int32) []int32 {
215	return getImplementation().GetInitializedTicksInRange(poolPath, tickLower, tickUpper)
216}
217
218// GetTickLiquidityGross returns the total liquidity that references a tick.
219func GetTickLiquidityGross(poolPath string, tick int32) string {
220	return getImplementation().GetTickLiquidityGross(poolPath, tick)
221}
222
223// GetTickLiquidityNet returns the net liquidity change at a tick.
224func GetTickLiquidityNet(poolPath string, tick int32) string {
225	return getImplementation().GetTickLiquidityNet(poolPath, tick)
226}
227
228// GetTickSecondsOutside returns seconds spent outside a tick.
229func GetTickSecondsOutside(poolPath string, tick int32) uint32 {
230	return getImplementation().GetTickSecondsOutside(poolPath, tick)
231}
232
233// GetTickSecondsPerLiquidityOutsideX128 returns seconds per liquidity outside a tick.
234func GetTickSecondsPerLiquidityOutsideX128(poolPath string, tick int32) string {
235	return getImplementation().GetTickSecondsPerLiquidityOutsideX128(poolPath, tick)
236}
237
238// GetTickSpacing returns the tick spacing of the pool.
239func GetTickSpacing(poolPath string) int32 {
240	return getImplementation().GetTickSpacing(poolPath)
241}
242
243// GetToken0Path returns the path of token0 in the pool.
244func GetToken0Path(poolPath string) string {
245	return getImplementation().GetToken0Path(poolPath)
246}
247
248// GetToken1Path returns the path of token1 in the pool.
249func GetToken1Path(poolPath string) string {
250	return getImplementation().GetToken1Path(poolPath)
251}
252
253// GetWithdrawalFee returns the current withdrawal fee rate.
254func GetWithdrawalFee() uint64 {
255	return getImplementation().GetWithdrawalFee()
256}
257
258// GetTWAP returns the time-weighted average price for a pool.
259// Returns arithmetic mean tick and harmonic mean liquidity over the time period.
260func GetTWAP(poolPath string, secondsAgo uint32) (int32, *u256.Uint, error) {
261	return getImplementation().GetTWAP(poolPath, secondsAgo)
262}
263
264// Structure getters
265
266// GetPool returns a copy of the pool for the given token pair and fee tier.
267func GetPool(token0Path, token1Path string, fee uint32) (*Pool, error) {
268	pool, err := getImplementation().GetPool(token0Path, token1Path, fee)
269	if err != nil {
270		return nil, err
271	}
272
273	return pool.Clone(), nil
274}
275
276// GetTickInfo returns the tick info for a given tick.
277func GetTickInfo(poolPath string, tick int32) (TickInfo, error) {
278	tickInfo, err := getImplementation().GetTickInfo(poolPath, tick)
279	if err != nil {
280		return TickInfo{}, err
281	}
282
283	return cloneTickInfo(tickInfo), nil
284}
285
286// GetTickBitmaps returns the tick bitmap for a given word position.
287func GetTickBitmaps(poolPath string, wordPos int16) (*u256.Uint, error) {
288	tickBitmap, err := getImplementation().GetTickBitmaps(poolPath, wordPos)
289	if err != nil {
290		return nil, err
291	}
292
293	return tickBitmap.Clone(), nil
294}
295
296// GetPosition returns the position info for a given key.
297func GetPosition(poolPath, key string) (PositionInfo, error) {
298	positionInfo, err := getImplementation().GetPosition(poolPath, key)
299	if err != nil {
300		return PositionInfo{}, err
301	}
302
303	return clonePositionInfo(positionInfo), nil
304}
305
306// GetObservationState returns the observation state for a given pool path.
307func GetObservationState(poolPath string) (*ObservationState, error) {
308	observationState, err := getImplementation().GetObservationState(poolPath)
309	if err != nil {
310		return nil, err
311	}
312
313	return observationState.Clone(), nil
314}