1package amm23import (4 "gno.land/p/nt/avl/v0"5 "gno.land/p/nt/grc20/v0"6 "gno.land/p/nt/testutils/v0"7)89// A fixed LP token for the examples, so the rendered symbol does not depend on10// how many pools the other tests happened to open first.11var (12 exLP *grc20.Token13 exLedge *grc20.PrivateLedger14)1516func init(cur realm) {17 exLP, exLedge = grc20.NewToken("AMM LP AAA/BBB", "LPDEMO", 6, 9999, cur)18 exLedge.Mint(testutils.TestAddress("lp"), 1_000_000)19}2021// seedExamplePool installs one deterministic pool so the examples below do not22// depend on which tests ran before them. The numbers are the worked example23// from the package docs: a 1,000,000 / 4,000,000 pool after a 100,000 swap.24func seedExamplePool() {25 pools = avl.Tree{}26 pools.Set(poolID(keyAAA, keyBBB), &pool{27 keyA: keyAAA, keyB: keyBBB,28 tokA: tokAAA, tokB: tokBBB,29 resA: 1_100_000, resB: 3_637_356,30 lp: exLP, lpLedger: exLedge,31 lpKey: "gno.land/r/moul/x/amm/v0.LPDEMO",32 })33}3435// ExampleRender pins the realm's home page.36func ExampleRender() {37 seedExamplePool()38 print(Render(""))39 // Output:40 // # Minimal AMM41 //42 // Constant product (`x*y=k`) with a 30 bps fee kept by the pool. Every position is a transferable GRC20 LP token. Reserves are stored, never read from balances, so sending tokens here directly does nothing and they cannot be recovered.43 //44 // | pool | reserves | LP token | supply | holders |45 // |---|---|---|---|---|46 // | [AAA/BBB](/r/moul/x/amm/v0:gno.land/r/moul/x/amm/v0.AAA~gno.land/r/moul/x/amm/v0.BBB) | 1100000 AAA / 3637356 BBB | LPDEMO | 1000000 | 1 |47}4849// ExampleRender_pool pins a single pool's detail page.50func ExampleRender_pool() {51 seedExamplePool()52 print(Render(poolID(keyAAA, keyBBB)))53 // Output:54 // # AAA / BBB55 //56 // - **AAA** reserve: 1100000 (`gno.land/r/moul/x/amm/v0.AAA`)57 // - **BBB** reserve: 3637356 (`gno.land/r/moul/x/amm/v0.BBB`)58 // - **LP token**: `gno.land/r/moul/x/amm/v0.LPDEMO` (LPDEMO)59 // - **LP shares**: 1000000 across 1 holder(s)60}6162// ExampleRender_unknown pins the miss.63func ExampleRender_unknown() {64 seedExamplePool()65 print(Render("nope"))66 // Output:67 // # 40468 //69 // No pool `nope`.70}71AddLiquidity(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, keyA string, keyB string, maxA int64, maxB int64) int64
AllowanceLP(keyA string, keyB string, owner string, spender string) int64
AmountOut(amountIn int64, reserveIn int64, reserveOut int64) int64
ApproveLP(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, keyA string, keyB string, spender string, amount int64)
LPToken(keyA string, keyB string) string
PoolCount() int
Quote(keyIn string, keyOut string, amountIn int64) int64
RemoveLiquidity(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, keyA string, keyB string, shares int64) (int64, int64)
Render(path string) string
Reserves(keyA string, keyB string) (int64, int64)
SharesOf(keyA string, keyB string, owner string) int64
Swap(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, keyIn string, keyOut string, amountIn int64, minOut int64) int64
TotalShares(keyA string, keyB string) int64
TransferFromLP(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, keyA string, keyB string, from string, to string, amount int64)
TransferLP(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, keyA string, keyB string, to string, amount int64)
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.
vm/qrender output, sanitized (docs/render-security.md) and displayed in an empty-sandbox iframe — scripts, forms and popups cannot run. Links stay inert in-preview; right-click to open.