const ErrNilInitializer
ErrNilInitializer is raised by RegisterInitializer for a nil factory.
Package limit is the GnoSwap limit order realm.
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:
ErrNilInitializer is raised by RegisterInitializer for a nil factory.
ErrSpoofedRealm is returned when a store write gets a non-current realm.
Store layout. Tree keys are built by the plimit key helpers.
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.
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.
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.
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.
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.
1func ExecuteOrder(cur realm, orderID uint64, maxAmountIn int64, poolFee uint32, sqrtPriceLimitX96 string) (int64, int64)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.
ExistsOrder reports whether an order is pending. Settled orders are deleted.
Parameters:
Returns:
GetConfig returns a detached copy of the current global configuration.
Returns:
GetExecutionFeeRate returns the execution fee rate snapshotted into new orders.
Returns:
GetImplementationPackagePath returns the active implementation path.
GetMaxCleanupBatchSize returns the most orders one CleanupExpiredOrders call examines.
Returns:
GetMaxSlippageBps returns the slippage cap for new orders.
Returns:
GetMinMakingAmount returns the minimum input amount for new orders.
Returns:
GetNextOrderID returns the ID the next created order receives.
Returns:
GetOrder returns a detached pending order, or nil after it is settled.
Parameters:
Returns:
GetOrderDeadlines returns the allowed order duration range for new orders.
Returns:
GetOrders returns a live read-only view of pending orders.
Returns:
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:
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:
Returns:
GetPendingExecutionFees returns the read-only index of pending execution fees.
Returns:
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.
NewLimitOrderStore wraps the domain KV store.
1func NewSwapCallback(_ int, rlm realm, tokenIn string, zeroForOne bool, maxAmountIn int64) func(cur realm, amount0Delta, amount1Delta int64, marker *pool.CallbackMarker) errorNewSwapCallback 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.
1func RegisterInitializer(cur realm, initializer func(_ int, rlm realm, orderStore plimit.ILimitOrderStore) plimit.ILimitOrder)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.
SetExecutionFeeRate sets the execution fee rate snapshotted into new orders, in basis points of gross output. Admin or governance only.
SetMaxCleanupBatchSize caps the orders one CleanupExpiredOrders call examines, bounding its gas. Admin or governance only.
SetMaxSlippageBps sets the slippage cap for new orders in [0, 10000] bps. Existing orders keep their slippage. Admin or governance only.
SetMinMakingAmount sets the minimum input amount for new orders, in raw token units. Existing orders are unaffected. Admin or governance only.
SetOrderDeadlines sets the allowed order duration range for new orders, in seconds. Admin or governance only.
UpgradeImpl activates a previously registered version by package path. Admin or governance only.