Search Apps Documentation Source Content File Folder Download Copy Actions Download

types.gno

7.68 Kb ยท 272 lines
  1package pool
  2
  3import (
  4	u256 "gno.land/p/gnoswap/uint256"
  5	"gno.land/p/nt/avl"
  6)
  7
  8// IPool interface defines all public methods that must be implemented by pool contract versions.
  9// This interface serves as the contract between the proxy layer and implementation versions,
 10// ensuring that all versions (v1, v2, v3, etc.) maintain the same public API.
 11//
 12// This design enables seamless upgrades while maintaining backwards compatibility.
 13// When upgrading from v1 to v2, the proxy simply switches the implementation pointer
 14// without changing the public interface, ensuring zero downtime and no breaking changes.
 15type IPool interface {
 16	IPoolManager
 17	IPoolPosition
 18	IPoolSwap
 19	IPoolGetter
 20}
 21
 22// IPoolManager interface defines pool management operations.
 23// These methods handle pool creation and fee configuration.
 24type IPoolManager interface {
 25	// CreatePool creates a new concentrated liquidity pool.
 26	CreatePool(
 27		token0Path string,
 28		token1Path string,
 29		fee uint32,
 30		sqrtPriceX96 string,
 31	)
 32
 33	// SetPoolCreationFee sets the pool creation fee.
 34	SetPoolCreationFee(fee int64)
 35
 36	IncreaseObservationCardinalityNext(
 37		token0Path string,
 38		token1Path string,
 39		fee uint32,
 40		cardinalityNext uint16,
 41	)
 42}
 43
 44// IPoolPosition interface defines position management operations.
 45// These methods handle liquidity provision and position management.
 46type IPoolPosition interface {
 47	// Mint adds liquidity to a pool position.
 48	Mint(
 49		token0Path string,
 50		token1Path string,
 51		fee uint32,
 52		tickLower int32,
 53		tickUpper int32,
 54		liquidityAmount string,
 55		positionCaller address,
 56	) (string, string)
 57
 58	// Burn removes liquidity from a position.
 59	Burn(
 60		token0Path string,
 61		token1Path string,
 62		fee uint32,
 63		tickLower int32,
 64		tickUpper int32,
 65		liquidityAmount string,
 66		positionCaller address,
 67	) (string, string)
 68
 69	// Collect transfers owed tokens from a position to recipient.
 70	Collect(
 71		token0Path string,
 72		token1Path string,
 73		fee uint32,
 74		recipient address,
 75		tickLower int32,
 76		tickUpper int32,
 77		amount0Requested string,
 78		amount1Requested string,
 79	) (string, string)
 80
 81	SetWithdrawalFee(fee uint64)
 82
 83	HandleWithdrawalFee(
 84		positionId uint64,
 85		token0Path string,
 86		amount0 string,
 87		token1Path string,
 88		amount1 string,
 89		poolPath string,
 90		positionCaller address,
 91	) (string, string)
 92}
 93
 94// IPoolSwap interface defines swap and protocol fee operations.
 95// These methods handle token swaps and protocol fee management.
 96type IPoolSwap interface {
 97	Swap(
 98		token0Path string,
 99		token1Path string,
100		fee uint32,
101		recipient address,
102		zeroForOne bool,
103		amountSpecified string,
104		sqrtPriceLimitX96 string,
105		payer address,
106		swapCallback func(cur realm, amount0Delta, amount1Delta int64, callbackMarker *CallbackMarker) error,
107	) (string, string)
108
109	DrySwap(
110		token0Path string,
111		token1Path string,
112		fee uint32,
113		zeroForOne bool,
114		amountSpecified string,
115		sqrtPriceLimitX96 string,
116	) (string, string, bool)
117
118	SetSwapEndHook(hook func(cur realm, poolPath string) error)
119
120	SetSwapStartHook(hook func(cur realm, poolPath string, timestamp int64))
121
122	SetTickCrossHook(hook func(cur realm, poolPath string, tickId int32, zeroForOne bool, timestamp int64))
123
124	CollectProtocol(
125		token0Path string,
126		token1Path string,
127		fee uint32,
128		recipient address,
129		amount0Requested string,
130		amount1Requested string,
131	) (string, string)
132
133	SetFeeProtocol(feeProtocol0, feeProtocol1 uint8)
134}
135
136// IPoolGetter interface defines data retrieval operations.
137// These methods provide read-only access to pool state and data.
138type IPoolGetter interface {
139	ExistsPoolPath(poolPath string) bool
140
141	GetBalanceToken0(poolPath string) string
142
143	GetBalanceToken1(poolPath string) string
144
145	GetFee(poolPath string) uint32
146
147	GetFeeAmountTickSpacing(fee uint32) (spacing int32)
148
149	GetFeeGrowthGlobal0X128(poolPath string) string
150
151	GetFeeGrowthGlobal1X128(poolPath string) string
152
153	GetFeeGrowthGlobalX128(poolPath string) (*u256.Uint, *u256.Uint)
154
155	GetLiquidity(poolPath string) string
156
157	GetMaxLiquidityPerTick(poolPath string) string
158
159	GetObservation(poolPath string, secondsAgo int64) (tickCumulative int64, liquidityCumulative, secondsPerLiquidityCumulativeX128 string, blockTimestamp int64)
160
161	GetPoolCreationFee() int64
162
163	GetPositionFeeGrowthInside0LastX128(poolPath, key string) string
164
165	GetPositionFeeGrowthInside1LastX128(poolPath, key string) string
166
167	GetPositionFeeGrowthInsideLastX128(poolPath, key string) (*u256.Uint, *u256.Uint)
168
169	GetPositionLiquidity(poolPath, key string) *u256.Uint
170
171	GetPositionTokensOwed0(poolPath, key string) string
172
173	GetPositionTokensOwed1(poolPath, key string) string
174
175	GetProtocolFeesToken0(poolPath string) string
176
177	GetProtocolFeesToken1(poolPath string) string
178
179	GetSlot0FeeProtocol(poolPath string) uint8
180
181	GetSlot0SqrtPriceX96(poolPath string) *u256.Uint
182
183	GetSlot0Tick(poolPath string) int32
184
185	GetSlot0Unlocked(poolPath string) bool
186
187	GetTickCumulativeOutside(poolPath string, tick int32) int64
188
189	GetTickFeeGrowthOutside0X128(poolPath string, tick int32) string
190
191	GetTickFeeGrowthOutside1X128(poolPath string, tick int32) string
192
193	GetTickFeeGrowthOutsideX128(poolPath string, tick int32) (*u256.Uint, *u256.Uint)
194
195	GetTickInitialized(poolPath string, tick int32) bool
196
197	GetTickLiquidityGross(poolPath string, tick int32) string
198
199	GetTickLiquidityNet(poolPath string, tick int32) string
200
201	GetTickSecondsOutside(poolPath string, tick int32) uint32
202
203	GetTickSecondsPerLiquidityOutsideX128(poolPath string, tick int32) string
204
205	GetTickSpacing(poolPath string) int32
206
207	GetToken0Path(poolPath string) string
208
209	GetToken1Path(poolPath string) string
210
211	GetWithdrawalFee() uint64
212
213	GetTWAP(poolPath string, secondsAgo uint32) (int32, *u256.Uint, error)
214
215	GetPoolCount() int
216	GetPoolPaths(offset, count int) []string
217	GetFeeAmountTickSpacings() map[uint32]int32
218
219	GetPoolPositionCount(poolPath string) int
220	GetPoolPositionKeys(poolPath string, offset, count int) []string
221
222	GetInitializedTicksInRange(poolPath string, tickLower, tickUpper int32) []int32
223
224	// Structure getters
225	GetPool(token0Path, token1Path string, fee uint32) (*Pool, error)
226	GetTickInfo(poolPath string, tick int32) (TickInfo, error)
227	GetTickBitmaps(poolPath string, wordPos int16) (*u256.Uint, error)
228	GetPosition(poolPath, key string) (PositionInfo, error)
229	GetObservationState(poolPath string) (*ObservationState, error)
230}
231
232// IPoolStore interface defines the storage abstraction for pool data.
233// This interface provides a clean separation between business logic and storage,
234// allowing different implementations to use the same storage interface.
235//
236// All pool implementations (v1, v2, etc.) use this interface to access
237// and modify pool state, ensuring data consistency across versions.
238type IPoolStore interface {
239	HasPools() bool
240	GetPools() *avl.Tree
241	SetPools(pools *avl.Tree) error
242
243	HasFeeAmountTickSpacing() bool
244	GetFeeAmountTickSpacing() map[uint32]int32
245	SetFeeAmountTickSpacing(feeAmountTickSpacing map[uint32]int32) error
246
247	HasSlot0FeeProtocol() bool
248	GetSlot0FeeProtocol() uint8
249	SetSlot0FeeProtocol(slot0FeeProtocol uint8) error
250
251	HasPoolCreationFee() bool
252	GetPoolCreationFee() int64
253	SetPoolCreationFee(poolCreationFee int64) error
254
255	HasWithdrawalFeeBPS() bool
256	GetWithdrawalFeeBPS() uint64
257	SetWithdrawalFeeBPS(withdrawalFeeBPS uint64) error
258
259	HasSwapStartHook() bool
260	GetSwapStartHook() func(cur realm, poolPath string, timestamp int64)
261	SetSwapStartHook(swapStartHook func(cur realm, poolPath string, timestamp int64)) error
262
263	HasSwapEndHook() bool
264	GetSwapEndHook() func(cur realm, poolPath string) error
265	SetSwapEndHook(swapEndHook func(cur realm, poolPath string) error) error
266
267	HasTickCrossHook() bool
268	GetTickCrossHook() func(cur realm, poolPath string, tickId int32, zeroForOne bool, timestamp int64)
269	SetTickCrossHook(tickCrossHook func(cur realm, poolPath string, tickId int32, zeroForOne bool, timestamp int64)) error
270}
271
272type CallbackMarker struct{}