Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

limit source realm

Package limit is the GnoSwap limit order realm.

Overview

Package limit is the GnoSwap limit order realm.

Users escrow makingAmount of tokenIn for takingAmount of tokenOut before expiresAt. Authorized keepers fill orders on a whitelisted direct pool, without the router, choosing the pool fee tier and swap price limit for each fill. Partial fills leave unsold input in escrow; each fill pays the owner immediately after deducting the order's snapshotted execution fee, while enforcing the order's slippage-adjusted owner-net exchange ratio. Owners can cancel for the remaining input, and anyone can refund expired orders through bounded cleanup. Settled orders are removed from the indexes.

This package is the permanent entry point. It owns the escrow address, the KV store shared by every version, and the upgrade switch; the business logic lives in a registered implementation (impl/v0).

Files:

  • proxy.gno: state-changing entry points
  • getter.gno: read-only queries
  • store.gno: KV store and store keys
  • state.gno: realm state and the active implementation
  • upgrade.gno: implementation registration and upgrades
  • swap_callback.gno: authenticated pool callback paying escrowed input

Constants 3

const ErrNilInitializer

1const ErrNilInitializer = "nil initializer"
source

ErrNilInitializer is raised by RegisterInitializer for a nil factory.

const ErrSpoofedRealm

1const ErrSpoofedRealm = "spoofed realm"
source

ErrSpoofedRealm is returned when a store write gets a non-current realm.

const StoreKeyOrders, StoreKeyOrdersByOwner, StoreKeyPendingExecutionFees, StoreKeyNextOrderID, StoreKeyConfig

1const (
2	StoreKeyOrders               StoreKey = "orders"
3	StoreKeyOrdersByOwner        StoreKey = "ordersByOwner"
4	StoreKeyPendingExecutionFees StoreKey = "pendingExecutionFees"
5	StoreKeyNextOrderID          StoreKey = "nextOrderID"
6	StoreKeyConfig               StoreKey = "config"
7)
source

Store layout. Tree keys are built by the plimit key helpers.

Example
1orders         OrderKey -> *Order, pending orders only
2ordersByOwner  OwnerOrderKey -> orderID, pending orders only
3pendingExecutionFees tokenPath -> int64, held until the protocol fee collector accepts them
4nextOrderID    uint64
5config         *Config

Functions 30

func CancelOrder

crossing Action
1func CancelOrder(cur realm, orderID uint64) int64
source

CancelOrder refunds the remaining input and removes the order from the indexes. A past-deadline refund uses the expired event. It returns the refunded input.

Owner only. Reverts while withdrawals are halted for limit orders.

func CleanupExpiredOrders

crossing Action
1func CleanupExpiredOrders(cur realm, startAfterOrderID uint64, maxOrders int) (int, uint64)
source

CleanupExpiredOrders refunds pending orders after their deadline. Anyone may call it.

One call examines at most min(maxOrders, maxCleanupBatchSize) orders after startAfterOrderID, in ID order. It returns the number of orders expired and the cursor for the next call; repeat until the cursor is 0. Reverts while withdrawals are halted for limit orders.

func CleanupExpiredOrdersByIDs

crossing Action
1func CleanupExpiredOrdersByIDs(cur realm, orderIDs string) (int, string)
source

CleanupExpiredOrdersByIDs refunds only the named expired orders. orderIDs is a strictly increasing comma-separated list of positive decimal order IDs. Existing unexpired or underfunded orders are returned for retry. Reverts while withdrawals are halted for limit orders.

func CollectPendingExecutionFee

crossing Action
1func CollectPendingExecutionFee(cur realm, tokenPath string) (int64, int64)
source

CollectPendingExecutionFee forwards fees pending for tokenPath to the protocol fee realm without another fill. Anyone may call it; the caller receives nothing. Returns the amount forwarded and the amount left pending. Reverts while withdrawals are halted for Limit orders.

func CreateOrder

