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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v4 source realm

Package lastcall is a synthetic stocks desk on gno.land.

Overview

Package lastcall is a synthetic stocks desk on gno.land.

It is self-contained: it runs its own price feed (off-chain updaters push quotes, trusted by caller address, see feed.gno), issues a test-USD collateral token and synthetic stock tokens, and lets users trade them spot against the desk. There is no external oracle and no external liquidity — the desk is always the counterparty at its own quoted price.

All amounts are integers. USD values are micro-USD (6 decimals): $190.42 -> 190420000. Token amounts use 6 decimals too, so one whole share is 1_000000 units and lines up 1:1 with the price scale.

Functions 56

func AddMargin

crossing Action
1func AddMargin(cur realm, id uint64, amount int64)
source

AddMargin adds `amount` tUSD micro from the caller to their own position, lowering its leverage. It trades nothing, so it applies at once.

func AllLiquidatable

Action
1func AllLiquidatable(offset, count int) string
source

AllLiquidatable lists, within one page of open positions, the ids at or below maintenance on a fresh quote, ';'-joined, for the keeper.

func AvgEntry

Action
1func AvgEntry(ticker string, owner address) int64
source

AvgEntry returns the owner's average entry price for ticker in micro-USD per share, or 0 if they hold none.

func Buy

crossing Action
1func Buy(cur realm, ticker string, stockAmount int64) uint64
source

Buy places an order for stockAmount units (6 dp) of sTicker. It locks the cost at the worst price it accepts and refunds the difference when it fills. Returns the order id.

func CancelOrder

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

CancelOrder refunds the caller's pending limit order. Market orders, buys and sells cannot be cancelled: they fill or are refunded on the next price.

func ClosePartial

crossing Action
1func ClosePartial(cur realm, id uint64, closeSize int64)
source

ClosePartial asks to close `closeSize` units (6 dp) of the caller's position on the first price observed after the request. Allowed while the market is closed.

func ClosePerp

crossing Action
1func ClosePerp(cur realm, id uint64)
source

ClosePerp asks to close the caller's whole position. It closes on the first price observed after the request (FillClose).

func Delever

crossing Action
1func Delever(cur realm, id uint64)
source

Delever cuts a position held above closedMaxLeverage while the market is closed, at the desk price, to the size its margin carries at that leverage. Permissionless.

func FaucetUSD

crossing Action
1func FaucetUSD(cur realm)
source

FaucetUSD mints 10,000 tUSD to the caller. Open faucet — demo only.

func FillClose

crossing Action
1func FillClose(cur realm, id uint64)
source

FillClose closes a requested position on the first price observed after the request, or drops a request that waited longer than orderTTL. Permissionless.

func FillOrder

crossing Action
1func FillOrder(cur realm, id uint64) uint64
source

FillOrder executes an order on the first price observed after it was placed, or refunds a market order, buy or sell that the price moved past or that waited longer than orderTTL. Permissionless. Returns the new position id for a perp order that filled, otherwise 0.

func GetPrice

Action
1func GetPrice(ticker string) (int64, int64)
source

GetPrice returns the desk price for a ticker and its observation time. Panics if unknown.

func IsFresh

Action
1func IsFresh(ticker string) bool
source

IsFresh reports whether a ticker has a price young enough to trade against.

func IsMarketOpen

Action
1func IsMarketOpen() bool
source

IsMarketOpen reports whether a quorum of updaters say the stock market is open. While it is not, new perps are held to closedMaxLeverage and positions above it can be cut down to it (Delever). A limit above that leverage fills only on a price observed after the open, never on the last pre-open quote.

func LastCallAt

Action
1func LastCallAt(ticker string) int64
source

LastCallAt is the time after which the stored price no longer allows a trade, or 0 before the first price.

func Liquidate

crossing Action
1func Liquidate(cur realm, id uint64)
source

