Search Apps Documentation Source Content File Folder Download Copy Actions Download

orderbook package

Overview

Package orderbook is spike v2 of the GnoPulse on-chain order engine: it turns the proven one-shot Execute(args) (see r/<addr>/limitspike) into a persistent order book — CreateOrder stores an intent, a permissionless keeper pokes Execute(orderID), and the realm RE-VALIDATES the trigger on-chain before swapping on GnoSwap for the owner.

Two order kinds share one machine:

  • "dca": time-gated. Executes `amountIn` wugnot every `intervalBlocks`, up to `runs` times.
  • "limit": price-gated. Executes once when the pool tick >= minTick.

Non-custodial: the realm never holds user funds. The owner grants THIS realm a wugnot allowance; each fill pulls exactly `amountIn`, swaps wugnot->GNS, and forwards the GNS to the owner. The keeper is trustless — it only controls TIMING; the realm re-checks the trigger, so a keeper can never force an early or off-limit fill. Cancel = deactivate (or the owner simply revokes the allowance).

Functions

CancelOrder

func CancelOrder(cur realm, id uint64)

CancelOrder deactivates an order. Owner only. No funds are held, so this just stops the keeper from filling it (the owner may also revoke the wugnot allowance).

Param

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/g1cz86tl8vnh9956cpuu43ksjy7kmur745wdjxsc/orderbook" -func "CancelOrder" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "test-13" -remote "https://rpc.test13.testnets.gno.land" ADDRESSgnokey query -remote "https://rpc.test13.testnets.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/g1cz86tl8vnh9956cpuu43ksjy7kmur745wdjxsc/orderbook" -func "CancelOrder" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "test-13" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.test13.testnets.gno.land" call.tx
  

CreateOrder

func CreateOrder(cur realm, kind string, amountIn, minOut int64, minTick int32, intervalBlocks, runs int64) uint64

CreateOrder stores an order intent and returns its id. The caller must first Approve THIS realm as a wugnot spender for at least amountIn (for dca, amountIn*runs so every fill is covered).

Example
1kind "dca":   intervalBlocks>0 and runs>=1; minTick ignored; first fill is due immediately.
2kind "limit": minTick set; runs forced to 1; intervalBlocks ignored.

Params

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/g1cz86tl8vnh9956cpuu43ksjy7kmur745wdjxsc/orderbook" -func "CreateOrder" -args $'' -args $'' -args $'' -args $'' -args $'' -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "test-13" -remote "https://rpc.test13.testnets.gno.land" ADDRESSgnokey query -remote "https://rpc.test13.testnets.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/g1cz86tl8vnh9956cpuu43ksjy7kmur745wdjxsc/orderbook" -func "CreateOrder" -args $'' -args $'' -args $'' -args $'' -args $'' -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "test-13" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.test13.testnets.gno.land" call.tx
  

Execute

func Execute(cur realm, id uint64) (int32, int64)

Execute runs one fill. PERMISSIONLESS — any keeper may poke it; the realm re-validates the trigger on-chain, so a keeper controls only TIMING, never whether a fill is allowed. Returns (tickAtExec, gnsOut).

Param

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/g1cz86tl8vnh9956cpuu43ksjy7kmur745wdjxsc/orderbook" -func "Execute" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "test-13" -remote "https://rpc.test13.testnets.gno.land" ADDRESSgnokey query -remote "https://rpc.test13.testnets.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/g1cz86tl8vnh9956cpuu43ksjy7kmur745wdjxsc/orderbook" -func "Execute" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "test-13" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.test13.testnets.gno.land" call.tx
  

GetOrderJSON

func GetOrderJSON(id uint64) string

Param

Command

gnokey query vm/qeval -remote "https://rpc.test13.testnets.gno.land" -data "gno.land/r/g1cz86tl8vnh9956cpuu43ksjy7kmur745wdjxsc/orderbook.GetOrderJSON()"

Result

ListActiveJSON

func ListActiveJSON(offset, limit int) string

ListActiveJSON returns up to `limit` active orders from `offset` — the keeper's scan feed.

Params

Command

gnokey query vm/qeval -remote "https://rpc.test13.testnets.gno.land" -data "gno.land/r/g1cz86tl8vnh9956cpuu43ksjy7kmur745wdjxsc/orderbook.ListActiveJSON(,)"

Result

Render

func Render(_ string) string

Param

Command

gnokey query vm/qeval -remote "https://rpc.test13.testnets.gno.land" -data "gno.land/r/g1cz86tl8vnh9956cpuu43ksjy7kmur745wdjxsc/orderbook.Render()"

Result

Tick

func Tick() int32

Command

gnokey query vm/qeval -remote "https://rpc.test13.testnets.gno.land" -data "gno.land/r/g1cz86tl8vnh9956cpuu43ksjy7kmur745wdjxsc/orderbook.Tick()"

Result