Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

v0 state

Back to all declarations

feeNum

untyped bigint

Value

(997 <untyped> bigint)

feeDen

untyped bigint

Value

(1000 <untyped> bigint)

maxReserve

untyped bigint

// 9223372036854775

Value

(9223372036854775 <untyped> bigint)

pool

type

pool is one token pair. keyA \< keyB always holds: the pair is canonicalised on the way in, so (X,Y) and (Y,X) address the same pool.

Value

v0.pool

pools

v0.Tree

pools maps the pool id "keyA~keyB" -> \*pool. "~" cannot occur in a grc20reg key, and unlike "|" it does not break a markdown table cell.

Open
OID
0fed64…7ec1:4
pools details

Inspect ref

lpSeq

v0.ID

lpSeq numbers the LP tokens. It is never reset, so a symbol is never reused and grc20reg's one-token-per-realm-and-symbol rule is never tripped.

Value

<zero>

AddLiquidity

func(keyA string, keyB string, maxA int64, maxB int64) int64

AddLiquidity deposits up to maxA of keyA and maxB of keyB and mints LP shares to the caller. It creates the pool if this is its first deposit, in which case the caller's amounts set the starting price and the whole of maxA and maxB is taken. On an existing pool the deposit is trimmed to the current reserve ratio: only one side is consumed in full and the remainder of the richer side is left untouched, so pass the amounts you are willing to spend, not the amounts you insist on spending. The caller must first Approve this realm's address on BOTH tokens for at least the amounts that will be taken. Returns the shares minted.

Open
OID
0fed64…7ec1:6
AddLiquidity details

Inspect func

RemoveLiquidity

func(keyA string, keyB string, shares int64) (int64, int64)

RemoveLiquidity burns shares held by the caller and returns the proportional amounts of both tokens, in the caller's (keyA, keyB) argument order. Burning the pool's entire share supply pays out the whole reserve, so the last provider out leaves nothing unclaimable behind and the pool can be reseeded at a fresh price.

Open
OID
0fed64…7ec1:8
RemoveLiquidity details

Inspect func

Swap

func(keyIn string, keyOut string, amountIn int64, minOut int64) int64

Swap sells amountIn of keyIn for keyOut and aborts unless at least minOut comes back. The caller must first Approve this realm's address on keyIn. minOut is the only protection against being sandwiched or against the pool moving between quoting and execution. Pass a real bound; passing 0 means accepting any price at all.

Open
OID
0fed64…7ec1:9
Swap details

Inspect func

TransferLP

func(keyA string, keyB string, to .uverse.address, amount int64)

TransferLP moves amount of the caller's LP position to \`to\`. The LP token lives in this realm, so a signing user cannot reach it through the token's own entry points the way they would for any other GRC20: there are none. These four wrappers are that entry point. A REALM holding LP does not need them and can go through grc20reg instead: grc20reg.Transfer(0, cur, amm.LPToken(keyA, keyB), to, n)

Open
OID
0fed64…7ec1:10
TransferLP details

Inspect func

ApproveLP

func(keyA string, keyB string, spender .uverse.address, amount int64)

ApproveLP lets spender move up to amount of the caller's LP position. Same approve race as any GRC20: an allowance changed from a non-zero value can be spent at both the old and the new one if the holder is unlucky with ordering. Set it to 0 first when lowering it.

Open
OID
0fed64…7ec1:11
ApproveLP details

Inspect func

TransferFromLP

func(keyA string, keyB string, from .uverse.address, to .uverse.address, amount int64)

TransferFromLP spends an allowance the owner granted to the caller.

Open
OID
0fed64…7ec1:12
TransferFromLP details

Inspect func

AmountOut

func(amountIn int64, reserveIn int64, reserveOut int64) int64

AmountOut is the pricing function, fee included, as a pure function of the two reserves. Exported so a caller can quote off-chain against reserves it already holds, and so the arithmetic is testable on its own.

Open
OID
0fed64…7ec1:14
AmountOut details

Inspect func

Quote

func(keyIn string, keyOut string, amountIn int64) int64

Quote prices amountIn of keyIn against the pool's live reserves. It is the number Swap would return right now, which is not a promise about the next block.

Open
OID
0fed64…7ec1:15
Quote details

Inspect func

Reserves

func(keyA string, keyB string) (int64, int64)

Reserves returns the two reserves in the caller's argument order.

Open
OID
0fed64…7ec1:16
Reserves details

Inspect func

SharesOf

func(keyA string, keyB string, owner .uverse.address) int64

SharesOf returns owner's LP shares, i.e. their LP token balance.

Open
OID
0fed64…7ec1:17
SharesOf details

Inspect func

TotalShares

func(keyA string, keyB string) int64

TotalShares returns the pool's LP token total supply.

Open
OID
0fed64…7ec1:18
TotalShares details

Inspect func

LPToken

func(keyA string, keyB string) string

LPToken returns the grc20reg key of the pool's LP token. Hand it to any realm that should read or move these positions without importing this one.

Open
OID
0fed64…7ec1:19
LPToken details

Inspect func

AllowanceLP

func(keyA string, keyB string, owner .uverse.address, spender .uverse.address) int64

AllowanceLP reports how much of owner's LP position spender may move.

Open
OID
0fed64…7ec1:20
AllowanceLP details

Inspect func

PoolCount

func() int

