// 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. package lastcall import ( "gno.land/p/nt/seqid/v0" "gno.land/p/nt/ufmt/v0" ) var ( admin address // deployer; may rotate admin, manage updaters, seed the reserve deskAddr address // this realm's own address — the escrow / reserve account nextTokID seqid.ID // unique id source for every grc20 token this realm mints ) func init(cur realm) { admin = cur.Previous().Address() updaters = []address{admin} deskAddr = cur.Address() initUSD(cur) // create the tUSD collateral token initStocks(cur) // create the default synthetic stock markets } // --- admin --- func SetAdmin(cur realm, a address) { assertAdmin(cur) if !a.IsValid() { panic("desk: invalid admin address") } admin = a } func Admin() address { return admin } func DeskAddress() address { return deskAddr } func assertAdmin(cur realm) { if cur.Previous().Address() != admin { panic("desk: admin only") } } // --- render --- func Render(path string) string { out := "# LastCall\n\n" out += "Synthetic stock desk: spot, perps, limit orders and a fee pool. Test funds only.\n\n" out += "## Markets\n\n" out += "| Ticker | Price (USD) | Quote | Supply | Long OI | Short OI |\n|---|---|---|---|---|---|\n" for _, t := range tickers { ps, quote := "-", "none" if p, ok := prices[t]; ok { ps = usdFmt(p.Value) quote = "last call passed" if IsFresh(t) { quote = "live" } } out += ufmt.Sprintf("| s%s | %s | %s | %s | %s | %s |\n", t, ps, quote, sharesFmt(stocks[t].token.TotalSupply()), usdFmt(oiLong[t]), usdFmt(oiShort[t])) } out += "\n## Desk\n\n" out += ufmt.Sprintf("* tUSD total supply: %s\n", usdFmt(usd.TotalSupply())) out += ufmt.Sprintf("* desk tUSD reserve: %s\n", usdFmt(usd.BalanceOf(deskAddr))) out += ufmt.Sprintf("* locked behind positions and orders: %s\n", usdFmt(lockedUSD)) out += ufmt.Sprintf("* fee pool: %s, cumulative fees %s\n", usdFmt(assetsNow()), usdFmt(poolFeesAll)) out += ufmt.Sprintf("* open positions: %d, pending orders: %d\n", perps.Size(), orders.Size()) out += ufmt.Sprintf("* a price older than %d seconds stops every trade that moves value\n", maxPriceAge) out += "* every trade fills on the first price observed after it was placed\n" if marketOpen { out += ufmt.Sprintf("* stock market open: new perps up to %dx\n", maxLeverage) } else { out += ufmt.Sprintf("* stock market closed: new perps up to %dx until the open, positions above it are cut to it\n", closedMaxLeverage) } out += "\n## Keys\n\n" out += ufmt.Sprintf("* admin: %s\n* desk reserve account: %s\n", admin.String(), deskAddr.String()) out += ufmt.Sprintf("* price updaters, %d must agree: %s\n", quorum, Updaters()) return out } // usdFmt formats micro-USD as a dollar string with two decimals. func usdFmt(micro int64) string { neg := micro < 0 if neg { micro = -micro } d := micro / 1000000 c := (micro % 1000000) / 10000 cs := ufmt.Sprintf("%d", c) if len(cs) == 1 { cs = "0" + cs } s := ufmt.Sprintf("$%d.%s", d, cs) if neg { s = "-" + s } return s } // sharesFmt formats a 6-decimal token amount as a share count. func sharesFmt(units int64) string { neg := units < 0 if neg { units = -units } d := units / 1000000 f := units % 1000000 fs := ufmt.Sprintf("%d", f) for len(fs) < 6 { fs = "0" + fs } s := ufmt.Sprintf("%d.%s", d, fs) if neg { s = "-" + s } return s }