v1 source realm
package v1 implements GnoSwap's concentrated liquidity pools based on Uniswap V3. It manages liquidity positions, exe...
package v1 implements GnoSwap's concentrated liquidity pools based on Uniswap V3. It manages liquidity positions, executes swaps, and maintains pool state including price, liquidity, and fee calculations.
The pool contract is the core of the GnoSwap AMM, supporting: - Concentrated liquidity within custom price ranges - Multiple fee tiers (0.01%, 0.05%, 0.3%, 1%) - Single-tick and cross-tick swaps - Protocol fee collection - Tick bitmap optimization for gas efficiency
6
const MIN_SQRT_RATIO, MAX_SQRT_RATIO
const MaxBpsValue, ZeroBps
const MAX_LIQUIDITY_PER_TICK_SPACING_1, MAX_LIQUIDITY_PER_TICK_SPACING_10, MAX_LIQUIDITY_PER_TICK_SPACING_60, MAX_LIQUIDITY_PER_TICK_SPACING_200, MIN_TICK, MAX_TICK
1const (
2 MAX_LIQUIDITY_PER_TICK_SPACING_1 = "191757530477355301479181766273477"
3 MAX_LIQUIDITY_PER_TICK_SPACING_10 = "1917569901783203986719870431555990"
4 MAX_LIQUIDITY_PER_TICK_SPACING_60 = "11505743598341114571880798222544994"
5 MAX_LIQUIDITY_PER_TICK_SPACING_200 = "38350317471085141830651933667504588"
6 MIN_TICK int32 = -887272
7 MAX_TICK int32 = 887272
8)const MAX_UINT64, MAX_INT64, MAX_INT128, MAX_UINT128, MAX_INT256, INT64_MIN, INT64_MAX, Q96_RESOLUTION, Q128_RESOLUTION, Q64, Q96, Q128
1const (
2 MAX_UINT64 string = "18446744073709551615"
3 MAX_INT64 string = "9223372036854775807"
4 MAX_INT128 string = "170141183460469231731687303715884105727"
5 MAX_UINT128 string = "340282366920938463463374607431768211455"
6 MAX_INT256 string = "57896044618658097711785492504343953926634992332820282019728792003956564819967"
7
8 INT64_MIN int64 = -9223372036854775808
9 INT64_MAX int64 = 9223372036854775807
10
11 Q96_RESOLUTION uint = 96
12 Q128_RESOLUTION uint = 128
13
14 Q64 string = "18446744073709551616" // 2 ** 64
15 Q96 string = "79228162514264337593543950336" // 2 ** 96
16 Q128 string = "340282366920938463463374607431768211456" // 2 ** 128
17)const GNS_TOKEN_KEY
17
func GetPoolPath
ActionGetPoolPath generates a unique pool path string based on the token paths and fee tier.
func GetPositionByPool
ActionGetPosition returns the position info for a given key.
func GetTickCumulativeOutside
ActionGetTickCumulativeOutside returns the cumulative liquidity outside the tick.
func GetTickFeeGrowthOutside0X128
ActionGetTickFeeGrowthOutside0X128 returns the fee growth outside the tick for token 0.
func GetTickFeeGrowthOutside1X128
ActionGetTickFeeGrowthOutside1X128 returns the fee growth outside the tick for token 1.
func GetTickInitialized
ActionGetTickInitialized returns whether the tick is initialized.
func GetTickLiquidityGross
ActionGetTickLiquidityGross returns the gross liquidity for the specified tick.
func GetTickLiquidityNet
ActionGetTickLiquidityNet returns the net liquidity for the specified tick.
func GetTickSecondsOutside
ActionGetTickSecondsOutside returns the seconds outside the tick.
func GetTickSecondsPerLiquidityOutsideX128
ActionGetTickSecondsPerLiquidityOutsideX128 returns the seconds per liquidity outside the tick.
func NewPoolV1
Actionfunc PositionFeeGrowthInside0LastX128
ActionPositionFeeGrowthInside0LastX128 returns the fee growth of token0 inside a position.
func PositionFeeGrowthInside1LastX128
ActionPositionFeeGrowthInside1LastX128 returns the fee growth of token1 inside a position.
func PositionLiquidity
ActionPositionLiquidity returns the liquidity of a position.
func PositionTokensOwed0
ActionPositionTokensOwed0 returns the amount of token0 owed by a position.
func PositionTokensOwed1
ActionPositionTokensOwed1 returns the amount of token1 owed by a position.
func NewTickEventInfo
Action6
type ModifyPositionParams
struct 1type ModifyPositionParams struct {
2 // owner is the address that owns the position
3 owner address
4
5 tickLower int32 // lower tick of the position
6 tickUpper int32 // upper tick of the position
7
8 // liquidityDelta represents the change in liquidity
9 // Positive for minting, negative for burning
10 liquidityDelta *i256.Int
11}ModifyPositionParams repersents the parameters for modifying a liquidity position. This structure is used internally both `Mint` and `Burn` operation to manage the liquidity positions.
type StepComputations
struct1type StepComputations struct {
2 sqrtPriceStartX96 *u256.Uint // price at the beginning of the step
3 tickNext int32 // next tick to swap to from the current tick in the swap direction
4 initialized bool // whether tickNext is initialized
5 sqrtPriceNextX96 *u256.Uint // sqrt(price) for the next tick (token1/token0) Q96
6 amountIn *u256.Uint // how much being swapped in this step
7 amountOut *u256.Uint // how much is being swapped out in this step
8 feeAmount *u256.Uint // how much fee is being paid in this step
9}StepComputations holds intermediate values used during a single step of a swap. Each step represents movement from the current tick to the next initialized tick or the target price, whichever comes first.
type SwapCache
struct1type SwapCache struct {
2 feeProtocol uint8 // protocol fee for the input token
3 liquidityStart *u256.Uint // liquidity at the beginning of the swap
4 blockTimestamp int64 // current block timestamp
5 tickCumulative int64 // current tick accumulator value
6 secondsPerLiquidityCumulativeX128 *u256.Uint // current seconds per liquidity accumulator
7 computedLatestObservation bool // whether we've computed the above accumulators
8}SwapCache holds data that remains constant throughout a swap.
type SwapComputation
structSwapComputation encapsulates the pure computation logic for swaps.
type SwapResult
structSwapResult encapsulates all state changes from a swap. It ensures atomic state transitions that can be applied at once.
type SwapState
struct1type SwapState struct {
2 amountSpecifiedRemaining *i256.Int // amount remaining to be swapped in/out of the input/output token
3 amountCalculated *i256.Int // amount already swapped out/in of the output/input token
4 sqrtPriceX96 *u256.Uint // current sqrt(price)
5 tick int32 // tick associated with the current sqrt(price)
6 feeGrowthGlobalX128 *u256.Uint // global fee growth of the input token
7 protocolFee *u256.Uint // amount of input token paid as protocol fee
8 liquidity *u256.Uint // current liquidity in range
9}SwapState tracks the changing values during a swap. This type helps manage the state transitions that occur as the swap progresses across different price ranges.
20
- chain stdlib
- errors stdlib
- gno.land/p/gnoswap/consts package
- gno.land/p/gnoswap/gnsmath package
- gno.land/p/gnoswap/int256 package
- gno.land/p/gnoswap/rbac package
- gno.land/p/gnoswap/uint256 package
- gno.land/p/gnoswap/utils package
- gno.land/p/nt/ufmt/v0 package
- gno.land/r/gnoswap/access realm
- gno.land/r/gnoswap/common realm
- gno.land/r/gnoswap/emission realm
- gno.land/r/gnoswap/gns realm
- gno.land/r/gnoswap/halt realm
- gno.land/r/gnoswap/pool realm
- gno.land/r/gnoswap/protocol_fee realm
- gno.land/r/gnoswap/rbac realm
- strconv stdlib
- strings stdlib
- time stdlib