PoolCount returns how many pools exist.

Open
OID
0fed64…7ec1:21
PoolCount details

Inspect func

Render

func(path string) string

Render lists every pool, or one pool's detail when path is a "keyA~keyB" pool id.

Open
OID
0fed64…7ec1:22
Render details

Inspect func

canon

func(first string, second string) (a string, b string, flipped bool)

canon sorts a caller's token pair into the pool's canonical order and reports whether the caller's order was reversed.

Open
OID
0fed64…7ec1:23
canon details

Inspect func

newPool

func(int, rlm .uverse.realm, a string, b string) *v0.pool

newPool resolves both tokens, mints this pool's LP token and registers it. Non-crossing (\`\_ int, rlm realm\`): grc20.NewToken binds the token's origRealm to rlm.PkgPath() under an IsCurrent assertion, and grc20reg keys off the registering caller, so rlm has to stay AddLiquidity's own live frame rather than a fresh one. The LP unit is token A at seed time, so the LP token mirrors token A's decimals. The symbol is LP\<n> because grc20 caps a symbol at 11 chars, which "LP-" plus two 11-char symbols would blow past; the human-readable pair lives in the name instead.

Open
OID
0fed64…7ec1:24
newPool details

Inspect func

poolID

func(a string, b string) string

poolID is the storage and render key for a canonicalised pair.

Open
OID
0fed64…7ec1:25
poolID details

Inspect func

getPool

func(a string, b string) *v0.pool
Open
OID
0fed64…7ec1:26
getPool details

Inspect func

mustPool

func(a string, b string) *v0.pool
Open
OID
0fed64…7ec1:27
mustPool details

Inspect func

pull

func(int, rlm .uverse.realm, tok *v0.Token, from .uverse.address, to .uverse.address, amount int64)

pull moves amount of tok from \`from\` into this realm, spending the allowance \`from\` granted to this realm's address. Non-crossing on purpose: \`\_ int, rlm realm\` is the only shape that keeps rlm the caller's own live frame. RealmTeller binds the spender eagerly to rlm.Address(), which is this realm.

Open
OID
0fed64…7ec1:28
pull details

Inspect func

push

func(int, rlm .uverse.realm, tok *v0.Token, to .uverse.address, amount int64)

push sends amount of tok from this realm to \`to\`.

Open
OID
0fed64…7ec1:29
push details

Inspect func

mulDiv

func(a int64, b int64, c int64) int64

mulDiv returns floor(a\*b/c) through a 128-bit intermediate, which plain int64 arithmetic cannot do: a\*b is routinely wider than 63 bits here even when the quotient is small.

Open
OID
0fed64…7ec1:30
mulDiv details

Inspect func

cmpProd

func(a int64, b int64, c int64, d int64) int

cmpProd compares a\*b with c\*d exactly, in 128 bits, and returns -1, 0 or 1.

Open
OID
0fed64…7ec1:31
cmpProd details

Inspect func
feeNum : untyped bigint =(997 <untyped> bigint)
feeDen : untyped bigint =(1000 <untyped> bigint)
maxReserve : untyped bigint =(9223372036854775 <untyped> bigint)
pool : type =v0.pool
pools : v0.Tree Inspect
lpSeq : v0.ID =<zero>
AddLiquidity : func(keyA string, keyB string, maxA int64, maxB int64) int64 Inspect
RemoveLiquidity : func(keyA string, keyB string, shares int64) (int64, int64) Inspect
Swap : func(keyIn string, keyOut string, amountIn int64, minOut int64) int64 Inspect
TransferLP : func(keyA string, keyB string, to .uverse.address, amount int64) Inspect
ApproveLP : func(keyA string, keyB string, spender .uverse.address, amount int64) Inspect
TransferFromLP : func(keyA string, keyB string, from .uverse.address, to .uverse.address, amount int64) Inspect
lpCheck : func(err .uverse.error) Inspect
AmountOut : func(amountIn int64, reserveIn int64, reserveOut int64) int64 Inspect
Quote : func(keyIn string, keyOut string, amountIn int64) int64 Inspect
Reserves : func(keyA string, keyB string) (int64, int64) Inspect
SharesOf : func(keyA string, keyB string, owner .uverse.address) int64 Inspect
TotalShares : func(keyA string, keyB string) int64 Inspect
LPToken : func(keyA string, keyB string) string Inspect
AllowanceLP : func(keyA string, keyB string, owner .uverse.address, spender .uverse.address) int64 Inspect
PoolCount : func() int Inspect
Render : func(path string) string Inspect
canon : func(first string, second string) (a string, b string, flipped bool) Inspect
newPool : func(int, rlm .uverse.realm, a string, b string) *v0.pool Inspect
poolID : func(a string, b string) string Inspect
getPool : func(a string, b string) *v0.pool Inspect
mustPool : func(a string, b string) *v0.pool Inspect
pull : func(int, rlm .uverse.realm, tok *v0.Token, from .uverse.address, to .uverse.address, amount int64) Inspect
push : func(int, rlm .uverse.realm, tok *v0.Token, to .uverse.address, amount int64) Inspect
mulDiv : func(a int64, b int64, c int64) int64 Inspect
cmpProd : func(a int64, b int64, c int64, d int64) int Inspect
min64 : func(a int64, b int64) int64 Inspect
itoa : func(v int64) string Inspect