crossing Action
 1func CreateOrder(
 2	cur realm,
 3	tokenIn string,
 4	tokenOut string,
 5	makingAmount int64,
 6	takingAmount int64,
 7	slippageBps int64,
 8	expiresAt int64,
 9	baseToken string,
10) uint64
source

CreateOrder escrows makingAmount of tokenIn for takingAmount of tokenOut. Each fill supplies its pool fee tier and price limit. slippageBps=0 enforces the making/taking ratio or better. expiresAt must be positive and within the configured duration bounds. The execution fee rate is snapshotted into each new order. baseToken must be tokenIn (Sell) or tokenOut (Buy); it is emitted only as creation metadata and does not affect the order's execution terms. The caller must first approve Address() for makingAmount. Reverts while execution is halted for Limit orders.

func ExecuteOrder

crossing Action
1func ExecuteOrder(cur realm, orderID uint64, maxAmountIn int64, poolFee uint32, sqrtPriceLimitX96 string) (int64, int64)
source

ExecuteOrder fills up to maxAmountIn through the order's token pair at poolFee. A nonzero sqrtPriceLimitX96 stops at that pool price and may leave input unspent in escrow. Zero requires maxAmountIn to be consumed in full. The order's minimum owner-net output is enforced on the actual input. Returns actual input and pool output before the order's execution fee; the owner is paid immediately after that fee is deducted. The immediate caller must be authorized for ExecuteOrder by the shared keeper policy. Reverts while execution or withdrawals are halted for limit orders.

func ExistsOrder

Action
1func ExistsOrder(orderID uint64) bool
source

ExistsOrder reports whether an order is pending. Settled orders are deleted.

Parameters:

  • orderID: order to look up

Returns:

  • bool: true while the order is pending

func GetConfig

Action
1func GetConfig() *plimit.Config
source

GetConfig returns a detached copy of the current global configuration.

Returns:

  • *plimit.Config: copy of the stored configuration

func GetExecutionFeeRate

Action
1func GetExecutionFeeRate() int64
source

GetExecutionFeeRate returns the execution fee rate snapshotted into new orders.

Returns:

  • int64: execution fee rate, in basis points of gross output

func GetMaxCleanupBatchSize

Action
1func GetMaxCleanupBatchSize() int64
source

GetMaxCleanupBatchSize returns the most orders one CleanupExpiredOrders call examines.

Returns:

  • int64: maximum cleanup batch size

func GetMaxSlippageBps

Action
1func GetMaxSlippageBps() int64
source

GetMaxSlippageBps returns the slippage cap for new orders.

Returns:

  • int64: maximum slippage, in basis points

func GetMinMakingAmount

Action
1func GetMinMakingAmount() int64
source

GetMinMakingAmount returns the minimum input amount for new orders.

Returns:

  • int64: minimum makingAmount, in raw token units

func GetNextOrderID

Action
1func GetNextOrderID() uint64
source

GetNextOrderID returns the ID the next created order receives.

Returns:

  • uint64: next order ID

func GetOrder

Action
1func GetOrder(orderID uint64) *plimit.Order
source

GetOrder returns a detached pending order, or nil after it is settled.

Parameters:

  • orderID: order to look up

Returns:

  • *plimit.Order: copy of the order; nil when it is not pending

func GetOrderDeadlines

Action
1func GetOrderDeadlines() (int64, int64)
source

GetOrderDeadlines returns the allowed order duration range for new orders.

Returns:

  • int64: shortest allowed expiresAt - createdAt, in seconds
  • int64: longest allowed expiresAt - createdAt, in seconds

func GetOrders

Action
1func GetOrders() *rotree.ReadOnlyTree
source

GetOrders returns a live read-only view of pending orders.

Returns:

  • *rotree.ReadOnlyTree: plimit.OrderKey(orderID) -> *plimit.Order; each order read from the view is detached from stored state

func GetOrdersByOwner

