render.gno
4.03 Kb · 100 lines
1package nativeify
2
3import (
4 "strings"
5
6 "gno.land/p/moul/kit/ui/v0"
7 "gno.land/p/moul/md/v0"
8 "gno.land/p/nt/ufmt/v0"
9)
10
11// Render lists the pairs. `?<base>` shows one.
12func Render(path string) string {
13 if path == "" {
14 return renderIndex()
15 }
16 return renderOne(path)
17}
18
19func renderIndex() string {
20 var sb strings.Builder
21 sb.WriteString(md.H1("nativeify: wugnot, backwards"))
22 sb.WriteString("\nwugnot takes a native coin and issues a GRC20, because a GRC20 can be " +
23 "pulled by a contract and a native coin cannot. This realm does the other one: escrow " +
24 "a GRC20, issue a native denom against it 1:1, and hand back something that moves with " +
25 "no realm call, rides the `-send` envelope of a transaction, and shows up beside GNOT " +
26 "on an account page.\n\n")
27 sb.WriteString(md.Blockquote("What you give up is everything downstream of `Approve`. A " +
28 "native coin has no allowance, so nothing can pull it: not an AMM, not an escrow, not " +
29 "a subscription. And its issuer can always delete a balance."))
30 sb.WriteString("\n")
31 sb.WriteString(ufmt.Sprintf("Escrow account to approve: `%s`\n\n", home.String()))
32
33 sb.WriteString(md.H2("Pairs") + "\n")
34 t := ui.NewTable("base", "underlying", "denom", "escrowed", "issued", "solvent")
35 for _, b := range bases {
36 p := mustPair(b)
37 escrowed, issued := Solvency(b)
38 solvent := "yes"
39 if escrowed < issued {
40 solvent = "**NO**"
41 }
42 t.Row(md.Link(b, "/r/moul/x/nativeify/v0:"+b),
43 ui.Cell(Underlying(b).GetSymbol()),
44 md.InlineCode(ui.ShortN(p.denom, 20, 10)),
45 ufmt.Sprintf("%d", escrowed), ufmt.Sprintf("%d", issued), solvent)
46 }
47 sb.WriteString(t.OrEmpty("Nothing wrapped yet.") + "\n")
48
49 sb.WriteString(md.H2("Try it") + "\n")
50 sb.WriteString("Claim play money, let this realm pull it, wrap, then send the result " +
51 "around like any other coin:\n\n")
52 sb.WriteString(md.LanguageCodeBlock("",
53 "# 1. get RED\n"+
54 "maketx call -pkgpath gno.land/r/moul/x/grc20faucet/v0 -func Claim\n\n"+
55 "# 2. let this realm pull your RED\n"+
56 "maketx call -pkgpath gno.land/r/moul/x/grc20faucet/v0 -func Approve \\\n"+
57 ufmt.Sprintf(" -args RED -args %s -args 1000000\n\n", home.String())+
58 "# 3. create the pair once, then wrap into it\n"+
59 "maketx call -pkgpath "+Path+" -func Nativeify \\\n"+
60 " -args gno.land/r/moul/x/grc20faucet/v0.RED -args nred\n"+
61 "maketx call -pkgpath "+Path+" -func Wrap -args nred -args 500000\n\n"+
62 "# 4. it is an ordinary coin now: no realm call, no approval\n"+
63 "maketx send -to <address> -send 1000/"+Path+":nred\n\n"+
64 "# 5. redeem, by sending the coins back\n"+
65 "maketx call -pkgpath "+Path+" -func Unwrap -args nred \\\n"+
66 " -send 1000/"+Path+":nred"))
67 sb.WriteString("\nEvery denom here is described in [nativereg](/r/moul/x/nativereg/v0), " +
68 "which is where a native coin says what it is, since the chain stores no name for it.\n")
69 return sb.String()
70}
71
72func renderOne(base string) string {
73 v := byBase.Get(base)
74 if v == nil {
75 return md.H1("404") + "\nThis realm does not issue " + md.InlineCode(base) + ".\n"
76 }
77 p := v.(*pair)
78 under := Underlying(base)
79 escrowed, issued := Solvency(base)
80
81 t := ui.NewTable("", "")
82 t.Row("denom", md.InlineCode(p.denom))
83 t.Row("underlying", ui.Cell(under.GetName())+" ("+ui.Cell(under.GetSymbol())+")")
84 t.Row("registry key", md.InlineCode(p.key))
85 t.Row("decimals", ufmt.Sprintf("%d, a display hint only", under.GetDecimals()))
86 t.Row("escrowed", ufmt.Sprintf("%d", escrowed))
87 t.Row("issued", ufmt.Sprintf("%d", issued))
88 t.Row("solvent", ufmt.Sprintf("%t", escrowed >= issued))
89 t.Row("created at block", ufmt.Sprintf("%d", p.height))
90 t.Row("created by", ui.Addr(p.creator))
91
92 s := md.H1(ui.Inline(base)) + "\n" + t.String() + "\n"
93 s += "Escrowed and issued are read from the GRC20 ledger and from the bank, not from " +
94 "this realm's own bookkeeping. If they disagree, the disagreement is the answer.\n\n"
95 s += md.LanguageCodeBlock("",
96 "maketx call -pkgpath "+Path+" -func Wrap -args "+base+" -args <amount>\n"+
97 "maketx call -pkgpath "+Path+" -func Unwrap -args "+base+" \\\n"+
98 " -send <amount>"+p.denom)
99 return s
100}