PathrockNetwork Gno Explorer
HomeBlocksTransactionsRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/r/gnoswap/pool/v1

Realm
Open in gnoweb ↗

Overview

Kind
Realm (renderable)
Name
v1
Namespace
gnoswap / pool
Files
24 (README)(gnomod.toml)
Exported functions
3
Module
gno.land/r/gnoswap/pool/v1
gno
0.9

Files (24)

  • README.mdmarkdown
  • gnomod.tomltoml
  • assert.gnogno
  • doc.gnogno
  • errors.gnogno
  • event_info.gnogno
  • factory_param.gnogno
  • getter_utils.gnogno
  • getter.gnogno
  • init.gnogno
  • instance.gnogno
  • lock.gnogno
  • manager.gnogno
  • oracle.gnogno
  • pool.gnogno
  • position.gnogno
  • protocol_fee.gnogno
  • render.gnogno
  • swap.gnogno
  • tick_bitmap.gnogno
  • tick.gnogno
  • transfer.gnogno
  • type.gnogno
  • utils.gnogno
  • init.gnogno
    1package pool23import (4	ufmt "gno.land/p/nt/ufmt/v0"5	"gno.land/r/gnoswap/access/v1"6	"gno.land/r/gnoswap/emission"7	"gno.land/r/gnoswap/pool"

    Functions

    • GetPoolPath(token0Path string, token1Path string, fee uint32) string

    • NewPoolV1(store interface {GetFeeAmountTickSpacing func() map[uint32]int32; GetObservations func() *gno.land/p/nt/bptree/v0.BPTree; GetPendingProtocolFee func(string) int64; GetPendingProtocolFees func() map[string]int64; GetPoolCreationFee func() int64; GetPools func() *gno.land/p/nt/bptree/v0.BPTree; GetSlot0FeeProtocol func() uint8; GetSwapEndHook func() func(.uverse.realm, string) .uverse.error; GetSwapStartHook func() func(.uverse.realm, string, int64); GetTickCrossHook func() func(.uverse.realm, string, int32, bool, int64); GetUnlocked func() bool; GetWithdrawalFeeBPS func() uint64; HasFeeAmountTickSpacing func() bool; HasObservations func() bool; HasPendingProtocolFees func() bool; HasPoolCreationFee func() bool; HasPools func() bool; HasSlot0FeeProtocol func() bool; HasSwapEndHook func() bool; HasSwapStartHook func() bool; HasTickCrossHook func() bool; HasUnlocked func() bool; HasWithdrawalFeeBPS func() bool; RemovePendingProtocolFee func(int, .uverse.realm, string) .uverse.error; SetFeeAmountTickSpacing func(int, .uverse.realm, map[uint32]int32) .uverse.error; SetObservations func(int, .uverse.realm, *gno.land/p/nt/bptree/v0.BPTree) .uverse.error; SetPendingProtocolFee func(int, .uverse.realm, string, int64) .uverse.error; SetPendingProtocolFees func(int, .uverse.realm, map[string]int64) .uverse.error; SetPoolCreationFee func(int, .uverse.realm, int64) .uverse.error; SetPools func(int, .uverse.realm, *gno.land/p/nt/bptree/v0.BPTree) .uverse.error; SetSlot0FeeProtocol func(int, .uverse.realm, uint8) .uverse.error; SetSwapEndHook func(int, .uverse.realm, func(.uverse.realm, string) .uverse.error) .uverse.error; SetSwapStartHook func(int, .uverse.realm, func(.uverse.realm, string, int64)) .uverse.error; SetTickCrossHook func(int, .uverse.realm, func(.uverse.realm, string, int32, bool, int64)) .uverse.error; SetUnlocked func(int, .uverse.realm, bool) .uverse.error; SetWithdrawalFeeBPS func(int, .uverse.realm, uint64) .uverse.error}) interface {Burn func(int, .uverse.realm, string, string, uint32, int32, int32, string, .uverse.address) (string, string); Collect func(int, .uverse.realm, string, string, uint32, .uverse.address, int32, int32, string, string) (string, string); CollectProtocol func(int, .uverse.realm, string, string, uint32, .uverse.address, string, string) (string, string); CollectSwapFee func(int, .uverse.realm, string, string, uint32, .uverse.address, int32, int32, string, string) (string, string, string, string); CreatePool func(int, .uverse.realm, string, string, uint32, string); DrySwap func(string, string, uint32, bool, string, string) (string, string, .uverse.error); ExistsPoolPath func(string) bool; GetBalanceToken0 func(string) (int64, .uverse.error); GetBalanceToken1 func(string) (int64, .uverse.error); GetFee func(string) (uint32, .uverse.error); GetFeeAmountTickSpacing func(uint32) (int32, .uverse.error); GetFeeAmountTickSpacings func() map[uint32]int32; GetFeeGrowthGlobal0X128 func(string) (*gno.land/p/gnoswap/uint256/v1.Uint, .uverse.error); GetFeeGrowthGlobal1X128 func(string) (*gno.land/p/gnoswap/uint256/v1.Uint, .uverse.error); GetFeeGrowthGlobalX128 func(string) (*gno.land/p/gnoswap/uint256/v1.Uint, *gno.land/p/gnoswap/uint256/v1.Uint, .uverse.error); GetInitializedTicksInRange func(string, int32, int32) ([]int32, .uverse.error); GetLiquidity func(string) (*gno.land/p/gnoswap/uint256/v1.Uint, .uverse.error); GetObservationAt func(string, uint16) (gno.land/r/gnoswap/pool.Observation, .uverse.error); GetPendingProtocolFees func() map[string]int64; GetPoolCreationFee func() int64; GetPoolPositions func(string) *gno.land/p/nt/bptree/rotree/v0.ReadOnlyTree; GetPools func() *gno.land/p/nt/bptree/rotree/v0.ReadOnlyTree; GetPositionFeeGrowthInside0LastX128 func(string, string) (string, .uverse.error); GetPositionFeeGrowthInside1LastX128 func(string, string) (string, .uverse.error); GetPositionFeeGrowthInsideLastX128 func(string, string) (string, string, .uverse.error); GetPositionLiquidity func(string, string) (string, .uverse.error); GetPositionTokensOwed0 func(string, string) (int64, .uverse.error); GetPositionTokensOwed1 func(string, string) (int64, .uverse.error); GetProtocolFeesToken0 func(string) (int64, .uverse.error); GetProtocolFeesToken1 func(string) (int64, .uverse.error); GetSlot0 func(string) gno.land/r/gnoswap/pool.Slot0; GetSlot0FeeProtocol func(string) (uint8, .uverse.error); GetSlot0SqrtPriceX96 func(string) (*gno.land/p/gnoswap/uint256/v1.Uint, .uverse.error); GetSlot0Tick func(string) (int32, .uverse.error); GetSlot0Unlocked func(string) (bool, .uverse.error); GetTickBitmaps func(string, int16) (string, .uverse.error); GetTickCumulativeOutside func(string, int32) (int64, .uverse.error); GetTickFeeGrowthOutside0X128 func(string, int32) (string, .uverse.error); GetTickFeeGrowthOutside1X128 func(string, int32) (string, .uverse.error); GetTickFeeGrowthOutsideX128 func(string, int32) (string, string, .uverse.error); GetTickInfo func(string, int32) (gno.land/r/gnoswap/pool.TickInfo, .uverse.error); GetTickInitialized func(string, int32) (bool, .uverse.error); GetTickLiquidityGross func(string, int32) (string, .uverse.error); GetTickLiquidityNet func(string, int32) (string, .uverse.error); GetTickSecondsOutside func(string, int32) (uint32, .uverse.error); GetTickSecondsPerLiquidityOutsideX128 func(string, int32) (string, .uverse.error); GetTickSpacing func(string) (int32, .uverse.error); GetToken0Path func(string) (string, .uverse.error); GetToken1Path func(string) (string, .uverse.error); GetWithdrawalFee func() uint64; IncreaseObservationCardinalityNext func(int, .uverse.realm, string, string, uint32, uint16); Mint func(int, .uverse.realm, string, string, uint32, int32, int32, string, .uverse.address) (string, string); Observe func(string, []uint32) ([]int64, []string, .uverse.error); OracleConsult func(string, uint32) (int32, *gno.land/p/gnoswap/uint256/v1.Uint, .uverse.error); Render func(string) string; SetFeeProtocol func(int, .uverse.realm, uint8, uint8); SetPoolCreationFee func(int, .uverse.realm, int64); SetSwapEndHook func(int, .uverse.realm, func(.uverse.realm, string) .uverse.error); SetSwapStartHook func(int, .uverse.realm, func(.uverse.realm, string, int64)); SetTickCrossHook func(int, .uverse.realm, func(.uverse.realm, string, int32, bool, int64)); SetWithdrawalFee func(int, .uverse.realm, uint64); SnapshotCumulativesInside func(string, int32, int32) (int64, *gno.land/p/gnoswap/uint256/v1.Uint, uint32, .uverse.error); Swap func(int, .uverse.realm, string, string, uint32, .uverse.address, bool, string, string, func(.uverse.realm, int64, int64, *gno.land/r/gnoswap/pool.CallbackMarker) .uverse.error) (string, string)}

    • NewTickEventInfo(tickID int32, tickInfo struct{liquidityGross string; liquidityNet string; feeGrowthOutside0X128 string; feeGrowthOutside1X128 string; tickCumulativeOutside int64; secondsPerLiquidityOutsideX128 string; secondsOutside uint32; initialized bool}) *gno.land/r/gnoswap/pool/v1.tickEventInfo

    Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.

    Rendered

    RenderedRawgnoweb ↗
    This realm does not provide renderable output (vm/qrender → NoRenderDeclError). View on gnoweb ↗

    vm/qrender output, sanitized (docs/render-security.md) and displayed in an empty-sandbox iframe — scripts, forms and popups cannot run. Links stay inert in-preview; right-click to open.

    8
    )
    9
    10const (
    11 // slot0FeeProtocol is the protocol-fee denominator (0 or 4-10).
    12 // Zero disables protocol fees; 4 routes 1/4 of swap fees to the protocol.
    13 // This parameter can be modified through governance.
    14 defaultSlot0FeeProtocol = uint8(0)
    15
    16 // poolCreationFee is the fee that is charged when a user creates a pool.
    17 // The fee is denominated in GNS tokens.
    18 // This parameter can be modified through governance.
    19 defaultPoolCreationFee = int64(100_000_000) // 100_GNS
    20
    21 // withdrawalFeeBPS is the fee that is charged when a user withdraws their collected fees
    22 // The fee is denominated in BPS (Basis Points)
    23 // Example: 100 BPS = 1%
    24 // This parameter can be modified through governance.
    25 defaultWithdrawalFeeBPS = uint64(100)
    26
    27 defaultUnlocked = true
    28)
    29
    30func init(cur realm) {
    31 registerPoolV1(cur)
    32}
    33
    34func registerPoolV1(cur realm) {
    35 pool.RegisterInitializer(cross(cur), func(_ int, rlm realm, poolStore pool.IPoolStore) pool.IPool {
    36 access.AssertIsRlmCurrent(0, rlm)
    37
    38 err := initStoreData(0, rlm, poolStore)
    39 if err != nil {
    40 panic(err)
    41 }
    42
    43 emission.SetDefaultInitialPoolChecker(cross(rlm), func(poolPath string) bool {
    44 return pool.ExistsPoolPath(poolPath)
    45 })
    46
    47 return NewPoolV1(poolStore)
    48 })
    49}
    50
    51func initStoreData(_ int, rlm realm, poolStore pool.IPoolStore) error {
    52 if !poolStore.HasPools() {
    53 err := poolStore.SetPools(0, rlm, pool.NewPoolsTree())
    54 if err != nil {
    55 return err
    56 }
    57 }
    58
    59 if !poolStore.HasObservations() {
    60 err := poolStore.SetObservations(0, rlm, pool.NewObservationsTree())
    61 if err != nil {
    62 return err
    63 }
    64 }
    65
    66 if err := validatePoolObservations(poolStore); err != nil {
    67 return err
    68 }
    69
    70 if !poolStore.HasFeeAmountTickSpacing() {
    71 err := poolStore.SetFeeAmountTickSpacing(0, rlm, pool.NewDefaultFeeAmountTickSpacing())
    72 if err != nil {
    73 return err
    74 }
    75 }
    76
    77 if !poolStore.HasPoolCreationFee() {
    78 err := poolStore.SetPoolCreationFee(0, rlm, defaultPoolCreationFee)
    79 if err != nil {
    80 return err
    81 }
    82 }
    83
    84 pendingProtocolFees := make(map[string]int64)
    85 if poolStore.HasPendingProtocolFees() {
    86 pendingProtocolFees = poolStore.GetPendingProtocolFees()
    87 }
    88 if err := poolStore.SetPendingProtocolFees(0, rlm, pendingProtocolFees); err != nil {
    89 return err
    90 }
    91
    92 if !poolStore.HasSlot0FeeProtocol() {
    93 err := poolStore.SetSlot0FeeProtocol(0, rlm, defaultSlot0FeeProtocol)
    94 if err != nil {
    95 return err
    96 }
    97 }
    98
    99 if !poolStore.HasWithdrawalFeeBPS() {
    100 err := poolStore.SetWithdrawalFeeBPS(0, rlm, defaultWithdrawalFeeBPS)
    101 if err != nil {
    102 return err
    103 }
    104 }
    105
    106 if !poolStore.HasUnlocked() {
    107 err := poolStore.SetUnlocked(0, rlm, defaultUnlocked)
    108 if err != nil {
    109 return err
    110 }
    111 }
    112
    113 // Initialize swap start hook with no-op function
    114 if !poolStore.HasSwapStartHook() {
    115 noopSwapStart := func(cur realm, poolPath string, timestamp int64) {}
    116 err := poolStore.SetSwapStartHook(0, rlm, noopSwapStart)
    117 if err != nil {
    118 return err
    119 }
    120 }
    121
    122 // Initialize swap end hook with no-op function
    123 if !poolStore.HasSwapEndHook() {
    124 noopSwapEnd := func(cur realm, poolPath string) error {
    125 return nil
    126 }
    127 err := poolStore.SetSwapEndHook(0, rlm, noopSwapEnd)
    128 if err != nil {
    129 return err
    130 }
    131 }
    132
    133 // Initialize tick cross hook with no-op function
    134 if !poolStore.HasTickCrossHook() {
    135 noopTickCross := func(cur realm, poolPath string, tickId int32, zeroForOne bool, timestamp int64) {}
    136 err := poolStore.SetTickCrossHook(0, rlm, noopTickCross)
    137 if err != nil {
    138 return err
    139 }
    140 }
    141
    142 return nil
    143}
    144
    145// validatePoolObservations ensures every persisted pool owns an observation tree.
    146// CreatePool initializes the pair in one transaction; this check catches an
    147// implementation or upgrade that would otherwise leave a pool unusable later.
    148func validatePoolObservations(poolStore pool.IPoolStore) error {
    149 pools := poolStore.GetPools()
    150 observations := poolStore.GetObservations()
    151
    152 var validationErr error
    153 pools.Iterate("", "", func(poolPath string, _ any) bool {
    154 if !observations.Has(poolPath) {
    155 validationErr = ufmt.Errorf("expected observations for poolPath(%s) to exist", poolPath)
    156 return true
    157 }
    158 return false
    159 })
    160
    161 return validationErr
    162}
    163