Liquidate closes an underwater position. Permissionless: anyone (the desk's keeper bot, or the UI) may call it once the position is at maintenance.

func LockedUSD

Action
1func LockedUSD() int64
source

LockedUSD is the part of the reserve owed back as margin and limit escrow.

func MarketVoteOf

Action
1func MarketVoteOf(u address) string
source

MarketVoteOf returns an updater's recorded view of the market: "open", "closed" or "none".

func OIOf

Action
1func OIOf(ticker string) string
source

OIOf returns a market's open-interest state, comma-separated: oiLong,oiShort,capPerSide,maxLev (notional micro-USD; maxLev a plain integer).

func OpenPerp

crossing Action
1func OpenPerp(cur realm, ticker string, isLong bool, size int64, margin int64) uint64
source

OpenPerp places a market order for a long or short of `size` stock units (6 dp) backed by `margin` tUSD micro, plus the open fee. It fills on the next price if that is within marketBandBps of the price now, else it is refunded. Returns the order id; the position id comes with the OrderFill event.

func OrderStatus

Action
1func OrderStatus(id uint64) string
source

OrderStatus is "pending", "filled", "filled:<position id>" for a perp order, "refunded:<reason>", or "unknown".

func OrdersOf

Action
1func OrdersOf(owner address) string
source

OrdersOf returns an owner's pending orders, ';'-joined, fields comma-separated: id,kind,ticker,L|S,size,margin,limit,mark,placedAt (money and size at 6 dp).

func Overleveraged

Action
1func Overleveraged(offset, count int) string
source

Overleveraged lists, within one page of open positions, the ids Delever would cut now, ';'-joined, for the keeper. Empty while the market is open.

func PerpsOf

Action
1func PerpsOf(owner address) string
source

PerpsOf returns the caller's open positions, one per line, fields comma- separated: id,ticker,L|S,size,entry,margin,mark,pnl,liq,stopLoss,takeProfit,closing. Money and size are integers at 6 dp; mark/pnl/liq are computed live. Stop prices are 0 when unset; closing is the size of a close waiting for the next price.

func PlaceLimit

crossing Action
1func PlaceLimit(cur realm, ticker string, isLong bool, size, margin, limit int64) uint64
source

PlaceLimit places an order to open a perp once the desk price reaches `limit` (long: at or below, short: at or above). Returns the order id.

func PoolDeposit

crossing Action
1func PoolDeposit(cur realm, amount int64) int64
source

PoolDeposit pulls `amount` tUSD micro from the caller into the desk reserve and mints pool shares at the current share price. Returns the shares minted.

func PoolInfo

Action
1func PoolInfo() string
source

PoolInfo returns pool-wide figures, comma-separated: totalShares,poolAssets,feesAll,deskReserve (all micro, 6 dp).

func PoolOf

Action
1func PoolOf(owner address) string
source

PoolOf returns one depositor's position, comma-separated: shares,assets where assets is the current tUSD micro value of those shares.

func PoolSharePrice

Action
1func PoolSharePrice() int64
source

PoolSharePrice is the value of one share in micro-USD, scaled by 1e6 (so a fresh pool reads 1_000000 == $1.000000 per share). Returns 1e6 when empty.

func PoolWithdraw

crossing Action
1func PoolWithdraw(cur realm, shares int64) int64
source

PoolWithdraw burns `shares` from the caller and pays their pro-rata slice of the pool in tUSD from the desk reserve. Returns the tUSD micro paid out.

func QuoteBuy

Action
1func QuoteBuy(ticker string, stockAmount int64) int64
source

QuoteBuy / QuoteSell are read-only helpers for the UI: the tUSD cost/proceeds of trading stockAmount units at the current price.

func ReadyCloses

Action
1func ReadyCloses(offset, count int) string
source

ReadyCloses lists, within one page of open positions, the ids FillClose would act on now, ';'-joined, for the keeper.

func ReadyOrders

Action
1func ReadyOrders(offset, count int) string
source

ReadyOrders lists, within one page of pending orders, the ids FillOrder would act on now, ';'-joined, for the keeper.

func ReadyStops

Action
1func ReadyStops(offset, count int) string
source

ReadyStops lists, within one page of open positions, the ids whose stop TriggerStop would act on now, ';'-joined, for the keeper.

func SeedUSD

crossing Action
1func SeedUSD(cur realm, amount int64)
source

SeedUSD mints tUSD into the desk reserve so it can pay out on sells and in-the-money perps. Admin only — the desk's bootstrap liquidity.

func Sell

crossing Action
1func Sell(cur realm, ticker string, stockAmount int64) uint64
source

Sell places an order to sell stockAmount units of sTicker. The shares are burned now and minted back if the order is refunded. Returns the order id.

func SetMarketOpen

crossing Action
1func SetMarketOpen(cur realm, open bool)
source

SetMarketOpen records the caller's view of the US stock market.

func SetMaxLev

crossing Action
1func SetMaxLev(cur realm, ticker string, lev int64)
source

SetMaxLev lowers (never raises) the max leverage for a market. 0 restores the global default.

func SetOICap

crossing Action
1func SetOICap(cur realm, ticker string, perSide int64)
source

SetOICap sets the per-side open-interest cap for a market (micro-USD). 0 restores the default.

func SetPrices

crossing Action
1func SetPrices(cur realm, quotes string, observedAt int64)
source

SetPrices records the caller's quotes, "TICKER:microUSD" pairs joined by ',', all observed at observedAt, and forms a desk price where a quorum agrees. A stamp ahead of the block time is lowered to it, so no price is ever dated after a request that could already see it.

func SetStops

crossing Action
1func SetStops(cur realm, id uint64, stopLoss, takeProfit int64)
source

SetStops sets, updates or clears the stop-loss and take-profit of the caller's own position. Each price is micro-USD per share; pass 0 to clear that leg.

func TriggerStop

crossing Action
1func TriggerStop(cur realm, id uint64)
source

TriggerStop closes a position whose stop-loss or take-profit has been reached, at the current mark. Permissionless (keeper / UI); panics if no stop is set or not reached, so the keeper simply retries later.

Types 1

type Price

struct
1type Price struct {
2	Value      int64 // micro-USD per share
3	ObservedAt int64 // unix seconds, the oldest observation behind this price
4}
source

Price is quoted in micro-USD per whole share.

Dependencies

Source Files 17