package lastcall // Spot trading against the desk. The desk quotes its own price and takes a fee on // each side; it is the counterparty to every trade. Buy and Sell are orders that // fill on the next price (orders.gno): a buy mints sStock, a sell pays tUSD from // the desk reserve, never from tUSD locked behind margin or orders. const ( feeBps = 30 // 0.30% desk fee each side bpsDenom = 10000 // microUSD = 1000000 // 1 tUSD = 1_000000 micro; 1 share = 1_000000 units minTradeUnits = 1000 // 0.001 share minimum, blocks dust maxTradeUnits = 10_000_000000 // 10,000 shares max, keeps price*amount in int64 ) // notionalMicroUSD returns price * stockAmount / 1e6 — the micro-USD value of // stockAmount units (6 dp) of a stock quoted at `price` micro-USD per share. func notionalMicroUSD(price, stockAmount int64) int64 { return mulDiv(price, stockAmount, microUSD) } func assertTradeSize(stockAmount int64) { if stockAmount < minTradeUnits { panic("desk: amount below minimum (0.001 share)") } if stockAmount > maxTradeUnits { panic("desk: amount above maximum (10,000 shares)") } } // QuoteBuy / QuoteSell are read-only helpers for the UI: the tUSD cost/proceeds // of trading stockAmount units at the current price. func QuoteBuy(ticker string, stockAmount int64) int64 { assertTradeSize(stockAmount) price, _ := GetPrice(ticker) return mulDiv(notionalMicroUSD(price, stockAmount), bpsDenom+feeBps, bpsDenom) } func QuoteSell(ticker string, stockAmount int64) int64 { assertTradeSize(stockAmount) price, _ := GetPrice(ticker) return mulDiv(notionalMicroUSD(price, stockAmount), bpsDenom-feeBps, bpsDenom) } // 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 SeedUSD(cur realm, amount int64) { assertAdmin(cur) if amount <= 0 { panic("desk: amount must be positive") } if err := usdLedger.Mint(deskAddr, amount); err != nil { panic(err.Error()) } } // DeskReserveUSD is the desk's own tUSD balance. func DeskReserveUSD() int64 { return usd.BalanceOf(deskAddr) }