Action
1func GetOrdersByOwner() *rotree.ReadOnlyTree
source

GetOrdersByOwner returns the read-only owner index of pending orders. Iterate the [plimit.OwnerOrderPrefix(owner), plimit.PrefixEnd(prefix)) range for one owner's orders in ID order, choosing the page size.

Returns:

  • *rotree.ReadOnlyTree: plimit.OwnerOrderKey(owner, orderID) -> uint64 orderID

func GetPendingExecutionFeeAmount

Action
1func GetPendingExecutionFeeAmount(tokenPath string) int64
source

GetPendingExecutionFeeAmount returns execution fees held for tokenPath until the protocol fee realm accepts them. A later fill with the same output token retries collection.

Parameters:

  • tokenPath: fee token path

Returns:

  • int64: pending execution fee, in raw token units

func GetPendingExecutionFees

Action
1func GetPendingExecutionFees() *rotree.ReadOnlyTree
source

GetPendingExecutionFees returns the read-only index of pending execution fees.

Returns:

  • *rotree.ReadOnlyTree: tokenPath -> int64 pending amount

func NewBPTreeN

Action
1func NewBPTreeN(fanout int) *bptree.BPTree
source

NewBPTreeN allocates an empty B+tree in the order/limit realm. Implementations create the store trees through it, so the trees are owned by the realm that stores them.

func NewSwapCallback

Action
1func NewSwapCallback(_ int, rlm realm, tokenIn string, zeroForOne bool, maxAmountIn int64) func(cur realm, amount0Delta, amount1Delta int64, marker *pool.CallbackMarker) error
source

NewSwapCallback binds payment to this proxy's custody, the order's input token and its input budget. Only code already executing in the proxy's current realm context can create it. The closure is declared here so pool callbacks retain proxy custody rather than paying from an implementation realm.

func RegisterInitializer

crossing Action
1func RegisterInitializer(cur realm, initializer func(_ int, rlm realm, orderStore plimit.ILimitOrderStore) plimit.ILimitOrder)
source

RegisterInitializer registers an implementation version. Each version calls it from init with a factory that receives the shared store. Only packages under this realm's path may register, and the first registration becomes active. A nil initializer is rejected before its version path is registered.

func SetExecutionFeeRate

crossing Action
1func SetExecutionFeeRate(cur realm, executionFeeRate int64)
source

SetExecutionFeeRate sets the execution fee rate snapshotted into new orders, in basis points of gross output. Admin or governance only.

func SetMaxCleanupBatchSize

crossing Action
1func SetMaxCleanupBatchSize(cur realm, maxCleanupBatchSize int64)
source

SetMaxCleanupBatchSize caps the orders one CleanupExpiredOrders call examines, bounding its gas. Admin or governance only.

func SetMaxSlippageBps

crossing Action
1func SetMaxSlippageBps(cur realm, maxSlippageBps int64)
source

SetMaxSlippageBps sets the slippage cap for new orders in [0, 10000] bps. Existing orders keep their slippage. Admin or governance only.

func SetMinMakingAmount

crossing Action
1func SetMinMakingAmount(cur realm, minMakingAmount int64)
source

SetMinMakingAmount sets the minimum input amount for new orders, in raw token units. Existing orders are unaffected. Admin or governance only.

func SetOrderDeadlines

crossing Action
1func SetOrderDeadlines(cur realm, minDuration int64, maxDuration int64)
source

SetOrderDeadlines sets the allowed order duration range for new orders, in seconds. Admin or governance only.

func UpgradeImpl

crossing Action
1func UpgradeImpl(cur realm, packagePath string)
source

UpgradeImpl activates a previously registered version by package path. Admin or governance only.

Types 1

type StoreKey

ident
1type StoreKey string
source

StoreKey is a key of the limit order KV store.

Methods on StoreKey

func String

method on StoreKey
1func (s StoreKey) String() string
source

Dependencies

Source Files 9