Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v4 state

Back to all declarations

usd

*v0.Token

tUSD 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.

Open
OID
0c7b0a…bdec:235
usd details

Inspect pointer

usdLedger

*v0.PrivateLedger

tUSD 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.

Open
OID
0c7b0a…bdec:237
usdLedger details

Inspect pointer

FaucetUSD

func()

FaucetUSD mints 10,000 tUSD to the caller. Open faucet — demo only.

Open
OID
0c7b0a…bdec:7
FaucetUSD details

Inspect func

BalanceUSD

func(owner .uverse.address) int64
Open
OID
0c7b0a…bdec:8
BalanceUSD details

Inspect func

costKey

type

Value

v4.costKey

spotCost

map[v4.costKey]int64
Open
OID
0c7b0a…bdec:10
spotCost details

Inspect map

addCost

func(owner .uverse.address, ticker string, paid int64)

addCost records the tUSD notional (micro) a buyer paid toward their cost basis.

Open
OID
0c7b0a…bdec:11
addCost details

Inspect func

costOf

func(owner .uverse.address, ticker string) int64
Open
OID
0c7b0a…bdec:13
costOf details

Inspect func

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.

Open
OID
0c7b0a…bdec:14
reduceCost details

Inspect func

AvgEntry

func(ticker string, owner .uverse.address) int64

AvgEntry returns the owner's average entry price for ticker in micro-USD per share, or 0 if they hold none.

Open
OID
0c7b0a…bdec:15
AvgEntry details

Inspect func

AddMargin

func(id uint64, amount int64)

