usd
*v0.TokentUSD is the test-USD collateral token. 6 decimals, so one tUSD unit is 1\_000000 and token amounts line up 1:1 with micro-USD price quotes.
- OID
- 009d34…44b1:142
usd details
usdLedger
*v0.PrivateLedgertUSD is the test-USD collateral token. 6 decimals, so one tUSD unit is 1\_000000 and token amounts line up 1:1 with micro-USD price quotes.
- OID
- 009d34…44b1:144
usdLedger details
initUSD
func()- OID
- 009d34…44b1:5
initUSD details
FaucetUSD
func()FaucetUSD mints 10,000 tUSD to the caller. Open faucet — demo only.
- OID
- 009d34…44b1:7
FaucetUSD details
BalanceUSD
func(owner .uverse.address) int64- OID
- 009d34…44b1:8
BalanceUSD details
costKey
typeValue
lastcall.costKey
spotCost
map[lastcall.costKey]int64- OID
- 009d34…44b1:10
spotCost details
addCost
func(owner .uverse.address, ticker string, paid int64)addCost records the tUSD notional (micro) a buyer paid toward their cost basis.
- OID
- 009d34…44b1:11
addCost details
reduceCost
func(owner .uverse.address, ticker string, sold int64, heldBefore int64)reduceCost removes the cost of \`sold\` units from a holder whose balance BEFORE the sale was \`heldBefore\`, keeping the average per-share cost unchanged.
- OID
- 009d34…44b1:13
reduceCost details
AvgEntry
func(ticker string, owner .uverse.address) int64AvgEntry returns the owner's average entry price for ticker in micro-USD per share, or 0 if they hold none.
- OID
- 009d34…44b1:14
AvgEntry details
admin
.uverse.addressValue
<gnolang.StringValue>
updater
.uverse.addressValue
<gnolang.StringValue>
deskAddr
.uverse.addressValue
<gnolang.StringValue>
nextTokID
v0.IDValue
<zero>
init.14
func()- OID
- 009d34…44b1:19
init.14 details
SetAdmin
func(a .uverse.address)- OID
- 009d34…44b1:21
SetAdmin details
SetUpdater
func(u .uverse.address)- OID
- 009d34…44b1:22
SetUpdater details
Admin
func() .uverse.address- OID
- 009d34…44b1:23
Admin details
Updater
func() .uverse.address- OID
- 009d34…44b1:24
Updater details
DeskAddress
func() .uverse.address- OID
- 009d34…44b1:25
DeskAddress details
assertAdmin
func()- OID
- 009d34…44b1:26
assertAdmin details
assertUpdater
func()- OID
- 009d34…44b1:27
assertUpdater details
Price
typePrice is quoted in micro-USD per whole share.
Value
lastcall.Price
prices
map[string]lastcall.Price- OID
- 009d34…44b1:29
prices details
SetPrice
func(ticker string, value int64, observedAt int64)SetPrice is pushed by the off-chain bot (updater key) for one ticker.
- OID
- 009d34…44b1:30
SetPrice details
SetPrices
func(quotes string, observedAt int64)SetPrices stores several quotes in one transaction so the keeper pays one fee per cycle. quotes is "TICKER:microUSD" pairs joined by ','.
- OID
- 009d34…44b1:31
SetPrices details
storePrice
func(ticker string, value int64, observedAt int64)- OID
- 009d34…44b1:32
storePrice details
GetPrice
func(ticker string) (int64, int64)GetPrice returns the last quote for a ticker. Panics if unknown.
- OID
- 009d34…44b1:33
GetPrice details
maxPriceAge
untyped bigintValue
(600 <untyped> bigint)
maxClockSkew
untyped bigintValue
(60 <untyped> bigint)
maxPrice
untyped bigintValue
(1000000000000 <untyped> bigint)
IsFresh
func(ticker string) boolIsFresh reports whether a ticker has a quote young enough to trade against.
- OID
- 009d34…44b1:34
IsFresh details
freshPrice
func(ticker string) int64- OID
- 009d34…44b1:35
freshPrice details
Render
func(path string) string- OID
- 009d34…44b1:36
Render details
usdFmt
func(micro int64) stringusdFmt formats micro-USD as a dollar string with two decimals.
- OID
- 009d34…44b1:37
usdFmt details
sharesFmt
func(units int64) stringsharesFmt formats a 6-decimal token amount as a share count.
- OID
- 009d34…44b1:38
sharesFmt details
limitOrder
typeValue
lastcall.limitOrder
limits
map[uint64]*lastcall.limitOrder- OID
- 009d34…44b1:40
limits details
nextLimitID
uint64Value
0
PlaceLimit
func(ticker string, isLong bool, size int64, margin int64, limit int64) uint64PlaceLimit locks \`margin\` + the open fee and queues an order to open a perp when the oracle price reaches \`limit\`. Returns the order id.
- OID
- 009d34…44b1:42
PlaceLimit details
CancelLimit
func(id uint64)CancelLimit refunds a pending order's locked margin + fee to its owner.
- OID
- 009d34…44b1:44
CancelLimit details
limitReady
func(o *lastcall.limitOrder, mark int64) boollimitReady reports whether an order's trigger condition holds at \`mark\`: a long fills at or below its limit, a short at or above.
- OID
- 009d34…44b1:45
limitReady details
fillSize
func(o *lastcall.limitOrder, mark int64) int64fillSize shrinks an order whose notional at the fill price would exceed the leverage its margin allows, so a price gap past the limit still fills.
- OID
- 009d34…44b1:46
fillSize details
TriggerLimit
func(id uint64) uint64TriggerLimit executes a ready order at the current oracle price, using the locked margin + prepaid fee. Permissionless (keeper / UI). Requires the market open and the trigger reached; panics otherwise so the keeper simply retries later.
- OID
- 009d34…44b1:47
TriggerLimit details
LimitsOf
func(owner .uverse.address) stringLimitsOf returns an owner's pending orders, ';'-joined, fields comma-separated: id,ticker,L|S,size,margin,limit,mark (size/money micro, 6 dp).
- OID
- 009d34…44b1:48
LimitsOf details
AllLimits
func() stringAllLimits lists every pending order for the keeper to scan, ';'-joined: id,ticker,L|S,limit,mark. The keeper triggers the ones whose condition holds.
- OID
- 009d34…44b1:49
AllLimits details
marketOpen
bool// default open until the updater pushes the real status
Value
true
SetMarketOpen
func(open bool)SetMarketOpen is pushed by the off-chain updater (bot) from the live market state.
- OID
- 009d34…44b1:51
SetMarketOpen details
IsMarketOpen
func() boolIsMarketOpen reports whether the desk is accepting new perp opens.
- OID
- 009d34…44b1:53
IsMarketOpen details
maxInt64
uint64Value
9223372036854775807
mulDiv
func(a int64, b int64, c int64) int64- OID
- 009d34…44b1:54
mulDiv details
perpFeeBps
untyped bigint// 0.10% of notional, each side (open + close)
Value
(10 <untyped> bigint)
maxLeverage
untyped bigint// 10x: notional \<= margin \* 10
Value
(10 <untyped> bigint)
maintBps
untyped bigint// 10% maintenance: liquidatable when equity \<= 10% of margin
Value
(1000 <untyped> bigint)
minMargin
untyped bigint// $1 minimum margin, blocks dust
Value
(1000000 <untyped> bigint)
perpMaxNotional
untyped bigint// $1,000,000 notional cap
Value
(1000000000000 <untyped> bigint)
maxMargin
untyped bigintValue
(1000000000000 <untyped> bigint)
holdRateBpsYear
untyped bigint// 10%/yr borrow fee on notional while a position is open
Value
(1000 <untyped> bigint)
secondsYear
untyped bigint// 365d, for prorating the borrow fee
Value
(31536000 <untyped> bigint)
perp
typeValue
lastcall.perp
perps
map[uint64]*lastcall.perp- OID
- 009d34…44b1:57
perps details
nextPerpID
uint64Value
1
mustPerp
func(id uint64) *lastcall.perp- OID
- 009d34…44b1:59
mustPerp details
perpPnL
func(p *lastcall.perp, mark int64) int64perpPnL is size \* (mark - entry) / 1e6 for a long, negated for a short.
- OID
- 009d34…44b1:61
perpPnL details
perpEquity
func(p *lastcall.perp, mark int64) int64equity is the position's margin plus unrealized PnL.
- OID
- 009d34…44b1:62
perpEquity details
liquidatable
func(p *lastcall.perp, mark int64) boolliquidatable: equity has fallen to the maintenance fraction of the margin.
- OID
- 009d34…44b1:63
liquidatable details
liqPrice
func(p *lastcall.perp) int64liqPrice is the mark price at which the position becomes liquidatable.
- OID
- 009d34…44b1:64
liqPrice details
assertPerpSize
func(size int64)assertPerpSize bounds the size so price\*size stays inside int64.
- OID
- 009d34…44b1:65
assertPerpSize details
assertMargin
func(margin int64)- OID
- 009d34…44b1:66
assertMargin details
OpenPerp
func(ticker string, isLong bool, size int64, margin int64) uint64OpenPerp opens a long or short on \`ticker\` of \`size\` stock units (6 dp), backed by \`margin\` tUSD micro pulled from the caller (plus the open fee). Market order.
- OID
- 009d34…44b1:67
OpenPerp details
openPositionCore
func(owner .uverse.address, ticker string, isLong bool, size int64, margin int64, price int64, fee int64) uint64openPositionCore validates and creates a perp, assuming \`margin\`+\`fee\` tUSD are ALREADY in the desk reserve (pulled from the owner by the caller). Shared by market opens (OpenPerp) and limit-order execution (TriggerLimit). A panic here reverts the whole tx, including the funds pull, so nothing is stranded.
- OID
- 009d34…44b1:68
openPositionCore details
ClosePerp
func(id uint64)ClosePerp closes the caller's own position at the current mark and settles.
- OID
- 009d34…44b1:69
ClosePerp details
ClosePartial
func(id uint64, closeSize int64)ClosePartial closes \`closeSize\` units (6 dp) of the caller's own position at the current mark, leaving the rest open. Always allowed, even when the market is closed. closeSize == the full size behaves like ClosePerp.
- OID
- 009d34…44b1:70
ClosePartial details
Liquidate
func(id uint64)Liquidate closes an underwater position. Permissionless: anyone (the desk's keeper bot, or the UI) may call it once the position is at maintenance.
- OID
- 009d34…44b1:71
Liquidate details
holdingFee
func(p *lastcall.perp, now int64) int64holdingFee is the borrow fee owed to the pool for keeping a position open: holdRateBpsYear of the entry notional, prorated by seconds held. It prices the pool's directional risk over time — the honest substitute for funding on an oracle-mark desk (there is no perp-vs-spot basis to correct, but the pool is still carrying the position). Overflow-safe: perYear \<= 1e11, elapsed clamped.
- OID
- 009d34…44b1:72
holdingFee details
sliceSettle
func(p *lastcall.perp, sz int64, mark int64, now int64) (payout int64, fee int64, hold int64, marginSlice int64)sliceSettle computes the numbers for closing \`sz\` units of a position at \`mark\`: pro-rata margin, the slice's PnL, the close fee and the borrow fee, and the owner payout (floored at 0). Pure — no transfers — so it is unit-tested directly.
- OID
- 009d34…44b1:73
sliceSettle details
collectedFee
func(p *lastcall.perp, sz int64, mark int64, marginSlice int64, owed int64) int64collectedFee caps a close's fees at the equity the closed slice still had.
- OID
- 009d34…44b1:74
collectedFee details
closePortion
func(p *lastcall.perp, sz int64, mark int64)closePortion closes \`sz\` units of the position at \`mark\`: pays the owner the slice payout, routes the fees to the pool, releases the slice's open interest, and shrinks the position (or removes it when \`sz\` is the whole size). Leverage, entry and liq price of the remainder are unchanged (margin and size shrink together).
- OID
- 009d34…44b1:75
closePortion details
settlePerp
func(p *lastcall.perp, mark int64)settlePerp fully closes and removes the position.
- OID
- 009d34…44b1:76
settlePerp details
PerpsOf
func(owner .uverse.address) stringPerpsOf returns the caller's open positions, one per line, fields comma- separated: id,ticker,L|S,size,entry,margin,mark,pnl,liq,stopLoss,takeProfit. Money and size are integers at 6 dp; mark/pnl/liq are computed live. Stop prices are 0 when unset. Empty string if none.
- OID
- 009d34…44b1:77
PerpsOf details
AllLiquidatable
func() stringAllLiquidatable lists the ids of positions at or below maintenance on a fresh quote, ';'-joined, for the keeper.
- OID
- 009d34…44b1:78
AllLiquidatable details
defaultOICap
untyped bigint// $250,000 of open notional per side, per market
Value
(250000000000 <untyped> bigint)
skewImpactMaxBps
untyped bigint// max +/-1.00% skew price impact on entry
Value
(100 <untyped> bigint)
skewScaleK
untyped bigint// $500,000: net skew at which impact reaches the max
Value
(500000000000 <untyped> bigint)
oiLong
map[string]int64// open long notional (micro-USD, at entry) per ticker
- OID
- 009d34…44b1:80
oiLong details
oiShort
map[string]int64// open short notional per ticker
- OID
- 009d34…44b1:82
oiShort details
oiCapOv
map[string]int64// per-ticker per-side cap override; 0 => default
- OID
- 009d34…44b1:84
oiCapOv details
maxLevOv
map[string]int64// per-ticker max leverage override; 0 => global maxLeverage
- OID
- 009d34…44b1:86
maxLevOv details
oiCap
func(ticker string) int64- OID
- 009d34…44b1:87
oiCap details
maxLevOf
func(ticker string) int64maxLevOf is the leverage ceiling for a market: a per-asset override if set, otherwise the global maxLeverage. Overrides may only lower it.
- OID
- 009d34…44b1:89
maxLevOf details
sideOI
func(ticker string, isLong bool) int64- OID
- 009d34…44b1:90
sideOI details
addOI
func(ticker string, isLong bool, notional int64)- OID
- 009d34…44b1:91
addOI details
subOI
func(ticker string, isLong bool, notional int64)- OID
- 009d34…44b1:92
subOI details
SetOICap
func(ticker string, perSide int64)SetOICap sets the per-side open-interest cap for a market (micro-USD). 0 restores the default.
- OID
- 009d34…44b1:93
SetOICap details
SetMaxLev
func(ticker string, lev int64)SetMaxLev lowers (never raises) the max leverage for a market. 0 restores the global default.
- OID
- 009d34…44b1:94
SetMaxLev details
OIOf
func(ticker string) stringOIOf returns a market's open-interest state, comma-separated: oiLong,oiShort,capPerSide,maxLev (notional micro-USD; maxLev a plain integer).
- OID
- 009d34…44b1:95
OIOf details
skewImpactBps
func(ticker string, isLong bool, notional int64) int64skewImpactBps is the entry price impact in bps for opening \`notional\` on \`isLong\`: the opener pays when they deepen the skew and fills at the oracle price when they balance it. A rebate would let an instant round trip profit.
- OID
- 009d34…44b1:96
skewImpactBps details
skewEntry
func(price int64, impBps int64, isLong bool) int64skewEntry applies a bps impact to the oracle price to get the fill/entry price: a long fills higher and a short fills lower by \`impBps\` (worse when impBps > 0).
- OID
- 009d34…44b1:97
skewEntry details
stock
typeA stock is one synthetic-equity market: a GRC20 token (6 decimals) whose ledger the desk owns, so the desk can mint on Buy and burn on Sell.
Value
lastcall.stock
stocks
map[string]*lastcall.stock- OID
- 009d34…44b1:99
stocks details
tickers
[]string// insertion order, for Render
- OID
- 009d34…44b1:188
tickers details
defaultMarkets
[]struct{...}- OID
- 009d34…44b1:103
defaultMarkets details
initStocks
func()- OID
- 009d34…44b1:109
initStocks details
listStock
func(ticker string, name string)- OID
- 009d34…44b1:111
listStock details
mustStock
func(ticker string) *lastcall.stock- OID
- 009d34…44b1:112
mustStock details
StockBalance
func(ticker string, owner .uverse.address) int64- OID
- 009d34…44b1:113
StockBalance details
StockSupply
func(ticker string) int64- OID
- 009d34…44b1:114
StockSupply details
validateStops
func(p *lastcall.perp, sl int64, tp int64)validateStops rejects stop prices on the wrong side of the current mark, which would trigger instantly, and keeps SL below TP for a long / above TP for a short. A 0 clears that leg. Prices are micro-USD per share.
- OID
- 009d34…44b1:115
validateStops details
SetStops
func(id uint64, stopLoss int64, takeProfit int64)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.
- OID
- 009d34…44b1:117
SetStops details
stopReady
func(p *lastcall.perp, mark int64) boolstopReady reports whether a position's stop-loss or take-profit has been reached at \`mark\`. Long: SL when mark \<= SL, TP when mark >= TP. Short: mirrored.
- OID
- 009d34…44b1:118
stopReady details
TriggerStop
func(id uint64)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.
- OID
- 009d34…44b1:119
TriggerStop details
AllStops
func() stringAllStops lists every open position that has a stop set, for the keeper to scan, ';'-joined, fields comma-separated: id,ticker,L|S,stopLoss,takeProfit,mark. The keeper triggers the ones whose condition holds.
- OID
- 009d34…44b1:120
AllStops details
feeBps
untyped bigint// 0.30% desk fee each side
Value
(30 <untyped> bigint)
bpsDenom
untyped bigint//
Value
(10000 <untyped> bigint)
microUSD
untyped bigint// 1 tUSD = 1\_000000 micro; 1 share = 1\_000000 units
Value
(1000000 <untyped> bigint)
minTradeUnits
untyped bigint// 0.001 share minimum, blocks dust
Value
(1000 <untyped> bigint)
maxTradeUnits
untyped bigint// 10,000 shares max, keeps price\*amount in int64
Value
(10000000000 <untyped> bigint)
notionalMicroUSD
func(price int64, stockAmount int64) int64notionalMicroUSD returns price \* stockAmount / 1e6 — the micro-USD value of stockAmount units (6 dp) of a stock quoted at \`price\` micro-USD per share.
- OID
- 009d34…44b1:121
notionalMicroUSD details
assertTradeSize
func(stockAmount int64)- OID
- 009d34…44b1:123
assertTradeSize details
Buy
func(ticker string, stockAmount int64)Buy mints stockAmount units (6 dp) of sTicker to the caller and charges tUSD at the desk price plus fee. Caller must already hold enough tUSD.
- OID
- 009d34…44b1:124
Buy details
Sell
func(ticker string, stockAmount int64)Sell burns stockAmount units of sTicker from the caller and pays tUSD at the desk price minus fee, from the desk reserve.
- OID
- 009d34…44b1:125
Sell details
QuoteBuy
func(ticker string, stockAmount int64) int64QuoteBuy / QuoteSell are read-only helpers for the UI: the tUSD cost/proceeds of trading stockAmount units at the current price.
- OID
- 009d34…44b1:126
QuoteBuy details
QuoteSell
func(ticker string, stockAmount int64) int64- OID
- 009d34…44b1:127
QuoteSell details
SeedUSD
func(amount int64)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.
- OID
- 009d34…44b1:128
SeedUSD details
DeskReserveUSD
func() int64DeskReserveUSD is the desk's own tUSD balance.
- OID
- 009d34…44b1:129
DeskReserveUSD details
minPoolDeposit
untyped bigint// $1 minimum, blocks dust shares
Value
(1000000 <untyped> bigint)
poolShares
int64// total shares outstanding
Value
100000000
poolAssets
int64// micro-USD the pool is entitled to in the reserve
Value
100000000
poolFeesAll
int64// cumulative fees ever routed to the pool (metrics)
Value
0
poolBals
map[.uverse.address]int64// shares held per depositor
- OID
- 009d34…44b1:134
poolBals details
accrueFee
func(fee int64)accrueFee routes a desk fee into the pool. Called by spot and perp trading. If no one has deposited yet (poolShares == 0) the fee simply stays in the reserve as it did before — there is no one to credit.
- OID
- 009d34…44b1:135
accrueFee details
PoolDeposit
func(amount int64) int64PoolDeposit pulls \`amount\` tUSD micro from the caller into the desk reserve and mints pool shares at the current share price. Returns the shares minted.
- OID
- 009d34…44b1:137
PoolDeposit details
PoolWithdraw
func(shares int64) int64PoolWithdraw 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.
- OID
- 009d34…44b1:138
PoolWithdraw details
PoolSharePrice
func() int64PoolSharePrice 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.
- OID
- 009d34…44b1:139
PoolSharePrice details
PoolInfo
func() stringPoolInfo returns pool-wide figures, comma-separated: totalShares,poolAssets,feesAll,deskReserve (all micro, 6 dp).
- OID
- 009d34…44b1:140
PoolInfo details
PoolOf
func(owner .uverse.address) stringPoolOf returns one depositor's position, comma-separated: shares,assets where assets is the current tUSD micro value of those shares.
- OID
- 009d34…44b1:141