render.gno
3.23 Kb · 97 lines
1package grc20wrapdemo
2
3import (
4 "gno.land/p/nt/ufmt/v0"
5)
6
7func Render(path string) string {
8 if path == "" {
9 return renderIndex()
10 }
11 return renderOne(path)
12}
13
14func renderIndex() string {
15 s := "# GRC20 wrapper factory\n\n"
16 s += "Wrap any token registered in [grc20reg](/r/nt/grc20reg/v0) into a new one "
17 s += "with a different personality, or fuse two into one. Permissionless: "
18 s += "no allowlist, no owner, no authority over anybody's balance.\n\n"
19 s += ufmt.Sprintf("Escrow account to approve: `%s`\n\n", home.String())
20
21 s += "## Modes\n\n"
22 s += "| mode | what the wrapped token does |\n"
23 s += "|---|---|\n"
24 s += "| `plain` | 1:1 custody receipt |\n"
25 s += "| `kilo` | 1 underlying unit becomes 1000 wrapped, +3 decimals |\n"
26 s += "| `soulbound` | wrap and unwrap freely, never transferable |\n"
27 s += "| `pool` | shares in the escrow; `Donate` pays every holder at once |\n"
28 s += "| `sticky` | `pool` plus a 1% exit fee, left behind for whoever stays |\n"
29 s += "| `fusion` | one meta-token backed by a fixed bundle of two others |\n"
30
31 s += "\n## Issued here\n\n"
32 if len(created) == 0 {
33 s += "Nothing yet. Be the first.\n"
34 } else {
35 s += "| symbol | mode | backing | supply | registry key |\n"
36 s += "|---|---|---|---|---|\n"
37 for _, sym := range created {
38 e := must(sym)
39 s += ufmt.Sprintf("| [%s](/r/moul/x/grc20wrapdemo/v0:%s) | %s | %s | %d | `%s` |\n",
40 e.symbol, e.symbol, e.mode, e.backing(), e.token().TotalSupply(), e.key)
41 }
42 }
43
44 s += "\n## Try it\n\n"
45 s += "Claim play money from [the faucet](/r/moul/x/grc20faucet/v0), let this realm\n"
46 s += "spend it, then wrap:\n\n"
47 s += "```\n"
48 s += "# 1. get RED and BLUE\n"
49 s += "maketx call -pkgpath gno.land/r/moul/x/grc20faucet/v0 -func Claim\n\n"
50 s += "# 2. let this realm pull your RED\n"
51 s += "maketx call -pkgpath gno.land/r/moul/x/grc20faucet/v0 -func Approve \\\n"
52 s += ufmt.Sprintf(" -args RED -args %s -args 1000000\n\n", home.String())
53 s += "# 3. create a pool wrapper over RED, then deposit into it\n"
54 s += "maketx call -pkgpath gno.land/r/moul/x/grc20wrapdemo/v0 -func NewWrapper \\\n"
55 s += " -args gno.land/r/moul/x/grc20faucet/v0.RED -args pool -args pRED\n"
56 s += "maketx call -pkgpath gno.land/r/moul/x/grc20wrapdemo/v0 -func Deposit \\\n"
57 s += " -args pRED -args 500000\n"
58 s += "```\n\n"
59 s += "Built on [p/moul/x/grc20wrap](/p/moul/x/grc20wrap/v0).\n"
60 return s
61}
62
63func renderOne(symbol string) string {
64 e := byName.Get(symbol)
65 if e == nil {
66 return "# 404\n\nThis realm has not issued `" + symbol + "`.\n"
67 }
68 en := e.(*entry)
69
70 s := ufmt.Sprintf("# %s\n\n", en.symbol)
71 if en.vault != nil {
72 s += en.vault.Summary()
73 } else {
74 s += en.basket.Summary()
75 }
76 s += ufmt.Sprintf("\n- mode: `%s`\n", en.mode)
77 s += ufmt.Sprintf("- registry key: `%s`\n", en.key)
78 s += ufmt.Sprintf("- created by: `%s` at block %d\n", en.creator.String(), en.height)
79 s += "\n[back to the index](/r/moul/x/grc20wrapdemo/v0)\n"
80 return s
81}
82
83// backing names what an entry is redeemable for, for the index table.
84func (e *entry) backing() string {
85 if e.vault != nil {
86 return e.vault.Underlying().GetSymbol()
87 }
88 out := ""
89 for i := 0; i < e.basket.Legs(); i++ {
90 tok, per, _ := e.basket.Leg(i)
91 if i > 0 {
92 out += " + "
93 }
94 out += ufmt.Sprintf("%dx%s", per, tok.GetSymbol())
95 }
96 return out
97}