AddMargin adds \`amount\` tUSD micro from the caller to their own position, lowering its leverage. It trades nothing, so it applies at once.

Open
OID
0c7b0a…bdec:16
AddMargin details

Inspect func

overLeveraged

func(p *v4.perp, mark int64) bool
Open
OID
0c7b0a…bdec:18
overLeveraged details

Inspect func

Delever

func(id uint64)

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.

Open
OID
0c7b0a…bdec:19
Delever details

Inspect func

deleverSize

func(p *v4.perp, mark int64, now int64) int64
Open
OID
0c7b0a…bdec:20
deleverSize details

Inspect func

cutToMargin

func(p *v4.perp, sz int64, mark int64)
Open
OID
0c7b0a…bdec:21
cutToMargin details

Inspect func

Overleveraged

func(offset int, count int) string

Overleveraged lists, within one page of open positions, the ids Delever would cut now, ';'-joined, for the keeper. Empty while the market is open.

Open
OID
0c7b0a…bdec:22
Overleveraged details

Inspect func

admin

.uverse.address

Value

<gnolang.StringValue>

deskAddr

.uverse.address

Value

<gnolang.StringValue>

nextTokID

v0.ID

Value

<zero>

SetAdmin

func(a .uverse.address)
Open
OID
0c7b0a…bdec:28
SetAdmin details

Inspect func

DeskAddress

func() .uverse.address
Open
OID
0c7b0a…bdec:30
DeskAddress details

Inspect func

usdFmt

func(micro int64) string

usdFmt formats micro-USD as a dollar string with two decimals.

Open
OID
0c7b0a…bdec:33
usdFmt details

Inspect func

sharesFmt

func(units int64) string

sharesFmt formats a 6-decimal token amount as a share count.

Open
OID
0c7b0a…bdec:34
sharesFmt details

Inspect func

emitSpot

func(kind string, owner .uverse.address, ticker string, size int64, price int64, usd int64)
Open
OID
0c7b0a…bdec:39
emitSpot details

Inspect func

emitPerpOpen

func(p *v4.perp)
Open
OID
0c7b0a…bdec:40
emitPerpOpen details

Inspect func

emitPerpClose

func(p *v4.perp, kind string, size int64, mark int64, payout int64)
Open
OID
0c7b0a…bdec:41
emitPerpClose details

Inspect func

emitOrder

func(kind string, o *v4.order, extra []string)
Open
OID
0c7b0a…bdec:42
emitOrder details

Inspect func

emitPerp

func(kind string, p *v4.perp, extra []string)
Open
OID
0c7b0a…bdec:43
emitPerp details

Inspect func

emitPool

func(kind string, owner .uverse.address, usd int64, shares int64)
Open
OID
0c7b0a…bdec:44
emitPool details

Inspect func

Price

type

Price is quoted in micro-USD per whole share.

Value

v4.Price

maxPriceAge

untyped bigint

Value

(600 <untyped> bigint)

maxClockSkew

untyped bigint

Value

(60 <untyped> bigint)

maxPrice

untyped bigint

Value

(1000000000000 <untyped> bigint)

quoteWindow

untyped bigint

Value

(120 <untyped> bigint)

agreeBps

untyped bigint

Value

(100 <untyped> bigint)

maxUpdaters

untyped bigint

Value

(7 <untyped> bigint)

quorum

int

Value

2

submitted

map[string]map[.uverse.address]v4.Price
Open
OID
0c7b0a…bdec:50
submitted details

Inspect map

openVotes

map[.uverse.address]bool
Open
OID
0c7b0a…bdec:52
openVotes details

Inspect map

marketOpen

bool

Value

false

openedAt

int64

Value

0

AddUpdater

func(u .uverse.address)
Open
OID
0c7b0a…bdec:55
AddUpdater details

Inspect func

RemoveUpdater

func(u .uverse.address)
Open
OID
0c7b0a…bdec:57
RemoveUpdater details

Inspect func

Updaters

func() string

Updaters lists the updater addresses, comma-separated.

Open
OID
0c7b0a…bdec:59
Updaters details

Inspect func

isUpdater

func(a .uverse.address) bool
Open
OID
0c7b0a…bdec:61
isUpdater details

Inspect func

assertUpdater

func() .uverse.address
Open
OID
0c7b0a…bdec:62
assertUpdater details

Inspect func

SetPrices

func(quotes string, observedAt int64)

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.

Open
OID
0c7b0a…bdec:63
SetPrices details

Inspect func

submit

func(from .uverse.address, ticker string, value int64, observedAt int64)
Open
OID
0c7b0a…bdec:64
submit details

Inspect func

GetPrice

func(ticker string) (int64, int64)

GetPrice returns the desk price for a ticker and its observation time. Panics if unknown.

Open
OID
0c7b0a…bdec:67
GetPrice details

Inspect func

IsFresh

func(ticker string) bool

IsFresh reports whether a ticker has a price young enough to trade against.

Open
OID
0c7b0a…bdec:68
IsFresh details

Inspect func

LastCallAt

func(ticker string) int64

LastCallAt is the time after which the stored price no longer allows a trade, or 0 before the first price.

Open
OID
0c7b0a…bdec:69
LastCallAt details

Inspect func

freshPrice

func(ticker string) int64
Open
OID
0c7b0a…bdec:70
freshPrice details

Inspect func

pricedAfter

func(ticker string, t int64) bool

pricedAfter reports whether the ticker's price was observed after t, so a request made at t may fill on it.

Open
OID
0c7b0a…bdec:71
pricedAfter details

Inspect func

SetMarketOpen

func(open bool)

SetMarketOpen records the caller's view of the US stock market.

Open
OID
0c7b0a…bdec:72
SetMarketOpen details

Inspect func

MarketVoteOf

func(u .uverse.address) string

MarketVoteOf returns an updater's recorded view of the market: "open", "closed" or "none".

Open
OID
0c7b0a…bdec:73
MarketVoteOf details

Inspect func

IsMarketOpen

func() bool

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.

Open
OID
0c7b0a…bdec:75
IsMarketOpen details

Inspect func

maxPage

untyped bigint

Value

(200 <untyped> bigint)

ownerTree

func(index *v0.Tree, owner .uverse.address) *v0.Tree
Open
OID
0c7b0a…bdec:90
ownerTree details

Inspect func

putItem

func(all *v0.Tree, index *v0.Tree, owner .uverse.address, id uint64, item interface{...})
Open
OID
0c7b0a…bdec:91
putItem details

Inspect func

dropItem

func(all *v0.Tree, index *v0.Tree, owner .uverse.address, id uint64)
Open
OID
0c7b0a…bdec:92
dropItem details

Inspect func

eachOwned

func(index *v0.Tree, owner .uverse.address, cb func(...))
Open
OID
0c7b0a…bdec:93
eachOwned details

Inspect func

eachPage

func(all *v0.Tree, offset int, count int, cb func(...))
Open
OID
0c7b0a…bdec:94
eachPage details

Inspect func

joinRow

func(out string, row string) string
Open
OID
0c7b0a…bdec:95
joinRow details

Inspect func

OpenPerpCount

func() int

OpenPerpCount and OrderCount tell the keeper how many pages to read.

Open
OID
0c7b0a…bdec:96
OpenPerpCount details

Inspect func

maxInt64

uint64

Value

9223372036854775807

mulDiv

func(a int64, b int64, c int64) int64
Open
OID
0c7b0a…bdec:98
mulDiv details

Inspect func

marketBandBps

untyped bigint

Value

(200 <untyped> bigint)

orderTTL

untyped bigint

Value

(900 <untyped> bigint)

order

type

Value

v4.order

nextOrderID

uint64

Value

2

mustOrder

func(id uint64) *v4.order
Open
OID
0c7b0a…bdec:104
mustOrder details

Inspect func

isPerpOrder

func(o *v4.order) bool
Open
OID
0c7b0a…bdec:106
isPerpOrder details

Inspect func

bandPrice

func(mark int64, worseUp bool) int64
Open
OID
0c7b0a…bdec:107
bandPrice details

Inspect func

pull

func(from .uverse.address, amount int64)
Open
OID
0c7b0a…bdec:108
pull details

Inspect func

pay

func(to .uverse.address, amount int64)
Open
OID
0c7b0a…bdec:109
pay details

Inspect func

OpenPerp

func(ticker string, isLong bool, size int64, margin int64) uint64

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.

Open
OID
0c7b0a…bdec:111
OpenPerp details

Inspect func

openMarket

func(owner .uverse.address, ticker string, isLong bool, size int64, margin int64) uint64
Open
OID
0c7b0a…bdec:112
openMarket details

Inspect func

PlaceLimit

func(ticker string, isLong bool, size int64, margin int64, limit int64) uint64

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.

Open
OID
0c7b0a…bdec:113
PlaceLimit details

Inspect func

placePerp

func(owner .uverse.address, kind string, ticker string, isLong bool, size int64, margin int64, limit int64, ref int64, lev int64) uint64
Open
OID
0c7b0a…bdec:114
placePerp details

Inspect func

Buy

func(ticker string, stockAmount int64) uint64

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.

Open
OID
0c7b0a…bdec:115
Buy details

Inspect func

Sell

func(ticker string, stockAmount int64) uint64

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.

Open
OID
0c7b0a…bdec:116
Sell details

Inspect func

CancelOrder

func(id uint64)

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.

Open
OID
0c7b0a…bdec:117
CancelOrder details

Inspect func

FillOrder

func(id uint64) uint64

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.

Open
OID
0c7b0a…bdec:118
FillOrder details

Inspect func

fillOrder

func(id uint64) uint64
Open
OID
0c7b0a…bdec:119
fillOrder details

Inspect func

limitReady

func(o *v4.order, mark int64) bool
Open
OID
0c7b0a…bdec:120
limitReady details

Inspect func

waitsForOpen

func(o *v4.order) bool
Open
OID
0c7b0a…bdec:121
waitsForOpen details

Inspect func

perpFill

type

Value

v4.perpFill

quotePerp

func(o *v4.order, mark int64) (v4.perpFill, string)
Open
OID
0c7b0a…bdec:122
quotePerp details

Inspect func

fillable

func(o *v4.order) bool
Open
OID
0c7b0a…bdec:123
fillable details

Inspect func

fillPerp

func(o *v4.order, mark int64) uint64
Open
OID
0c7b0a…bdec:124
fillPerp details

Inspect func

fillSize

func(o *v4.order, mark int64) int64
Open
OID
0c7b0a…bdec:125
fillSize details

Inspect func

limitFill

func(o *v4.order, mark int64) (size int64, margin int64, fee int64, refund int64)
Open
OID
0c7b0a…bdec:126
limitFill details

Inspect func

fillBuy

func(o *v4.order, mark int64)
Open
OID
0c7b0a…bdec:127
fillBuy details

Inspect func

fillSell

func(o *v4.order, mark int64)
Open
OID
0c7b0a…bdec:128
fillSell details

Inspect func

refund

func(o *v4.order, reason string)
Open
OID
0c7b0a…bdec:129
refund details

Inspect func

done

func(o *v4.order, result string)
Open
OID
0c7b0a…bdec:130
done details

Inspect func

OrderStatus

func(id uint64) string

OrderStatus is "pending", "filled", "filled:\<position id>" for a perp order, "refunded:\<reason>", or "unknown".

Open
OID
0c7b0a…bdec:131
OrderStatus details

Inspect func

OrdersOf

func(owner .uverse.address) string

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).

Open
OID
0c7b0a…bdec:132
OrdersOf details

Inspect func

ReadyOrders

func(offset int, count int) string

ReadyOrders lists, within one page of pending orders, the ids FillOrder would act on now, ';'-joined, for the keeper.

Open
OID
0c7b0a…bdec:133
ReadyOrders details

Inspect func

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 bigint

Value

(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

type

Value

v4.perp

nextPerpID

uint64

Value

2

mustPerp

func(id uint64) *v4.perp
Open
OID
0c7b0a…bdec:135
mustPerp details

Inspect func

perpPnL

func(p *v4.perp, mark int64) int64

perpPnL is size \* (mark - entry) / 1e6 for a long, negated for a short.

Open
OID
0c7b0a…bdec:137
perpPnL details

Inspect func

perpEquity

func(p *v4.perp, mark int64) int64

equity is the position's margin plus unrealized PnL.

Open
OID
0c7b0a…bdec:138
perpEquity details

Inspect func

liquidatable

func(p *v4.perp, mark int64) bool

liquidatable: equity net of the accrued borrow fee has fallen to the maintenance fraction of the margin.

Open
OID
0c7b0a…bdec:139
liquidatable details

Inspect func

liqPrice

func(p *v4.perp) int64

liqPrice is the mark price at which the position becomes liquidatable.

Open
OID
0c7b0a…bdec:140
liqPrice details

Inspect func

assertPerpSize

func(size int64)

assertPerpSize bounds the size so price\*size stays inside int64.

Open
OID
0c7b0a…bdec:141
assertPerpSize details

Inspect func

assertMargin

func(margin int64)
Open
OID
0c7b0a…bdec:142
assertMargin details

Inspect func

openPositionCore

func(owner .uverse.address, ticker string, isLong bool, size int64, margin int64, price int64, fee int64) uint64

openPositionCore validates and creates a perp, assuming \`margin\`+\`fee\` tUSD are ALREADY in the desk reserve and not locked. Called when a perp order fills (FillOrder). A panic here reverts the whole tx, so nothing is stranded.

Open
OID
0c7b0a…bdec:143
openPositionCore details

Inspect func

ClosePerp

func(id uint64)

ClosePerp asks to close the caller's whole position. It closes on the first price observed after the request (FillClose).

Open
OID
0c7b0a…bdec:144
ClosePerp details

Inspect func

ClosePartial

func(id uint64, closeSize int64)

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.

Open
OID
0c7b0a…bdec:145
ClosePartial details

Inspect func

requestClose

func(owner .uverse.address, id uint64, size int64)
Open
OID
0c7b0a…bdec:146
requestClose details

Inspect func

closingSize

func(p *v4.perp) int64
Open
OID
0c7b0a…bdec:147
closingSize details

Inspect func

FillClose

func(id uint64)

FillClose closes a requested position on the first price observed after the request, or drops a request that waited longer than orderTTL. Permissionless.

Open
OID
0c7b0a…bdec:148
FillClose details

Inspect func

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.

Open
OID
0c7b0a…bdec:150
Liquidate details

Inspect func

holdingFee

func(p *v4.perp, now int64) int64

holdingFee 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.

Open
OID
0c7b0a…bdec:151
holdingFee details

Inspect func

sliceSettle

func(p *v4.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.

Open
OID
0c7b0a…bdec:152
sliceSettle details

Inspect func

collectedFee

func(p *v4.perp, sz int64, mark int64, marginSlice int64, owed int64) int64

collectedFee caps a close's fees at the equity the closed slice still had.

Open
OID
0c7b0a…bdec:153
collectedFee details

Inspect func

closePortion

func(p *v4.perp, sz int64, mark int64, kind string)

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).

Open
OID
0c7b0a…bdec:154
closePortion details

Inspect func

settlePerp

func(p *v4.perp, mark int64, kind string)

settlePerp fully closes and removes the position.

Open
OID
0c7b0a…bdec:155
settlePerp details

Inspect func

PerpsOf

func(owner .uverse.address) string

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.

Open
OID
0c7b0a…bdec:156
PerpsOf details

Inspect func

AllLiquidatable

func(offset int, count int) string

AllLiquidatable lists, within one page of open positions, the ids at or below maintenance on a fresh quote, ';'-joined, for the keeper.

Open
OID
0c7b0a…bdec:157
AllLiquidatable details

Inspect func

ReadyCloses

func(offset int, count int) string

ReadyCloses lists, within one page of open positions, the ids FillClose would act on now, ';'-joined, for the keeper.

Open
OID
0c7b0a…bdec:158
ReadyCloses details

Inspect func

lockedUSD

int64

lockedUSD is tUSD the reserve holds on behalf of open positions and pending limit orders. Payouts, spot sales and pool withdrawals may only spend the rest, so a margin or an escrow can always be returned to its owner.

Value

0

LockedUSD

func() int64

LockedUSD is the part of the reserve owed back as margin and limit escrow.

Open
OID
0c7b0a…bdec:164
LockedUSD details

Inspect func

defaultOICap

untyped bigint

// $250,000 of open notional per side, per market

Value

(250000000000 <untyped> bigint)

closedMaxLeverage

untyped bigint

Value

(2 <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

Open
OID
0c7b0a…bdec:166
oiLong details

Inspect map

oiShort

map[string]int64

// open short notional per ticker

Open
OID
0c7b0a…bdec:168
oiShort details

Inspect map

oiCapOv

map[string]int64

// per-ticker per-side cap override; 0 => default

Open
OID
0c7b0a…bdec:170
oiCapOv details

Inspect map

maxLevOv

map[string]int64

// per-ticker max leverage override; 0 => global maxLeverage

Open
OID
0c7b0a…bdec:172
maxLevOv details

Inspect map

openLevOf

func(ticker string) int64

openLevOf is the leverage ceiling for a market while it trades: a per-asset override if set, otherwise the global maxLeverage. Overrides may only lower it.

Open
OID
0c7b0a…bdec:175
openLevOf details

Inspect func

maxLevOf

func(ticker string) int64

maxLevOf is the ceiling a new position gets right now. While the stock market is closed the quote cannot move, but the next open can gap, so new exposure is held to closedMaxLeverage until then.

Open
OID
0c7b0a…bdec:176
maxLevOf details

Inspect func

sideOI

func(ticker string, isLong bool) int64
Open
OID
0c7b0a…bdec:177
sideOI details

Inspect func

addOI

func(ticker string, isLong bool, notional int64)
Open
OID
0c7b0a…bdec:178
addOI details

Inspect func

subOI

func(ticker string, isLong bool, notional int64)
Open
OID
0c7b0a…bdec:179
subOI details

Inspect func

SetOICap

func(ticker string, perSide int64)

SetOICap sets the per-side open-interest cap for a market (micro-USD). 0 restores the default.

Open
OID
0c7b0a…bdec:180
SetOICap details

Inspect func

SetMaxLev

func(ticker string, lev int64)

SetMaxLev lowers (never raises) the max leverage for a market. 0 restores the global default.

Open
OID
0c7b0a…bdec:181
SetMaxLev details

Inspect func

OIOf

func(ticker string) string

OIOf returns a market's open-interest state, comma-separated: oiLong,oiShort,capPerSide,maxLev (notional micro-USD; maxLev a plain integer).

Open
OID
0c7b0a…bdec:182
OIOf details

Inspect func

skewImpactBps

func(ticker string, isLong bool, notional int64) int64

skewImpactBps 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.

Open
OID
0c7b0a…bdec:183
skewImpactBps details

Inspect func

skewEntry

func(price int64, impBps int64, isLong bool) int64

skewEntry 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).

Open
OID
0c7b0a…bdec:184
skewEntry details

Inspect func

stock

type

A 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

v4.stock

listStock

func(ticker string, name string)
Open
OID
0c7b0a…bdec:198
listStock details

Inspect func

mustStock

func(ticker string) *v4.stock
Open
OID
0c7b0a…bdec:199
mustStock details

Inspect func

StockBalance

func(ticker string, owner .uverse.address) int64
Open
OID
0c7b0a…bdec:200
StockBalance details

Inspect func

StockSupply

func(ticker string) int64
Open
OID
0c7b0a…bdec:201
StockSupply details

Inspect func

validateStops

func(p *v4.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.

Open
OID
0c7b0a…bdec:202
validateStops details

Inspect func

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.

Open
OID
0c7b0a…bdec:204
SetStops details

Inspect func

stopFillable

func(p *v4.perp) bool
Open
OID
0c7b0a…bdec:205
stopFillable details

Inspect func

stopReady

func(p *v4.perp, mark int64) bool

stopReady 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.

Open
OID
0c7b0a…bdec:206
stopReady details

Inspect func

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.

Open
OID
0c7b0a…bdec:207
TriggerStop details

Inspect func

ReadyStops

func(offset int, count int) string

ReadyStops lists, within one page of open positions, the ids whose stop TriggerStop would act on now, ';'-joined, for the keeper.

Open
OID
0c7b0a…bdec:208
ReadyStops details

Inspect func

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) 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.

Open
OID
0c7b0a…bdec:209
notionalMicroUSD details

Inspect func

assertTradeSize

func(stockAmount int64)
Open
OID
0c7b0a…bdec:211
assertTradeSize details

Inspect func

QuoteBuy

func(ticker string, stockAmount int64) int64

QuoteBuy / QuoteSell are read-only helpers for the UI: the tUSD cost/proceeds of trading stockAmount units at the current price.

Open
OID
0c7b0a…bdec:212
QuoteBuy details

Inspect func

QuoteSell

func(ticker string, stockAmount int64) int64
Open
OID
0c7b0a…bdec:213
QuoteSell details

Inspect func

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.

Open
OID
0c7b0a…bdec:214
SeedUSD details

Inspect func

DeskReserveUSD

func() int64

DeskReserveUSD is the desk's own tUSD balance.

Open
OID
0c7b0a…bdec:215
DeskReserveUSD details

Inspect func

minPoolDeposit

untyped bigint

// $1 minimum, blocks dust shares

Value

(1000000 <untyped> bigint)

minPoolShares

untyped bigint

// a holding is zero or at least 0.1 share, so a share cannot be inflated

Value

(100000 <untyped> bigint)

feeStreamSec

untyped bigint

Value

(86400 <untyped> bigint)

poolShares

int64

// total shares outstanding

Value

0

poolAssets

int64

// micro-USD the pool is entitled to in the reserve

Value

0

poolFeesAll

int64

// cumulative fees ever routed to the pool (metrics)

Value

0

poolBals

map[.uverse.address]int64

// shares held per depositor

Open
OID
0c7b0a…bdec:220
poolBals details

Inspect map

pendingFees

int64

// fees not yet part of poolAssets

Value

0

streamAt

int64

// time up to which pendingFees have been released

Value

0

streamEnd

int64

// time at which the rest is fully released

Value

0

releasedFees

func(now int64) int64
Open
OID
0c7b0a…bdec:224
releasedFees details

Inspect func

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.

Open
OID
0c7b0a…bdec:228
accrueFee details

Inspect func

PoolDeposit

func(amount int64) int64

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.

Open
OID
0c7b0a…bdec:229
PoolDeposit details

Inspect func

PoolWithdraw

func(shares int64) int64

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.

Open
OID
0c7b0a…bdec:230
PoolWithdraw details

Inspect func

PoolSharePrice

func() int64

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.

Open
OID
0c7b0a…bdec:231
PoolSharePrice details

Inspect func

PoolInfo

func() string

PoolInfo returns pool-wide figures, comma-separated: totalShares,poolAssets,feesAll,deskReserve (all micro, 6 dp).

Open
OID
0c7b0a…bdec:232
PoolInfo details

Inspect func

PoolOf

func(owner .uverse.address) string

PoolOf returns one depositor's position, comma-separated: shares,assets where assets is the current tUSD micro value of those shares.

Open
OID
0c7b0a…bdec:233
PoolOf details

Inspect func
usd : *v0.Token Inspect
usdLedger : *v0.PrivateLedger Inspect
initUSD : func() Inspect
FaucetUSD : func() Inspect
BalanceUSD : func(owner .uverse.address) int64 Inspect
costKey : type =v4.costKey
spotCost : map[v4.costKey]int64 Inspect
addCost : func(owner .uverse.address, ticker string, paid int64) Inspect
costOf : func(owner .uverse.address, ticker string) int64 Inspect
reduceCost : func(owner .uverse.address, ticker string, sold int64, heldBefore int64) Inspect
AvgEntry : func(ticker string, owner .uverse.address) int64 Inspect
AddMargin : func(id uint64, amount int64) Inspect
overLeveraged : func(p *v4.perp, mark int64) bool Inspect
Delever : func(id uint64) Inspect
deleverSize : func(p *v4.perp, mark int64, now int64) int64 Inspect
cutToMargin : func(p *v4.perp, sz int64, mark int64) Inspect
Overleveraged : func(offset int, count int) string Inspect
admin : .uverse.address =<gnolang.StringValue>
deskAddr : .uverse.address =<gnolang.StringValue>
nextTokID : v0.ID =<zero>
init.20 : func() Inspect
SetAdmin : func(a .uverse.address) Inspect
Admin : func() .uverse.address Inspect
DeskAddress : func() .uverse.address Inspect
assertAdmin : func() Inspect
Render : func(path string) string Inspect
usdFmt : func(micro int64) string Inspect
sharesFmt : func(units int64) string Inspect
num : func(v int64) string Inspect
ref : func(v uint64) string Inspect
sideOf : func(isLong bool) string Inspect
emitSpot : func(kind string, owner .uverse.address, ticker string, size int64, price int64, usd int64) Inspect
emitPerpOpen : func(p *v4.perp) Inspect
emitPerpClose : func(p *v4.perp, kind string, size int64, mark int64, payout int64) Inspect
emitOrder : func(kind string, o *v4.order, extra []string) Inspect
emitPerp : func(kind string, p *v4.perp, extra []string) Inspect
emitPool : func(kind string, owner .uverse.address, usd int64, shares int64) Inspect
Price : type =v4.Price
maxPriceAge : untyped bigint =(600 <untyped> bigint)
maxClockSkew : untyped bigint =(60 <untyped> bigint)
maxPrice : untyped bigint =(1000000000000 <untyped> bigint)
quoteWindow : untyped bigint =(120 <untyped> bigint)
agreeBps : untyped bigint =(100 <untyped> bigint)
maxUpdaters : untyped bigint =(7 <untyped> bigint)
updaters : [].uverse.address (len=2) Inspect
quorum : int =2
prices : map[string]v4.Price Inspect
submitted : map[string]map[.uverse.address]v4.Price Inspect
openVotes : map[.uverse.address]bool Inspect
marketOpen : bool =false
openedAt : int64 =0
AddUpdater : func(u .uverse.address) Inspect
RemoveUpdater : func(u .uverse.address) Inspect
SetQuorum : func(n int) Inspect
Updaters : func() string Inspect
Quorum : func() int Inspect
isUpdater : func(a .uverse.address) bool Inspect
assertUpdater : func() .uverse.address Inspect
SetPrices : func(quotes string, observedAt int64) Inspect
submit : func(from .uverse.address, ticker string, value int64, observedAt int64) Inspect
aggregate : func(ticker string) Inspect
median : func(vals []int64) int64 Inspect
GetPrice : func(ticker string) (int64, int64) Inspect
IsFresh : func(ticker string) bool Inspect
LastCallAt : func(ticker string) int64 Inspect
freshPrice : func(ticker string) int64 Inspect
pricedAfter : func(ticker string, t int64) bool Inspect
SetMarketOpen : func(open bool) Inspect
MarketVoteOf : func(u .uverse.address) string Inspect
tallyMarket : func() Inspect
IsMarketOpen : func() bool Inspect
maxPage : untyped bigint =(200 <untyped> bigint)
perps : *v0.Tree Inspect
ownerPerps : *v0.Tree Inspect
orders : *v0.Tree Inspect
ownerOrders : *v0.Tree Inspect
idKey : func(id uint64) string Inspect
ownerTree : func(index *v0.Tree, owner .uverse.address) *v0.Tree Inspect
putItem : func(all *v0.Tree, index *v0.Tree, owner .uverse.address, id uint64, item interface{...}) Inspect
dropItem : func(all *v0.Tree, index *v0.Tree, owner .uverse.address, id uint64) Inspect
eachOwned : func(index *v0.Tree, owner .uverse.address, cb func(...)) Inspect
eachPage : func(all *v0.Tree, offset int, count int, cb func(...)) Inspect
joinRow : func(out string, row string) string Inspect
OpenPerpCount : func() int Inspect
OrderCount : func() int Inspect
maxInt64 : uint64 =9223372036854775807
mulDiv : func(a int64, b int64, c int64) int64 Inspect
marketBandBps : untyped bigint =(200 <untyped> bigint)
orderTTL : untyped bigint =(900 <untyped> bigint)
order : type =v4.order
nextOrderID : uint64 =2
results : *v0.Tree Inspect
mustOrder : func(id uint64) *v4.order Inspect
isPerpOrder : func(o *v4.order) bool Inspect
bandPrice : func(mark int64, worseUp bool) int64 Inspect
pull : func(from .uverse.address, amount int64) Inspect
pay : func(to .uverse.address, amount int64) Inspect
queue : func(o *v4.order) uint64 Inspect
OpenPerp : func(ticker string, isLong bool, size int64, margin int64) uint64 Inspect
openMarket : func(owner .uverse.address, ticker string, isLong bool, size int64, margin int64) uint64 Inspect
PlaceLimit : func(ticker string, isLong bool, size int64, margin int64, limit int64) uint64 Inspect
placePerp : func(owner .uverse.address, kind string, ticker string, isLong bool, size int64, margin int64, limit int64, ref int64, lev int64) uint64 Inspect
Buy : func(ticker string, stockAmount int64) uint64 Inspect
Sell : func(ticker string, stockAmount int64) uint64 Inspect
CancelOrder : func(id uint64) Inspect
FillOrder : func(id uint64) uint64 Inspect
fillOrder : func(id uint64) uint64 Inspect
limitReady : func(o *v4.order, mark int64) bool Inspect
waitsForOpen : func(o *v4.order) bool Inspect
perpFill : type =v4.perpFill
quotePerp : func(o *v4.order, mark int64) (v4.perpFill, string) Inspect
fillable : func(o *v4.order) bool Inspect
fillPerp : func(o *v4.order, mark int64) uint64 Inspect
fillSize : func(o *v4.order, mark int64) int64 Inspect
limitFill : func(o *v4.order, mark int64) (size int64, margin int64, fee int64, refund int64) Inspect
fillBuy : func(o *v4.order, mark int64) Inspect
fillSell : func(o *v4.order, mark int64) Inspect
refund : func(o *v4.order, reason string) Inspect
done : func(o *v4.order, result string) Inspect
OrderStatus : func(id uint64) string Inspect
OrdersOf : func(owner .uverse.address) string Inspect
ReadyOrders : func(offset int, count int) string Inspect
perpFeeBps : untyped bigint =(10 <untyped> bigint)
maxLeverage : untyped bigint =(10 <untyped> bigint)
maintBps : untyped bigint =(1000 <untyped> bigint)
minMargin : untyped bigint =(1000000 <untyped> bigint)
perpMaxNotional : untyped bigint =(1000000000000 <untyped> bigint)
maxMargin : untyped bigint =(1000000000000 <untyped> bigint)
holdRateBpsYear : untyped bigint =(1000 <untyped> bigint)
secondsYear : untyped bigint =(31536000 <untyped> bigint)
perp : type =v4.perp
nextPerpID : uint64 =2
mustPerp : func(id uint64) *v4.perp Inspect
perpPnL : func(p *v4.perp, mark int64) int64 Inspect
perpEquity : func(p *v4.perp, mark int64) int64 Inspect
liquidatable : func(p *v4.perp, mark int64) bool Inspect
liqPrice : func(p *v4.perp) int64 Inspect
assertPerpSize : func(size int64) Inspect
assertMargin : func(margin int64) Inspect
openPositionCore : func(owner .uverse.address, ticker string, isLong bool, size int64, margin int64, price int64, fee int64) uint64 Inspect
ClosePerp : func(id uint64) Inspect
ClosePartial : func(id uint64, closeSize int64) Inspect
requestClose : func(owner .uverse.address, id uint64, size int64) Inspect
closingSize : func(p *v4.perp) int64 Inspect
FillClose : func(id uint64) Inspect
fillClose : func(id uint64) Inspect
Liquidate : func(id uint64) Inspect
holdingFee : func(p *v4.perp, now int64) int64 Inspect
sliceSettle : func(p *v4.perp, sz int64, mark int64, now int64) (payout int64, fee int64, hold int64, marginSlice int64) Inspect
collectedFee : func(p *v4.perp, sz int64, mark int64, marginSlice int64, owed int64) int64 Inspect
closePortion : func(p *v4.perp, sz int64, mark int64, kind string) Inspect
settlePerp : func(p *v4.perp, mark int64, kind string) Inspect
PerpsOf : func(owner .uverse.address) string Inspect
AllLiquidatable : func(offset int, count int) string Inspect
ReadyCloses : func(offset int, count int) string Inspect
lockedUSD : int64 =0
lock : func(amount int64) Inspect
unlock : func(amount int64) Inspect
freeReserve : func() int64 Inspect
LockedUSD : func() int64 Inspect
defaultOICap : untyped bigint =(250000000000 <untyped> bigint)
closedMaxLeverage : untyped bigint =(2 <untyped> bigint)
skewImpactMaxBps : untyped bigint =(100 <untyped> bigint)
skewScaleK : untyped bigint =(500000000000 <untyped> bigint)
oiLong : map[string]int64 Inspect
oiShort : map[string]int64 Inspect
oiCapOv : map[string]int64 Inspect
maxLevOv : map[string]int64 Inspect
oiCap : func(ticker string) int64 Inspect
openLevOf : func(ticker string) int64 Inspect
maxLevOf : func(ticker string) int64 Inspect
sideOI : func(ticker string, isLong bool) int64 Inspect
addOI : func(ticker string, isLong bool, notional int64) Inspect
subOI : func(ticker string, isLong bool, notional int64) Inspect
SetOICap : func(ticker string, perSide int64) Inspect
SetMaxLev : func(ticker string, lev int64) Inspect
OIOf : func(ticker string) string Inspect
skewImpactBps : func(ticker string, isLong bool, notional int64) int64 Inspect
skewEntry : func(price int64, impBps int64, isLong bool) int64 Inspect
stock : type =v4.stock
stocks : map[string]*v4.stock Inspect
tickers : []string (len=5) Inspect
defaultMarkets : []struct{...} (len=5) Inspect
initStocks : func() Inspect
listStock : func(ticker string, name string) Inspect
mustStock : func(ticker string) *v4.stock Inspect
StockBalance : func(ticker string, owner .uverse.address) int64 Inspect
StockSupply : func(ticker string) int64 Inspect
validateStops : func(p *v4.perp, sl int64, tp int64) Inspect
SetStops : func(id uint64, stopLoss int64, takeProfit int64) Inspect
stopFillable : func(p *v4.perp) bool Inspect
stopReady : func(p *v4.perp, mark int64) bool Inspect
TriggerStop : func(id uint64) Inspect
ReadyStops : func(offset int, count int) string Inspect
feeBps : untyped bigint =(30 <untyped> bigint)
bpsDenom : untyped bigint =(10000 <untyped> bigint)
microUSD : untyped bigint =(1000000 <untyped> bigint)
minTradeUnits : untyped bigint =(1000 <untyped> bigint)
maxTradeUnits : untyped bigint =(10000000000 <untyped> bigint)
notionalMicroUSD : func(price int64, stockAmount int64) int64 Inspect
assertTradeSize : func(stockAmount int64) Inspect
QuoteBuy : func(ticker string, stockAmount int64) int64 Inspect
QuoteSell : func(ticker string, stockAmount int64) int64 Inspect
SeedUSD : func(amount int64) Inspect
DeskReserveUSD : func() int64 Inspect
minPoolDeposit : untyped bigint =(1000000 <untyped> bigint)
minPoolShares : untyped bigint =(100000 <untyped> bigint)
feeStreamSec : untyped bigint =(86400 <untyped> bigint)
poolShares : int64 =0
poolAssets : int64 =0
poolFeesAll : int64 =0
poolBals : map[.uverse.address]int64 Inspect
pendingFees : int64 =0
streamAt : int64 =0
streamEnd : int64 =0
releasedFees : func(now int64) int64 Inspect
drip : func(now int64) Inspect
assetsNow : func() int64 Inspect
accrueFee : func(fee int64) Inspect
PoolDeposit : func(amount int64) int64 Inspect
PoolWithdraw : func(shares int64) int64 Inspect
PoolSharePrice : func() int64 Inspect
PoolInfo : func() string Inspect
PoolOf : func(owner .uverse.address) string Inspect