func AddMargin
crossing ActionAddMargin adds `amount` tUSD micro from the caller to their own position, lowering its leverage. It trades nothing, so it applies at once.
Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.
Package lastcall is a synthetic stocks desk on gno.land.
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.
AddMargin adds `amount` tUSD micro from the caller to their own position, lowering its leverage. It trades nothing, so it applies at once.
AllLiquidatable lists, within one page of open positions, the ids at or below maintenance on a fresh quote, ';'-joined, for the keeper.
AvgEntry returns the owner's average entry price for ticker in micro-USD per share, or 0 if they hold none.
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.
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.
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.
ClosePerp asks to close the caller's whole position. It closes on the first price observed after the request (FillClose).
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.
DeskReserveUSD is the desk's own tUSD balance.
FaucetUSD mints 10,000 tUSD to the caller. Open faucet — demo only.
FillClose closes a requested position on the first price observed after the request, or drops a request that waited longer than orderTTL. Permissionless.
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.
GetPrice returns the desk price for a ticker and its observation time. Panics if unknown.
IsFresh reports whether a ticker has a price young enough to trade against.
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.
LastCallAt is the time after which the stored price no longer allows a trade, or 0 before the first price.
Liquidate closes an underwater position. Permissionless: anyone (the desk's keeper bot, or the UI) may call it once the position is at maintenance.
LockedUSD is the part of the reserve owed back as margin and limit escrow.
MarketVoteOf returns an updater's recorded view of the market: "open", "closed" or "none".
OIOf returns a market's open-interest state, comma-separated: oiLong,oiShort,capPerSide,maxLev (notional micro-USD; maxLev a plain integer).
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.
OpenPerpCount and OrderCount tell the keeper how many pages to read.
OrderStatus is "pending", "filled", "filled:<position id>" for a perp order, "refunded:<reason>", or "unknown".
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).
Overleveraged lists, within one page of open positions, the ids Delever would cut now, ';'-joined, for the keeper. Empty while the market is open.
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.
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.
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.
PoolInfo returns pool-wide figures, comma-separated: totalShares,poolAssets,feesAll,deskReserve (all micro, 6 dp).
PoolOf returns one depositor's position, comma-separated: shares,assets where assets is the current tUSD micro value of those shares.
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.
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.
QuoteBuy / QuoteSell are read-only helpers for the UI: the tUSD cost/proceeds of trading stockAmount units at the current price.
ReadyCloses lists, within one page of open positions, the ids FillClose would act on now, ';'-joined, for the keeper.
ReadyOrders lists, within one page of pending orders, the ids FillOrder would act on now, ';'-joined, for the keeper.
ReadyStops lists, within one page of open positions, the ids whose stop TriggerStop would act on now, ';'-joined, for the keeper.
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.
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.
SetMarketOpen records the caller's view of the US stock market.
SetMaxLev lowers (never raises) the max leverage for a market. 0 restores the global default.
SetOICap sets the per-side open-interest cap for a market (micro-USD). 0 restores the default.
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.
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.
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.
Updaters lists the updater addresses, comma-separated.