assertIsNotUserCall
func(int, rlm .uverse.realm)- OID
- 0fe078…3476:3
assertIsNotUserCall details
assertIsNotEqualsTokens
func(token0Path string, token1Path string)assertIsNotEqualsTokens asserts that the token0Path and token1Path are not equal.
- OID
- 0fe078…3476:5
assertIsNotEqualsTokens details
assertIsSupportedFeeTier
func(fee uint32)assertIsSupportedFeeTier asserts that the fee is a supported fee tier.
- OID
- 0fe078…3476:6
assertIsSupportedFeeTier details
assertIsNotExistsPoolPath
func(instance *v1.poolV1, token0Path string, token1Path string, fee uint32)assertIsNotExistsPoolPath asserts that the pool path does not exist.
- OID
- 0fe078…3476:7
assertIsNotExistsPoolPath details
assertIsValidTokenOrder
func(token0Path string, token1Path string)- OID
- 0fe078…3476:8
assertIsValidTokenOrder details
errUnsupportedFeeTier
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-001] unsupported fee tier"
errPoolAlreadyExists
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-002] pool already created"
errOutOfRange
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-003] out of range for numeric value"
errInvalidInput
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-004] invalid input data"
errDataNotFound
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-005] requested data not found"
errLiquidityCalculation
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-006] invalid liquidity calculated"
errZeroLiquidity
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-007] zero liquidity"
errDuplicateTokenInPool
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-008] same token used in single pool"
errTickLowerInvalid
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-009] tickLower is invalid"
errTickUpperInvalid
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-010] tickUpper is invalid"
errInvalidSwapAmount
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-011] invalid swap amount"
errInvalidProtocolFeePct
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-012] invalid protocol fee percentage"
errInvalidWithdrawalFeePct
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-013] invalid withdrawal fee percentage"
errLockedPool
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-014] cannot modify pool while locked"
errPriceOutOfRange
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-015] swap price out of range"
errTransferFailed
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-016] token transfer failed"
errInvalidTickAndTickSpacing
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-017] invalid tick and tick spacing requested"
errInvalidTickRange
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-018] tickLower is greater than or equal to tickUpper"
errUnderflow
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-019] underflow"
errOverflow
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-020] overflow"
errBalanceUpdateFailed
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-021] balance update failed"
errInvalidPayer
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-022] invalid payer"
errNotAccessEOA
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-023] not access EOA"
errInsufficientPayment
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-024] insufficient payment"
errNotInitializedObservation
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-025] not initialized observation"
errObservationTooOld
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-026] target timestamp before oldest observation"
errSpoofedRealm
untyped stringError definitions for pool operations
Value
"[GNOSWAP-POOL-027] rlm does not match the current crossing frame"
newErrorWithDetail
func(message string, detail string) stringnewErrorWithDetail adds detail to an error message.
- OID
- 0fe078…3476:9
newErrorWithDetail details
makeErrorWithDetails
func(message string, details string) .uverse.errormakeErrorWithDetails creates an error with additional context.
- OID
- 0fe078…3476:11
makeErrorWithDetails details
tickEventInfo
typeValue
v1.tickEventInfo
NewTickEventInfo
func(tickID int32, tickInfo pool.TickInfo) *v1.tickEventInfo- OID
- 0fe078…3476:12
NewTickEventInfo details
FeeTier100
uint32Value
100
FeeTier500
uint32Value
500
FeeTier3000
uint32Value
3000
FeeTier10000
uint32Value
10000
MIN_SQRT_RATIO
stringValue
"4295128739"
MAX_SQRT_RATIO
stringValue
"1461446703485210103287273052203988822378723970342"
poolCreateConfig
typepoolCreateConfig holds the essential parameters for creating a new pool.
Value
v1.poolCreateConfig
newPoolParams
func(token0Path string, token1Path string, fee uint32, sqrtPriceX96 string, tickSpacing int32, slot0FeeProtocol uint8) *v1.poolCreateConfignewPoolParams defines the essential parameters for creating a new pool.
- OID
- 0fe078…3476:14
newPoolParams details
validateSqrtPriceX96
func(sqrtPriceX96 *uint256.Uint) .uverse.errorvalidateSqrtPriceX96 validates that the given sqrtPriceX96 is within valid range
- OID
- 0fe078…3476:16
validateSqrtPriceX96 details
isValidFeeTier
func(feeTier uint32) bool- OID
- 0fe078…3476:17
isValidFeeTier details
GetPoolPath
func(token0Path string, token1Path string, fee uint32) stringGetPoolPath generates a unique pool path string based on the token paths and fee tier.
- OID
- 0fe078…3476:18
GetPoolPath details
defaultSlot0FeeProtocol
uint8Value
0
defaultPoolCreationFee
int64// 100\_GNS
Value
100000000
defaultWithdrawalFeeBPS
uint64Value
100
defaultUnlocked
untyped boolValue
true
init.51
func()- OID
- 0fe078…3476:20
init.51 details
registerPoolV1
func()- OID
- 0fe078…3476:22
registerPoolV1 details
initStoreData
func(int, rlm .uverse.realm, poolStore pool.IPoolStore) .uverse.error- OID
- 0fe078…3476:23
initStoreData details
poolV1
typeValue
v1.poolV1
NewPoolV1
func(store pool.IPoolStore) pool.IPool- OID
- 0fe078…3476:24
NewPoolV1 details
GNS_TOKEN_KEY
stringValue
"gno.land/r/gnoswap/gns.GNS"
validateFeeProtocol
func(feeProtocol0 uint8, feeProtocol1 uint8) .uverse.errorvalidateFeeProtocol validates the fee protocol values for token0 and token1. This function checks whether the provided fee protocol values (\`feeProtocol0\` and \`feeProtocol1\`) are valid using the \`isValidFeeProtocolValue\` function. If either value is invalid, it returns an error indicating that the protocol fee percentage is invalid. Parameters: - feeProtocol0: uint8, the fee protocol value for token0. - feeProtocol1: uint8, the fee protocol value for token1. Returns: - error: Returns \`errInvalidProtocolFeePct\` if either \`feeProtocol0\` or \`feeProtocol1\` is invalid. Returns \`nil\` if both values are valid.
- OID
- 0fe078…3476:26
validateFeeProtocol details
isValidFeeProtocolValue
func(value uint8) boolisValidFeeProtocolValue checks if a fee protocol value is within acceptable range. Valid values are either 0 (disabled) or between 4 and 10 inclusive. The value is used as a denominator: protocolFee = swapFee / feeProtocol (e.g., feeProtocol=4 means 1/4 = 25% of swap fees go to protocol)
- OID
- 0fe078…3476:28
isValidFeeProtocolValue details
maxObservationCardinality
uint16maxObservationCardinality defines the maximum number of observations to store
Value
65535
getTWAP
func(p *pool.Pool, secondsAgo uint32) (int32, *uint256.Uint, .uverse.error)GetTWAP calculates the time-weighted average price between two points in time Returns the arithmetic mean tick and harmonic mean liquidity over the time period
- OID
- 0fe078…3476:29
getTWAP details
writeObservationByPool
func(p *pool.Pool, currentTime int64, tick int32, liquidity *uint256.Uint) .uverse.error- OID
- 0fe078…3476:31
writeObservationByPool details
increaseObservationCardinalityNextByPool
func(p *pool.Pool, observationCardinalityNext uint16) .uverse.error- OID
- 0fe078…3476:32
increaseObservationCardinalityNextByPool details
transform
func(lastObservation *pool.Observation, currentTime int64, tick int32, liquidity *uint256.Uint) (*pool.Observation, .uverse.error)- OID
- 0fe078…3476:33
transform details
grow
func(os *pool.ObservationState, currentCardinality uint16, nextCardinality uint16) (uint16, .uverse.error)- OID
- 0fe078…3476:34
grow details
lte
func(time int64, a int64, b int64) bool- OID
- 0fe078…3476:35
lte details
writeObservation
func(os *pool.ObservationState, currentTime int64, tick int32, liquidity *uint256.Uint) .uverse.error- OID
- 0fe078…3476:36
writeObservation details
lastObservation
func(os *pool.ObservationState) (*pool.Observation, .uverse.error)- OID
- 0fe078…3476:37
lastObservation details
observationAt
func(os *pool.ObservationState, index uint16) (*pool.Observation, .uverse.error)observationAt returns the observation at a specific index Returns error if the observation doesn't exist
- OID
- 0fe078…3476:38
observationAt details
observeSingle
func(os *pool.ObservationState, currentTime int64, secondsAgo uint32, tick int32, index uint16, liquidity *uint256.Uint, cardinality uint16) (int64, string, .uverse.error)observeSingle returns the data for a single observation at a specific time ago
- OID
- 0fe078…3476:39
observeSingle details
getSurroundingObservations
func(os *pool.ObservationState, target int64, currentTime int64, tick int32, index uint16, liquidity *uint256.Uint, cardinality uint16) (*pool.Observation, *pool.Observation, .uverse.error)getSurroundingObservations finds the observations immediately before and after the target timestamp. It uses binary search over the logical time-ordered view of the circular buffer. Logical order starts at (index+1) % cardinality (oldest) and ends at index (latest).
- OID
- 0fe078…3476:40
getSurroundingObservations details
binarySearch
func(os *pool.ObservationState, currentTime int64, target int64, index uint16, cardinality uint16) (*pool.Observation, *pool.Observation, .uverse.error)- OID
- 0fe078…3476:41
binarySearch details
observe
func(os *pool.ObservationState, currentTime int64, secondsAgos []uint32, tick int32, index uint16, liquidity *uint256.Uint, cardinality uint16) ([]int64, []string, .uverse.error)observe returns the cumulative tick and liquidity as of each timestamp secondsAgo from the current time.
- OID
- 0fe078…3476:42
observe details
minRequestedAmount
func(request int64, available int64) int64- OID
- 0fe078…3476:43
minRequestedAmount details
getPositionKey
func(tickLower int32, tickUpper int32) stringgetPositionKey generates a compact deterministic key for a liquidity position. Creates deterministic identifier for position tracking. Ensures unique positions per price range while preserving lexical ordering. Used internally for position state management. Parameters: - tickLower: Lower boundary tick of position range - tickUpper: Upper boundary tick of position range Key Format: EncodePositionKey(tickLower, tickUpper)
- OID
- 0fe078…3476:45
getPositionKey details
positionUpdate
func(position pool.PositionInfo, liquidityDelta *int256.Int, feeGrowthInside0X128 *uint256.Uint, feeGrowthInside1X128 *uint256.Uint) (pool.PositionInfo, .uverse.error)positionUpdate updates a position's liquidity and calculates fees owed. Returns the updated position information and any error.
- OID
- 0fe078…3476:47
positionUpdate details
calculateToken0Amount
func(sqrtPriceLower *uint256.Uint, sqrtPriceUpper *uint256.Uint, liquidityDelta *int256.Int) *int256.IntcalculateToken0Amount calculates the amount of token0 based on price range and liquidity delta.
- OID
- 0fe078…3476:48
calculateToken0Amount details
calculateToken1Amount
func(sqrtPriceLower *uint256.Uint, sqrtPriceUpper *uint256.Uint, liquidityDelta *int256.Int) *int256.IntcalculateToken1Amount calculates the amount of token1 based on price range and liquidity delta.
- OID
- 0fe078…3476:49
calculateToken1Amount details
PositionLiquidity
func(p *pool.Pool, key string) stringPositionLiquidity returns the liquidity of a position.
- OID
- 0fe078…3476:50
PositionLiquidity details
PositionFeeGrowthInside0LastX128
func(p *pool.Pool, key string) stringPositionFeeGrowthInside0LastX128 returns the fee growth of token0 inside a position.
- OID
- 0fe078…3476:51
PositionFeeGrowthInside0LastX128 details
PositionFeeGrowthInside1LastX128
func(p *pool.Pool, key string) stringPositionFeeGrowthInside1LastX128 returns the fee growth of token1 inside a position.
- OID
- 0fe078…3476:52
PositionFeeGrowthInside1LastX128 details
PositionTokensOwed0
func(p *pool.Pool, key string) int64PositionTokensOwed0 returns the amount of token0 owed by a position.
- OID
- 0fe078…3476:53
PositionTokensOwed0 details
PositionTokensOwed1
func(p *pool.Pool, key string) int64PositionTokensOwed1 returns the amount of token1 owed by a position.
- OID
- 0fe078…3476:54
PositionTokensOwed1 details
GetPositionByPool
func(p *pool.Pool, key string) (pool.PositionInfo, bool)GetPosition returns the position info for a given key.
- OID
- 0fe078…3476:55
GetPositionByPool details
positionUpdateWithKey
func(p *pool.Pool, positionKey string, liquidityDelta *int256.Int, feeGrowthInside0X128 *uint256.Uint, feeGrowthInside1X128 *uint256.Uint) (pool.PositionInfo, .uverse.error)positionUpdateWithKey updates a position in the pool and returns the updated position.
- OID
- 0fe078…3476:56
positionUpdateWithKey details
setPosition
func(p *pool.Pool, posKey string, positionInfo pool.PositionInfo)setPosition sets the position info for a given key.
- OID
- 0fe078…3476:57
setPosition details
mustGetPositionByPool
func(p *pool.Pool, positionKey string) *pool.PositionInfomustGetPosition returns the position info for a given key.
- OID
- 0fe078…3476:58
mustGetPositionByPool details
modifyPosition
func(p *pool.Pool, params v1.ModifyPositionParams) (pool.PositionInfo, *uint256.Uint, *uint256.Uint, .uverse.error)modifyPosition updates a position in the pool and calculates the amount of tokens needed (for minting) or returned (for burning). The calculation depends on the current price (tick) relative to the position's price range. The function handles three cases: 1. Current price below range (tick \< tickLower): only token0 is used/returned 2. Current price in range (tickLower \<= tick \< tickUpper): both tokens are used/returned 3. Current price above range (tick >= tickUpper): only token1 is used/returned Parameters: - params: ModifyPositionParams containing owner, tickLower, tickUpper, and liquidityDelta Returns: - PositionInfo: updated position information - \*u256.Uint: amount of token0 needed/returned - \*u256.Uint: amount of token1 needed/returned
- OID
- 0fe078…3476:59
modifyPosition details
updatePosition
func(p *pool.Pool, positionParams v1.ModifyPositionParams, tick int32) (pool.PositionInfo, .uverse.error)updatePosition modifies the position's liquidity and updates the corresponding tick states. This function updates the position data based on the specified liquidity delta and tick range. It also manages the fee growth, tick state flipping, and cleanup of unused tick data. Parameters: - positionParams: ModifyPositionParams, the parameters for the position modification, which include: - owner: The address of the position owner. - tickLower: The lower tick boundary of the position. - tickUpper: The upper tick boundary of the position. - liquidityDelta: The change in liquidity (positive or negative). - tick: int32, the current tick position. Returns: - PositionInfo: The updated position information. Workflow: 1. Clone the global fee growth values (token 0 and token 1). 2. If the liquidity delta is non-zero: - Update the lower and upper ticks using \`tickUpdate\`, flipping their states if necessary. - If a tick's state was flipped, update the tick bitmap to reflect the new state. 3. Calculate the fee growth inside the tick range using \`getFeeGrowthInside\`. 4. Generate a unique position key and update the position data using \`positionUpdateWithKey\`. 5. If liquidity is being removed (negative delta), clean up unused tick data by deleting the tick entries. 6. Return the updated position. Notes: - The function flips the tick states and cleans up unused tick data when liquidity is removed. - It ensures fee growth and position data remain accurate after the update. Example Usage: \`\`\`gno updatedPosition := pool.updatePosition(positionParams, currentTick) println("Updated Position Info:", updatedPosition) \`\`\`
- OID
- 0fe078…3476:60
updatePosition details
MaxBpsValue
uint64// 10%
Value
1000
ZeroBps
uint64Value
0
calculateAmountWithFee
func(amount *uint256.Uint, fee *uint256.Uint) (feeAmount *uint256.Uint, afterAmount *uint256.Uint)calculateAmountWithFee calculates the fee amount and the amount after the fee Inputs: - amount: the amount before the fee - fee: the fee in BPS Outputs: - the fee amount - the amount after the fee applied
- OID
- 0fe078…3476:61
calculateAmountWithFee details
zero
*uint256.UintHook functions allow external contracts to be notified of swap events.
- OID
- 0fe078…3476:64
zero details
zeroI256
*int256.Int/\* readonly \*/
- OID
- 0fe078…3476:67
zeroI256 details
fixedPointQ128
*uint256.UintHook functions allow external contracts to be notified of swap events.
- OID
- 0fe078…3476:70
fixedPointQ128 details
maxInt256
*uint256.UintHook functions allow external contracts to be notified of swap events.
- OID
- 0fe078…3476:73
maxInt256 details
maxInt64
*int256.IntHook functions allow external contracts to be notified of swap events.
- OID
- 0fe078…3476:76
maxInt64 details
minInt64
*int256.IntHook functions allow external contracts to be notified of swap events.
- OID
- 0fe078…3476:79
minInt64 details
SwapResult
typeSwapResult encapsulates all state changes from a swap. It ensures atomic state transitions that can be applied at once.
Value
v1.SwapResult
SwapComputation
typeSwapComputation encapsulates the pure computation logic for swaps.
Value
v1.SwapComputation
tickCrossHookFn
typetickCrossHookFn is invoked from inside the swap loop whenever an initialized tick is crossed. DrySwap passes nil to skip side effects.
Value
v1.tickCrossHookFn
applySwapResult
func(pool *pool.Pool, result *v1.SwapResult)applySwapResult updates pool state with computed results. All state changes are applied at once to maintain consistency
- OID
- 0fe078…3476:81
applySwapResult details
validatePriceLimits
func(slot0 pool.Slot0, zeroForOne bool, sqrtPriceLimitX96 *uint256.Uint)validatePriceLimits ensures the provided price limit is valid for the swap direction The function enforces that: For zeroForOne (selling token0): - Price limit must be below current price - Price limit must be above MIN\_SQRT\_RATIO For !zeroForOne (selling token1): - Price limit must be above current price - Price limit must be below MAX\_SQRT\_RATIO
- OID
- 0fe078…3476:83
validatePriceLimits details
getFeeProtocol
func(slot0 pool.Slot0, zeroForOne bool) uint8getFeeProtocol returns the appropriate fee protocol based on zero for one. When zeroForOne is true, we want the lower 4 bits (% 16). Otherwise, we want the upper 4 bits (/ 16).
- OID
- 0fe078…3476:84
getFeeProtocol details
getFeeGrowthGlobal
func(pool *pool.Pool, zeroForOne bool) *uint256.UintgetFeeGrowthGlobal returns the appropriate fee growth global based on zero for one.
- OID
- 0fe078…3476:85
getFeeGrowthGlobal details
shouldContinueSwap
func(state v1.SwapState, sqrtPriceLimitX96 *uint256.Uint) boolshouldContinueSwap checks if swap should continue based on remaining amount and price limit.
- OID
- 0fe078…3476:86
shouldContinueSwap details
updateFeeProtocol
func(step v1.StepComputations, feeProtocol uint8, state v1.SwapState) (v1.SwapState, v1.StepComputations, .uverse.error)updateFeeProtocol calculates and updates protocol fees for the current step.
- OID
- 0fe078…3476:87
updateFeeProtocol details
computeSwapStepInit
func(state v1.SwapState, pool *pool.Pool, zeroForOne bool) v1.StepComputationscomputeSwapStepInit initializes the computation for a single swap step.
- OID
- 0fe078…3476:88
computeSwapStepInit details
computeTargetSqrtRatio
func(step v1.StepComputations, sqrtPriceLimitX96 *uint256.Uint, zeroForOne bool) *uint256.UintcomputeTargetSqrtRatio determines the target sqrt price for the current swap step.
- OID
- 0fe078…3476:89
computeTargetSqrtRatio details
shouldUsePriceLimit
func(sqrtPriceNext *uint256.Uint, sqrtPriceLimit *uint256.Uint, zeroForOne bool) boolshouldUsePriceLimit returns true if the price limit should be used instead of the next tick price
- OID
- 0fe078…3476:90
shouldUsePriceLimit details
computeAmounts
func(state v1.SwapState, sqrtRatioTargetX96 *uint256.Uint, pool *pool.Pool, step v1.StepComputations) (v1.SwapState, v1.StepComputations)computeAmounts calculates the input and output amounts for the current swap step.
- OID
- 0fe078…3476:91
computeAmounts details
updateAmounts
func(step v1.StepComputations, state v1.SwapState, exactInput bool) (v1.SwapState, .uverse.error)updateAmounts calculates new remaining and calculated amounts based on the swap step. For exact input swaps: - Decrements remaining input amount by (amountIn + feeAmount) - Decrements calculated amount by amountOut For exact output swaps: - Increments remaining output amount by amountOut - Increments calculated amount by (amountIn + feeAmount)
- OID
- 0fe078…3476:92
updateAmounts details
MAX_LIQUIDITY_PER_TICK_SPACING_1
untyped stringValue
"191757530477355301479181766273477"
MAX_LIQUIDITY_PER_TICK_SPACING_10
untyped stringValue
"1917569901783203986719870431555990"
MAX_LIQUIDITY_PER_TICK_SPACING_60
untyped stringValue
"11505743598341114571880798222544994"
MAX_LIQUIDITY_PER_TICK_SPACING_200
untyped stringValue
"38350317471085141830651933667504588"
MIN_TICK
int32Value
-887272
MAX_TICK
int32Value
887272
maxLiquidityPerTickSpacing1FromDec
func() *uint256.UintmaxLiquidityPerTickSpacing\* return the precomputed max-liquidity-per-tick for each supported tick spacing. They are constructors (not package-level vars) so each caller receives a fresh instance — calculateMaxLiquidityPerTick returns the value directly to callers, and a shared singleton could otherwise be mutated in place and corrupt every caller. Values are built from little-endian \[4]uint64 literals to avoid runtime decimal parsing.
- OID
- 0fe078…3476:93
maxLiquidityPerTickSpacing1FromDec details
maxLiquidityPerTickSpacing10FromDec
func() *uint256.Uint- OID
- 0fe078…3476:95
maxLiquidityPerTickSpacing10FromDec details
maxLiquidityPerTickSpacing60FromDec
func() *uint256.Uint- OID
- 0fe078…3476:96
maxLiquidityPerTickSpacing60FromDec details
maxLiquidityPerTickSpacing200FromDec
func() *uint256.Uint- OID
- 0fe078…3476:97
maxLiquidityPerTickSpacing200FromDec details
GetTickLiquidityGross
func(p *pool.Pool, tick int32) stringGetTickLiquidityGross returns the gross liquidity for the specified tick.
- OID
- 0fe078…3476:98
GetTickLiquidityGross details
GetTickLiquidityNet
func(p *pool.Pool, tick int32) stringGetTickLiquidityNet returns the net liquidity for the specified tick.
- OID
- 0fe078…3476:99
GetTickLiquidityNet details
GetTickFeeGrowthOutside0X128
func(p *pool.Pool, tick int32) stringGetTickFeeGrowthOutside0X128 returns the fee growth outside the tick for token 0.
- OID
- 0fe078…3476:100
GetTickFeeGrowthOutside0X128 details
GetTickFeeGrowthOutside1X128
func(p *pool.Pool, tick int32) stringGetTickFeeGrowthOutside1X128 returns the fee growth outside the tick for token 1.
- OID
- 0fe078…3476:101
GetTickFeeGrowthOutside1X128 details
GetTickCumulativeOutside
func(p *pool.Pool, tick int32) int64GetTickCumulativeOutside returns the cumulative liquidity outside the tick.
- OID
- 0fe078…3476:102
GetTickCumulativeOutside details
GetTickSecondsPerLiquidityOutsideX128
func(p *pool.Pool, tick int32) stringGetTickSecondsPerLiquidityOutsideX128 returns the seconds per liquidity outside the tick.
- OID
- 0fe078…3476:103
GetTickSecondsPerLiquidityOutsideX128 details
GetTickSecondsOutside
func(p *pool.Pool, tick int32) uint32GetTickSecondsOutside returns the seconds outside the tick.
- OID
- 0fe078…3476:104
GetTickSecondsOutside details
GetTickInitialized
func(p *pool.Pool, tick int32) boolGetTickInitialized returns whether the tick is initialized.
- OID
- 0fe078…3476:105
GetTickInitialized details
getFeeGrowthInside
func(p *pool.Pool, tickLower int32, tickUpper int32, tickCurrent int32, feeGrowthGlobal0X128 *uint256.Uint, feeGrowthGlobal1X128 *uint256.Uint) (*uint256.Uint, *uint256.Uint)getFeeGrowthInside calculates the fee growth within a specified tick range. This function computes the accumulated fee growth for token 0 and token 1 inside a given tick range (\`tickLower\` to \`tickUpper\`) relative to the current tick position (\`tickCurrent\`). It isolates the fee growth within the range by subtracting the fee growth below the lower tick and above the upper tick from the global fee growth. Parameters: - tickLower: int32, the lower tick boundary of the range. - tickUpper: int32, the upper tick boundary of the range. - tickCurrent: int32, the current tick index. - feeGrowthGlobal0X128: \*u256.Uint, the global fee growth for token 0 in X128 precision. - feeGrowthGlobal1X128: \*u256.Uint, the global fee growth for token 1 in X128 precision. Returns: - \*u256.Uint: Fee growth inside the tick range for token 0. - \*u256.Uint: Fee growth inside the tick range for token 1. Workflow: 1. Retrieve the tick information (\`lower\` and \`upper\`) for the lower and upper tick boundaries using \`p.getTick\`. 2. Calculate the fee growth below the lower tick using \`getFeeGrowthBelowX128\`. 3. Calculate the fee growth above the upper tick using \`getFeeGrowthAboveX128\`. 4. Subtract the fee growth below and above the range from the global fee growth values: feeGrowthInside = feeGrowthGlobal - feeGrowthBelow - feeGrowthAbove 5. Return the computed fee growth values for token 0 and token 1 within the range. Behavior: - The fee growth is isolated within the range \`\[tickLower, tickUpper]\`. - The function ensures the calculations accurately consider the tick boundaries and the current tick position. Example: \`\`\`gno feeGrowth0, feeGrowth1 := pool.getFeeGrowthInside( 100, 200, 150, globalFeeGrowth0, globalFeeGrowth1, ) println("Fee Growth Inside (Token 0):", feeGrowth0) println("Fee Growth Inside (Token 1):", feeGrowth1) \`\`\`
- OID
- 0fe078…3476:106
getFeeGrowthInside details
tickUpdate
func(p *pool.Pool, tick int32, tickCurrent int32, liquidityDelta *int256.Int, feeGrowthGlobal0X128 *uint256.Uint, feeGrowthGlobal1X128 *uint256.Uint, upper bool, maxLiquidity *uint256.Uint) flipped booltickUpdate updates the state of a specific tick. This function applies a given liquidity change (liquidityDelta) to the specified tick, updates the fee growth values if necessary, and adjusts the net liquidity based on whether the tick is an upper or lower boundary. It also verifies that the total liquidity does not exceed the maximum allowed value and ensures the net liquidity stays within the valid int128 range. Parameters: - tick: int32, the index of the tick to update. - tickCurrent: int32, the current active tick index. - liquidityDelta: \*i256.Int, the amount of liquidity to add or remove. - feeGrowthGlobal0X128: \*u256.Uint, the global fee growth value for token 0. - feeGrowthGlobal1X128: \*u256.Uint, the global fee growth value for token 1. - upper: bool, indicates if this is the upper boundary (true for upper, false for lower). - maxLiquidity: \*u256.Uint, the maximum allowed liquidity. Returns: - flipped: bool, indicates if the tick's initialization state has changed. (e.g., liquidity transitioning from zero to non-zero, or vice versa) Workflow: 1. Nil input values are replaced with zero. 2. The function retrieves the tick information for the specified tick index. 3. Applies the liquidityDelta to compute the new total liquidity (liquidityGross). - If the total liquidity exceeds the maximum allowed value, the function panics. 4. Checks whether the tick's initialized state has changed and sets the \`flipped\` flag. 5. If the tick was previously uninitialized and its index is less than or equal to the current tick, the fee growth values are initialized to the current global values. 6. Updates the tick's net liquidity: - For an upper boundary, it subtracts liquidityDelta. - For a lower boundary, it adds liquidityDelta. - Ensures the net liquidity remains within the int128 range using \`checkOverFlowInt128\`. 7. Updates the tick's state with the new values. 8. Returns whether the tick's initialized state has flipped. Panic Conditions: - The total liquidity (liquidityGross) exceeds the maximum allowed liquidity (maxLiquidity). - The net liquidity (liquidityNet) exceeds the int128 range. Example: \`\`\`gno flipped := pool.tickUpdate(10, 5, liquidityDelta, feeGrowth0, feeGrowth1, true, maxLiquidity) println("Tick flipped:", flipped) \`\`\`
- OID
- 0fe078…3476:107
tickUpdate details
tickCross
func(p *pool.Pool, tick int32, feeGrowthGlobal0X128 *uint256.Uint, feeGrowthGlobal1X128 *uint256.Uint, secondsPerLiquidityCumulativeX128 *uint256.Uint, tickCumulative int64, blockTimestamp int64) *int256.InttickCross updates a tick's state when it is crossed and returns the liquidity net. Updates fee growth and oracle accumulator values for the tick.
- OID
- 0fe078…3476:108
tickCross details
setTick
func(p *pool.Pool, tick int32, newTickInfo pool.TickInfo)setTick updates the tick data for the specified tick index in the pool.
- OID
- 0fe078…3476:109
setTick details
deleteTick
func(p *pool.Pool, tick int32)deleteTick deletes the tick data for the specified tick index in the pool.
- OID
- 0fe078…3476:110
deleteTick details
getTick
func(p *pool.Pool, tick int32) pool.TickInfogetTick retrieves the TickInfo associated with the specified tick index from the pool. If the TickInfo contains any nil fields, they are replaced with zero values using valueOrZero. Parameters: - tick: The tick index (int32) for which the TickInfo is to be retrieved. Behavior: - Retrieves the TickInfo for the given tick from the pool's tick map. - Ensures that all fields of TickInfo are non-nil by calling valueOrZero, which replaces nil values with zero. - Returns the updated TickInfo. Returns: - TickInfo: The tick data with all fields guaranteed to have valid values (nil fields are set to zero). Use Case: This function ensures the retrieved tick data is always valid and safe for further operations, such as calculations or updates, by sanitizing nil fields in the TickInfo structure.
- OID
- 0fe078…3476:111
getTick details
mustGetTick
func(p *pool.Pool, tick int32) *pool.TickInfomustGetTick retrieves the TickInfo for a specific tick, panicking if the tick does not exist. This function ensures that the requested tick data exists in the pool's tick mapping. If the tick does not exist, it panics with an appropriate error message. Parameters: - tick: int32, the index of the tick to retrieve. Returns: - TickInfo: The information associated with the specified tick. Behavior: - Checks if the tick exists in the pool's tick mapping (\`p.ticks\`). - If the tick exists, it returns the corresponding \`TickInfo\`. - If the tick does not exist, the function panics with a descriptive error. Panic Conditions: - The specified tick does not exist in the pool's mapping. Example: \`\`\`gno tickInfo := pool.mustGetTick(10) ufmt.Println("Tick Info:", tickInfo) \`\`\`
- OID
- 0fe078…3476:112
mustGetTick details
calculateMaxLiquidityPerTick
func(tickSpacing int32) *uint256.UintcalculateMaxLiquidityPerTick calculates the maximum liquidity per tick for a given tick spacing.
- OID
- 0fe078…3476:113
calculateMaxLiquidityPerTick details
getFeeGrowthBelowX128
func(tickLower int32, tickCurrent int32, feeGrowthGlobal0X128 *uint256.Uint, feeGrowthGlobal1X128 *uint256.Uint, lowerTick pool.TickInfo) (*uint256.Uint, *uint256.Uint)getFeeGrowthBelowX128 calculates the fee growth below a specified tick. This function computes the fee growth for token 0 and token 1 below a given tick (\`tickLower\`) relative to the current tick (\`tickCurrent\`). The fee growth values are adjusted based on whether the \`tickCurrent\` is above or below the \`tickLower\`. Parameters: - tickLower: int32, the lower tick boundary for fee calculation. - tickCurrent: int32, the current tick index. - feeGrowthGlobal0X128: \*u256.Uint, the global fee growth for token 0 in X128 precision. - feeGrowthGlobal1X128: \*u256.Uint, the global fee growth for token 1 in X128 precision. - lowerTick: TickInfo, the fee growth and liquidity details for the lower tick. Returns: - \*u256.Uint: Fee growth below \`tickLower\` for token 0. - \*u256.Uint: Fee growth below \`tickLower\` for token 1. Workflow: 1. If \`tickCurrent\` is greater than or equal to \`tickLower\`: - Return the \`feeGrowthOutside0X128\` and \`feeGrowthOutside1X128\` values of the \`lowerTick\`. 2. If \`tickCurrent\` is below \`tickLower\`: - Compute the fee growth below the lower tick by subtracting \`feeGrowthOutside\` values from the global fee growth values (\`feeGrowthGlobal0X128\` and \`feeGrowthGlobal1X128\`). 3. Return the calculated fee growth values for both tokens. Behavior: - If \`tickCurrent >= tickLower\`, the fee growth outside the lower tick is returned as-is. - If \`tickCurrent \< tickLower\`, the fee growth is calculated as: feeGrowthBelow = feeGrowthGlobal - feeGrowthOutside Example: \`\`\`gno feeGrowth0, feeGrowth1 := getFeeGrowthBelowX128( 100, 150, globalFeeGrowth0, globalFeeGrowth1, lowerTickInfo, ) println("Fee Growth Below:", feeGrowth0, feeGrowth1)
- OID
- 0fe078…3476:114
getFeeGrowthBelowX128 details
getFeeGrowthAboveX128
func(tickUpper int32, tickCurrent int32, feeGrowthGlobal0X128 *uint256.Uint, feeGrowthGlobal1X128 *uint256.Uint, upperTick pool.TickInfo) (*uint256.Uint, *uint256.Uint)getFeeGrowthAboveX128 calculates the fee growth above a specified tick. This function computes the fee growth for token 0 and token 1 above a given tick (\`tickUpper\`) relative to the current tick (\`tickCurrent\`). The fee growth values are adjusted based on whether the \`tickCurrent\` is above or below the \`tickUpper\`. Parameters: - tickUpper: int32, the upper tick boundary for fee calculation. - tickCurrent: int32, the current tick index. - feeGrowthGlobal0X128: \*u256.Uint, the global fee growth for token 0 in X128 precision. - feeGrowthGlobal1X128: \*u256.Uint, the global fee growth for token 1 in X128 precision. - upperTick: TickInfo, the fee growth and liquidity details for the upper tick. Returns: - \*u256.Uint: Fee growth above \`tickUpper\` for token 0. - \*u256.Uint: Fee growth above \`tickUpper\` for token 1. Workflow: 1. If \`tickCurrent\` is less than \`tickUpper\`: - Return the \`feeGrowthOutside0X128\` and \`feeGrowthOutside1X128\` values of the \`upperTick\`. 2. If \`tickCurrent\` is greater than or equal to \`tickUpper\`: - Compute the fee growth above the upper tick by subtracting \`feeGrowthOutside\` values from the global fee growth values (\`feeGrowthGlobal0X128\` and \`feeGrowthGlobal1X128\`). 3. Return the calculated fee growth values for both tokens. Behavior: - If \`tickCurrent \< tickUpper\`, the fee growth outside the upper tick is returned as-is. - If \`tickCurrent >= tickUpper\`, the fee growth is calculated as: feeGrowthAbove = feeGrowthGlobal - feeGrowthOutside Example: feeGrowth0, feeGrowth1 := getFeeGrowthAboveX128( 200, 150, globalFeeGrowth0, globalFeeGrowth1, upperTickInfo, ) println("Fee Growth Above:", feeGrowth0, feeGrowth1) \`\`\`
- OID
- 0fe078…3476:115
getFeeGrowthAboveX128 details
validateTicks
func(tickLower int32, tickUpper int32) .uverse.errorvalidateTicks validates the tick range for a liquidity position. This function performs three essential checks to ensure the provided tick values are valid before creating or modifying a liquidity position.
- OID
- 0fe078…3476:116
validateTicks details
bitMask8
untyped bigint// 256 - 1
Value
(255 <untyped> bigint)
tickBitmapFlipTick
func(p *pool.Pool, tick int32, tickSpacing int32)tickBitmapFlipTick flips the state of a tick in the tick bitmap. This function toggles the "initialized" state of a tick in the tick bitmap. It ensures that the tick aligns with the specified tick spacing and then flips the corresponding bit in the bitmap representation. Parameters: - tick: int32, the tick index to toggle. - tickSpacing: int32, the spacing between valid ticks. The tick must align with this spacing. Workflow: 1. Validates that the \`tick\` aligns with \`tickSpacing\` using \`checkTickSpacing\`. 2. Computes the position of the bit in the tick bitmap: - \`wordPos\`: Determines which word in the bitmap contains the bit. - \`bitPos\`: Identifies the position of the bit within the word. 3. Creates a bitmask using \`Lsh\` (Left Shift) to target the bit at \`bitPos\`. 4. Toggles (flips) the bit using XOR with the current value of the tick bitmap. 5. Updates the tick bitmap with the modified word. Behavior: - If the bit is \`0\` (uninitialized), it will be flipped to \`1\` (initialized). - If the bit is \`1\` (initialized), it will be flipped to \`0\` (uninitialized). Example: pool.tickBitmapFlipTick(120, 60) // This flips the bit for tick 120 with a tick spacing of 60. Notes: - The \`tick\` must be divisible by \`tickSpacing\`. If not, the function will panic.
- OID
- 0fe078…3476:117
tickBitmapFlipTick details
tickBitmapNextInitializedTickWithInOneWord
func(p *pool.Pool, tick int32, tickSpacing int32, lte bool) (int32, bool)tickBitmapNextInitializedTickWithInOneWord finds the next initialized tick within one word of the bitmap.
- OID
- 0fe078…3476:119
tickBitmapNextInitializedTickWithInOneWord details
getTickBitmap
func(p *pool.Pool, wordPos int16) *uint256.UintgetTickBitmap gets the tick bitmap for the given word position if the tick bitmap is not initialized, initialize it to zero
- OID
- 0fe078…3476:120
getTickBitmap details
setTickBitmap
func(p *pool.Pool, wordPos int16, tickBitmap *uint256.Uint)setTickBitmap sets the tick bitmap for the given word position
- OID
- 0fe078…3476:121
setTickBitmap details
tickBitmapPosition
func(tick int32) (int16, uint8)tickBitmapPosition calculates the word and bit position for a given tick
- OID
- 0fe078…3476:122
tickBitmapPosition details
getWordAndBitPos
func(tick int32, lte bool) (int16, uint8)getWordAndBitPos gets tick's wordPos and bitPos depending on the swap direction
- OID
- 0fe078…3476:123
getWordAndBitPos details
getMaskBit
func(bitPos uint, lte bool) *uint256.UintgetMaskBit generates a mask based on the provided bit position (bitPos) and a boolean flag (lte). The function constructs a bitmask with a shift depending on the bit position and the boolean value. It either returns the mask or its negation, based on the value of 'lte' (swap direction). NOTE: should always use a newly created \`u256.One()\` object.
- OID
- 0fe078…3476:124
getMaskBit details
getNextTick
func(lte bool, initialized bool, compress int32, bitPos uint8, tickSpacing int32, masked *uint256.Uint) int32getNextTick gets the next tick depending on the initialized state and the swap direction
- OID
- 0fe078…3476:125
getNextTick details
getTickIfInitialized
func(compress int32, tickSpacing int32, bitPos uint8, masked *uint256.Uint, lte bool) int32getTickIfInitialized gets the next tick if the tick bitmap is initialized
- OID
- 0fe078…3476:126
getTickIfInitialized details
getTickIfNotInitialized
func(compress int32, tickSpacing int32, bitPos uint8, lte bool) int32getTickIfNotInitialized gets the next tick if the tick bitmap is not initialized
- OID
- 0fe078…3476:127
getTickIfNotInitialized details
validatePoolBalance
func(token0 int64, token1 int64, amount int64, isToken0 bool) .uverse.errorvalidatePoolBalance checks if the pool has sufficient balance of either token0 and token1 before proceeding with a transfer. This prevents the pool won't go into a negative balance.
- OID
- 0fe078…3476:128
validatePoolBalance details
updatePoolBalance
func(token0 int64, token1 int64, amount int64, isToken0 bool) (int64, .uverse.error)updatePoolBalance calculates the new balance after a transfer and validate. It ensures the resulting balance won't be negative or overflow.
- OID
- 0fe078…3476:130
updatePoolBalance details
ModifyPositionParams
typeModifyPositionParams repersents the parameters for modifying a liquidity position. This structure is used internally both \`Mint\` and \`Burn\` operation to manage the liquidity positions.
Value
v1.ModifyPositionParams
newModifyPositionParams
func(owner .uverse.address, tickLower int32, tickUpper int32, liquidityDelta *int256.Int) v1.ModifyPositionParamsnewModifyPositionParams creates a new \`ModifyPositionParams\` instance. This is used to preare parameters for the \`modifyPosition\` function, which handles both minting and burning of liquidity positions. Parameters: - owner: address that will own (or owns) the position - tickLower: lower tick bound of the position - tickUpper: upper tick bound of the position - liquidityDelta: amount of liquidity to add (positive) or remove (negative) The tick parameters represent prices as powers of 1.0001: - actual\_price = 1.0001^tick - For example, tick = 100 means price = 1.0001^100 Returns: - ModifyPositionParams: a new instance of ModifyPositionParams
- OID
- 0fe078…3476:131
newModifyPositionParams details
SwapCache
typeSwapCache holds data that remains constant throughout a swap.
Value
v1.SwapCache
newSwapCache
func(feeProtocol uint8, liquidityStart *uint256.Uint, blockTimestamp int64) *v1.SwapCache- OID
- 0fe078…3476:133
newSwapCache details
SwapState
typeSwapState tracks the changing values during a swap. This type helps manage the state transitions that occur as the swap progresses across different price ranges.
Value
v1.SwapState
newSwapState
func(amountSpecifiedRemaining *int256.Int, feeGrowthGlobalX128 *uint256.Uint, liquidity *uint256.Uint, slot0 pool.Slot0) v1.SwapState- OID
- 0fe078…3476:134
newSwapState details
StepComputations
typeStepComputations 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.
Value
v1.StepComputations
newPool
func(poolInfo *v1.poolCreateConfig) *pool.Pool- OID
- 0fe078…3476:135
newPool details
MAX_UINT64
stringValue
"18446744073709551615"
MAX_INT64
stringValue
"9223372036854775807"
MAX_INT128
stringValue
"170141183460469231731687303715884105727"
MAX_UINT128
stringValue
"340282366920938463463374607431768211455"
MAX_INT256
stringValue
"57896044618658097711785492504343953926634992332820282019728792003956564819967"
INT64_MIN
int64Value
-9223372036854775808
INT64_MAX
int64Value
9223372036854775807
Q96_RESOLUTION
uintValue
96
Q128_RESOLUTION
uintValue
128
Q64
string// 2 \*\* 64
Value
"18446744073709551616"
Q96
string// 2 \*\* 96
Value
"79228162514264337593543950336"
Q128
string// 2 \*\* 128
Value
"340282366920938463463374607431768211456"
maxInt128FromDecimal
*int256.Int- OID
- 0fe078…3476:137
maxInt128FromDecimal details
maxUint128FromDecimal
*uint256.Uint- OID
- 0fe078…3476:140
maxUint128FromDecimal details
q128FromDecimal
*uint256.Uint- OID
- 0fe078…3476:143
q128FromDecimal details
uint128Mask
*uint256.Uint- OID
- 0fe078…3476:146
uint128Mask details
toUint128
func(value *uint256.Uint) *uint256.UinttoUint128 ensures a \*u256.Uint value fits within the uint128 range. This function validates that the given \`value\` is properly initialized and checks whether it exceeds the maximum value of uint128. If the value exceeds the uint128 range, it applies a masking operation to truncate the value to fit within the uint128 limit. Parameters: - value: \*u256.Uint, the value to be checked and possibly truncated. Returns: - \*u256.Uint: A value guaranteed to fit within the uint128 range. Notes: - The function first checks if the value is not nil to avoid potential runtime errors. - The mask ensures that only the lower 128 bits of the value are retained. - If the input value is already within the uint128 range, it is returned unchanged. - If masking is required, a new instance is returned without modifying the input. - MAX\_UINT128 is a constant representing \`2^128 - 1\`.
- OID
- 0fe078…3476:148
toUint128 details
u256Min
func(num1 *uint256.Uint, num2 *uint256.Uint) *uint256.Uintu256Min returns the smaller of two \*u256.Uint values. This function compares two unsigned 256-bit integers and returns the smaller of the two. If \`num1\` is less than \`num2\`, it returns \`num1\`; otherwise, it returns \`num2\`. Parameters: - num1 (\*u256.Uint): The first unsigned 256-bit integer. - num2 (\*u256.Uint): The second unsigned 256-bit integer. Returns: - \*u256.Uint: The smaller of \`num1\` and \`num2\`. Notes: - This function uses the \`Lt\` (less than) method of \`\*u256.Uint\` to perform the comparison. - The function assumes both input values are non-nil. If nil inputs are possible in the usage context, additional validation may be needed. Example: smaller := u256Min(u256.MustFromDecimal("10"), u256.MustFromDecimal("20")) // Returns 10 smaller := u256Min(u256.MustFromDecimal("30"), u256.MustFromDecimal("20")) // Returns 20
- OID
- 0fe078…3476:150
u256Min details
checkOverFlowInt128
func(value *int256.Int)checkOverFlowInt128 checks if the value overflows the int128 range.
- OID
- 0fe078…3476:151
checkOverFlowInt128 details
checkTickSpacing
func(tick int32, tickSpacing int32)checkTickSpacing checks if the tick is divisible by the tickSpacing.
- OID
- 0fe078…3476:152