Skip to content
UnityNodesPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

Repository files navigation

LastCall: a synthetic stock desk on Gno.land

Practise trading US stocks with up to 10× on Gno.land: test money, and the chain refuses any trade on a quote older than ten minutes.

Spot, perpetuals, limit orders and a fee pool for five synthetic stocks (sNVDA, sAAPL, sTSLA, sMSFT, sAMZN), settled in a test dollar (tUSD) by one Gno realm on the Onyx testnet.

The rule behind the name: if a quote is older than ten minutes, last call has passed. The realm itself refuses every trade that moves value against it. A dead keeper or a dead price source stops the desk instead of leaving it trading on old numbers.

Everything here is test money. Nothing is a security or grants rights in any company.

LastCall perpetuals page with an open position on Onyx

Try it

Without a wallet: open the Perps page and press Try a long or Try a short. A demo wallet on the server opens one real position on Onyx ($100 test margin at 2×), shows the block and transaction, and closes it when you ask or after 10 minutes. Each visitor gets 3 tries an hour, 40 a day for everyone.

With a wallet:

  1. Get GNOT for gas from https://faucet.gno.land (choose Onyx). A few GNOT covers fees and storage deposits.
  2. Open the app, connect Adena, press Get 10,000 on the Faucet page.
  3. Buy a stock on Spot, open a long or short on Perps, deposit on Earn.

Every market, chart and pool figure is readable without connecting anything; they come straight from the chain. Spot and Perps count down the seconds left before the current quote hits last call. Portfolio lists your past trades from the public Onyx indexer.

Agents

The realm needs no LastCall code to be traded: an agent with gnomcp can open and close a position with two calls, using its own key. tools/gnomcp has a small client and the transactions of a recorded run on Onyx. Every trade emits a chain event (Buy, Sell, PerpOpen, PerpClose, LimitPlace, LimitCancel, LimitFill, PoolDeposit, PoolWithdraw, each with the owner), so an agent or indexer can rebuild any account's history.

What the desk does

Feature Rule
Spot mint on buy, burn on sell, 0.30% each side
Perpetuals long or short, up to 10× while the US market is open and 2× while it is closed, isolated margin, 0.10% per side, 10%/yr borrow fee
Limit orders margin and fee locked up front; filled by anyone once the price is reached, never past the limit once skew impact is added; the fee is charged on the size actually filled; above 2× they wait for the market to open
Stop-loss and take-profit per position, executed by anyone once reached; refused while the reserve cannot pay the position in full
Liquidation permissionless at 10% of margin left, counted after the accrued borrow fee
Open interest $250,000 per side per market by default; the side that deepens the skew pays up to 1% on entry
Locked reserve open margin and limit escrow are set aside; profit, spot sales and pool withdrawals are paid only from what is left; pool deposits pause while what is left is smaller than the pool
Fee pool share-based; collects the desk's fees, which reach the share price evenly over 24 hours; smallest holding is 0.1 share
Last call quotes older than 600 s block buy, sell, open, close, liquidate, stop and limit fills
Keeper lists stops, limit orders and liquidations are read in pages of up to 200

All amounts are int64 micro-units (6 decimals). Every multiply-then-divide goes through a 128-bit mulDiv, because the Gno VM wraps int64 overflow silently.

Trust model and limits

  • Prices are trusted. One keeper key pushes them. Whoever holds it sets the price. There is no independent oracle. The keeper key is separate from the admin key: it can set prices and the market-hours flag, but cannot move funds or change roles. It pushes a Yahoo quote only when Nasdaq does not contradict it by more than 2%.
  • The ten minutes measure the keeper, not the market. Outside US hours the sources return the last close and the desk keeps trading on it, with new perps capped at 2× until the open.
  • Quotes update every few minutes, so a trader who watches the real market can act before the next push. A real-money version needs a faster oracle and a spread.
  • The admin seeds the reserve and it is the counterparty. The fee pool earns fees only; trader wins and losses settle against the reserve and do not change the pool share price.
  • The reserve carries gap risk. Margin is isolated and there is no funding, so someone holding an equal long and short gains from a large jump between two quotes (a weekend or earnings gap): the losing side stops at its margin, the winning side is paid in full while free reserve lasts. The 2× cap while the market is closed makes positions opened before a gap smaller, it does not remove the risk. A real-money desk would need net exposure limits, funding or a gap surcharge.
  • If the free reserve runs short, a winning perp closed by its owner pays back the margin plus whatever is free (the app asks first), a take-profit waits, and a spot sale is refused until the reserve is topped up.
  • Storage deposits go to whoever frees the storage. Opening a position locks about 0.55 GNOT of the owner's storage deposit; if someone else closes it through a stop or liquidation, Gno refunds that deposit to the caller.
  • The tUSD faucet is unlimited by design on testnet.

Layout

gno/r/lastcall/   the realm and its tests
web/              Vite multi-page app, vanilla JS; reads the RPC and the Onyx indexer directly
bot/              keeper (prices, liquidations, stops, limit fills, candles) and the demo wallet service
tools/gnomcp/     a minimal MCP client for trading the realm as an agent
ops/              systemd units, Caddy site and ship script
deploy.sh         publish the realm and seed the reserve

Run it

Frontend:

cd web
pnpm install
pnpm dev

VITE_RPC=http://127.0.0.1:26657 points a build at a local gnodev chain.

Keeper (needs the updater key):

cp bot/.env.example bot/.env
node bot/pricebot.mjs

Test

Contract (gno v1.8.0):

gno test -C gno/r/lastcall .

Keeper, demo wallet and countdown:

node --test bot/*.test.mjs web/src/lib/*.test.mjs

48 contract tests and 29 JavaScript tests. The contract tests include role checks, the closed-market cap and full caller flows: large deposits and positions that used to wrap, stale quotes, an instant skew round trip that must not profit, limit orders filled after a price gap, liquidation, pool share inflation, fee capture by a last-second deposit and a reserve that cannot cover a winner.

Deploy your own

Set the module path in gno/r/lastcall/gnomod.toml to your own address, put your keybase in .gnokey/ and its password in .gnokey.pass (both are gitignored), then:

UPDATER=<keeper address> bash deploy.sh

UPDATER hands the price role to the keeper's own key; without it the deployer stays the updater. Update desk in web/src/lib/chain.js; ops/ship.sh reads the module path from gnomod.toml and hands it to both services. The realm uses about 158 KB of storage, so the deployer needs roughly 16 GNOT. A price push costs 0.0144 GNOT, about 7 GNOT a day at the default 180 s interval. Trade calls are sent with a 40M gas limit (0.048 GNOT): on a local chain with 160 open positions and 160 limit orders, opening a position used 20M and filling a limit order 26M.

ops/ship.sh expects two keystores, each with its own password: the keeper in ~/.config/lastcall/keeper-keys and keeper.password, the demo wallet in try-keys and try.password (the folder is KEYS). Each service gets only its own keystore, copied in when it starts; neither can read a home directory.

Credits

Built for the Gnome Tavern hackathon. Charts by Lightweight Charts; the bell mark is bell-ringing from Phosphor Icons (MIT).

License

MIT © Unity Nodes. See LICENSE.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages