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