aaabbb.gno
2.51 Kb · 63 lines
1// Realm aaabbb is ONE AMM pair, AAA/BBB, and nothing else.
2//
3// This is the whole instance half of the instance-per-realm pattern, and it is
4// meant to be read in full in one screen: two configuration constants, an init
5// that builds the pair and announces it to the registry, and one-line
6// re-exports that forward the realm's own `cur` into the shared logic in
7// p/moul/x/pair/v0. Every instance in the ecosystem is byte-identical to this
8// file except for the two constants, which is what makes verifying an
9// unknown instance a two-line diff.
10//
11// The re-exports cannot be factored away: MsgCall addresses a realm path and a
12// function name, so anything a user calls has to be declared here.
13//
14// State and funds belong to THIS realm: the pair struct is its variable, the
15// tokens sit at its own package address, and its creator paid its storage
16// deposit. A bug in one instance cannot touch another.
17//
18// Pattern, and why an AMM is the contested case for it: see the README of
19// gno.land/p/moul/x/pair/v0.
20package aaabbb
21
22import (
23 "gno.land/p/moul/x/pair/v0"
24 "gno.land/r/moul/x/pairreg/v0"
25 "gno.land/r/nt/grc20reg/v0"
26
27 // Only because both tokens live in this same repository: the blank imports
28 // force their init (and therefore their grc20reg registration) to run
29 // before this one in a test binary. An instance deployed on chain against
30 // already-deployed tokens does not need them.
31 _ "gno.land/r/moul/x/pairs/aaa/v0"
32 _ "gno.land/r/moul/x/pairs/bbb/v0"
33)
34
35// The only two lines that differ between two instances.
36const (
37 keyA = "gno.land/r/moul/x/pairs/aaa/v0.AAA"
38 keyB = "gno.land/r/moul/x/pairs/bbb/v0.BBB"
39)
40
41var p *pair.Pair
42
43func init(cur realm) {
44 p = pair.New(keyA, keyB, grc20reg.MustGet(keyA), grc20reg.MustGet(keyB))
45 pairreg.Register(cross(cur), p)
46}
47
48func AddLiquidity(cur realm, maxA, maxB int64) int64 { return p.AddLiquidity(0, cur, maxA, maxB) }
49
50func RemoveLiquidity(cur realm, shares int64) (int64, int64) {
51 return p.RemoveLiquidity(0, cur, shares)
52}
53
54func Swap(cur realm, keyIn string, amountIn, minOut int64) int64 {
55 return p.Swap(0, cur, keyIn, amountIn, minOut)
56}
57
58func Quote(keyIn string, amountIn int64) int64 { return p.Quote(keyIn, amountIn) }
59func Reserves() (int64, int64) { return p.Reserves() }
60func SharesOf(owner address) int64 { return p.SharesOf(owner) }
61func TotalShares() int64 { return p.TotalShares() }
62func Keys() (string, string) { return p.Keys() }
63func Render(path string) string { return p.Render(path) }