Playground
gnomod.toml
module = "gno.land/r/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/x/nativeify/v0" gno = "0.9" [addpkg] creator = "g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv" height = 915402 max_deposit = "13000000ugnot"
nativeify.gno
// Package nativeify turns a GRC20 into a native coin, which is wugnot run
// backwards.
//
// wugnot takes GNOT, a coin the bank holds, and issues a GRC20 receipt for it,
// because a GRC20 can be pulled by a contract and a native coin cannot. This
// realm takes a GRC20, escrows it, and issues a native denom against it 1:1,
// because a native coin can do four things a GRC20 cannot:
//
// - move with no realm call at all (`gnokey maketx send`, from any wallet)
// - ride the `-send` envelope of a call, so it can PAY for something
// - sit beside GNOT on an account page, with nothing registered anywhere
// - be named as the gas denom by a chain whose genesis says so
//
// # What you give up, and it is not small
//
// A native coin cannot be pulled. `banker.SendCoins` refuses any `from` that is
// not the banker's own realm address, so there is no allowance, no
// `TransferFrom`, and no way for an AMM, an escrow or a subscription to take
// what you approved. Everything downstream of `Approve` stops working the moment
// a coin becomes native. That is not a gap in this realm; it is the property
// that makes the wrapping worth doing in the other direction.
//
// And the issuer of a native coin can always delete a balance: `RemoveCoin`
// takes an arbitrary address. This realm never calls it on an address other than
// its own, [Unwrap] explains why in detail, and the gnomod.toml explains why this
// path is public rather than redeployable. Those three together are the entire
// guarantee. There is no on-chain way to prove a negative about code.
//
// # The exchange rate is 1, always
//
// One smallest unit of the underlying is one unit of the coin. Not 10^decimals:
// the bank has no notion of divisibility, so a token with 6 decimals wrapped
// here produces a coin counted in the token's own smallest units, and the 6 is
// carried to `r/moul/x/nativereg` as a display hint and nowhere else.
//
// Solvency is therefore a plain equality that anybody can check without trusting
// this realm's bookkeeping: the GRC20 balance at this realm's address equals the
// total supply of the denom. [Solvency] computes it from both sides.
//
// Play money to try it on: `r/moul/x/grc20faucet/v0`.
package nativeify
import (
"chain"
"chain/banker"
"chain/runtime"
"strings"
"gno.land/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/x/envelope/v0"
"gno.land/p/nt/avl/v0"
"gno.land/p/nt/grc20/v0"
"gno.land/p/nt/ufmt/v0"
"gno.land/r/nt/grc20reg/v0"
"gno.land/r/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/x/nativereg/v0"
)
// Path is this realm's package path, which every denom it issues embeds.
const Path = "gno.land/r/moul/x/nativeify/v0"
// MinBase and MaxBase bound a base denom name. The chain enforces exactly this
// (`isValidBaseDenom` in the banker stdlib): a lowercase letter, then 2 to 15
// more lowercase letters or digits. Validating here rather than letting the
// banker abort is the difference between a usable error and a stack trace.
const (
MinBase = 3
MaxBase = 16
)
type pair struct {
base string // base denom name, unique in this realm
denom string // the full chain denom
key string // grc20reg key of the underlying
creator address
height int64
}
var (
byBase = avl.NewTree() // base name -> *pair
byKey = avl.NewTree() // grc20reg key -> *pair
bases []string // creation order, for a stable Render
home address // this realm's address: where every escrow sits
)
func init(cur realm) {
home = cur.Address()
}
// Home is the address to approve on the underlying token before wrapping. Every
// escrow this realm holds sits there.
func Home() address { return home }
// Nativeify creates the native counterpart of a GRC20 registered in
// `r/nt/grc20reg`, and returns its denom. It issues nothing: [Wrap] does that.
//
// `base` is the part of the denom after the colon, yours to choose, unique in
// this realm and in the chain's charset. One native denom per underlying token:
// a second one would double the chain's per-denom storage for no new capability,
// and realm-denom balances live under their own store keys, which are not
// gas-metered.
func Nativeify(cur realm, tokenKey, base string) string {
under := grc20reg.MustGet(tokenKey)
assertBase(base)
if byBase.Get(base) != nil {
panic("this realm already issues " + base)
}
if v := byKey.Get(tokenKey); v != nil {
panic(ufmt.Sprintf("%s is already native here as %s", under.GetSymbol(), v.(*pair).denom))
}
p := &pair{
base: base,
denom: chain.CoinDenom(Path, base),
key: tokenKey,
creator: cur.Previous().Address(),
height: runtime.ChainHeight(),
}
byBase.Set(base, p)
byKey.Set(tokenKey, p)
bases = append(bases, base)
// This realm is the issuer named inside the denom, so it is the only thing
// on the chain that can describe it. The decimals travel as a display hint;
// the bank still counts whole units.
nativereg.Register(cross(cur), p.denom,
under.GetName()+" (native)", "n"+under.GetSymbol(), under.GetDecimals(),
"1:1 native wrapper of "+tokenKey+", redeemable at "+Path)
return p.denom
}
// Wrap escrows `amount` of the underlying and issues the same number of native
// coins to the caller.
//
// You must `Approve` this realm's address on the underlying token first, through
// that token's own realm. Until you do, this realm has no authority over your
// balance at all, and Wrap fails with "insufficient allowance", which is the
// system working.
func Wrap(cur realm, base string, amount int64) int64 {
p := mustPair(base)
if amount <= 0 {
panic("wrap a positive amount")
}
who := cur.Previous().Address()
// Last point at which nothing has moved.
under := grc20reg.MustGet(p.key)
if err := under.RealmTeller(0, cur).TransferFrom(0, cur, who, home, amount); err != nil {
panic(err)
}
banker.NewBanker(banker.BankerTypeRealmIssue, cur).IssueCoin(who, p.denom, amount)
return amount
}
// Unwrap destroys the native coins attached to this call and releases the same
// number of underlying GRC20 units to the caller.
//
// # Why you have to send the coins rather than let this realm take them
//
// This realm holds a `BankerTypeRealmIssue` banker, and `RemoveCoin` takes an
// arbitrary address, so it could delete the caller's coins directly and save
// them a flag. It does not, and the reason is worth stating where somebody
// copying this will read it: a realm whose normal operation is to remove coins
// from addresses that did not hand them over has no way left to demonstrate that
// it only ever does so consensually. Every `RemoveCoin` here names this realm's
// own address, which anybody can check by reading the source, and the coins get
// to that address the only way a native coin ever moves, by their holder pushing
// them.
//
// So: attach them.
//
// -send <amount>/gno.land/r/moul/x/nativeify/v0:<base>
func Unwrap(cur realm, base string) int64 {
p := mustPair(base)
// Reading the envelope is also what makes this call payable at all: MsgCall
// rejects a message whose coins no code looked at.
amount := envelope.Require(p.denom)
who := cur.Previous().Address()
// Destroy the receipt before releasing the backing, so a failure between the
// two can only ever leave the pair over-collateralized.
banker.NewBanker(banker.BankerTypeRealmIssue, cur).RemoveCoin(home, p.denom, amount)
under := grc20reg.MustGet(p.key)
if err := under.RealmTeller(0, cur).Transfer(0, cur, who, amount); err != nil {
panic(err)
}
return amount
}
// Denom returns the denom this realm issues for a base name.
func Denom(base string) string { return mustPair(base).denom }
// TokenKey returns the grc20reg key of the underlying behind a base name.
func TokenKey(base string) string { return mustPair(base).key }
// Bases returns every base name this realm issues, in creation order.
func Bases() []string {
out := make([]string, len(bases))
copy(out, bases)
return out
}
// Solvency returns what is escrowed and what is issued for a base name. They are
// read from two different places on the chain, the GRC20 ledger and the bank,
// and this realm's own bookkeeping is not consulted for either: if they ever
// disagree, the disagreement is the answer.
func Solvency(base string) (escrowed, issued int64) {
p := mustPair(base)
escrowed = grc20reg.MustGet(p.key).BalanceOf(home)
issued = banker.NewReadonlyBanker().TotalCoin(p.denom)
return escrowed, issued
}
// IsSolvent reports whether every coin issued for a base name is backed.
//
// It allows escrowed > issued, which is what a donation to this realm's address
// looks like and cannot hurt anybody, and refuses the reverse.
func IsSolvent(base string) bool {
escrowed, issued := Solvency(base)
return escrowed >= issued
}
// Underlying returns the underlying token behind a base name, for a caller that
// wants its name, symbol or decimals.
func Underlying(base string) *grc20.Token {
return grc20reg.MustGet(mustPair(base).key)
}
func mustPair(base string) *pair {
v := byBase.Get(base)
if v == nil {
panic("this realm does not issue " + base)
}
return v.(*pair)
}
// assertBase applies the chain's own base-denom rule before the banker does, so
// the caller reads a sentence instead of a stack trace.
func assertBase(base string) {
if len(base) < MinBase || len(base) > MaxBase {
panic(ufmt.Sprintf("base %q is %d characters, must be %d to %d",
base, len(base), MinBase, MaxBase))
}
for i := 0; i < len(base); i++ {
c := base[i]
lower := c >= 'a' && c <= 'z'
digit := c >= '0' && c <= '9'
if lower || (i > 0 && digit) {
continue
}
panic(ufmt.Sprintf("base %q: a base denom is a lowercase letter followed by "+
"lowercase letters or digits, and %q is not", base, string(c)))
}
if strings.Contains(base, ":") { // unreachable past the charset loop; belt and braces
panic("a base denom cannot contain a colon")
}
}
nativeify_test.gno
package nativeify
import (
"chain"
"chain/banker"
"strings"
"testing"
"gno.land/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/x/envelope/v0"
"gno.land/p/nt/testutils/v0"
"gno.land/p/nt/uassert/v0"
"gno.land/r/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/x/grc20faucet/v0"
"gno.land/r/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/x/nativereg/v0"
)
// Two things about the harness shape every test below.
//
// testing.SetRealm governs only the crossing calls made from the frame that
// called it, so every account switch is inline in the test body.
//
// The BANK does not carry over between test functions while realm state does,
// so native balances, TotalCoin and the escrowed GRC20 cannot be compared
// across tests. Everything here is asserted as a delta inside one test.
func TestNativeifyCreatesThePair(cur realm, t *testing.T) {
alice := testutils.TestAddress("nf-alice")
testing.SetRealm(testing.NewUserRealm(alice))
denom := Nativeify(cross(cur), grc20faucet.RedKey, "nred")
uassert.Equal(t, "/gno.land/r/moul/x/nativeify/v0:nred", denom)
uassert.Equal(t, denom, Denom("nred"))
uassert.Equal(t, grc20faucet.RedKey, TokenKey("nred"))
// The denom names this realm, so this realm is the only thing on the chain
// that can describe it, and it did.
e := nativereg.MustGet(denom)
uassert.Equal(t, Path, e.Issuer)
uassert.Equal(t, "nRED", e.Symbol)
uassert.Equal(t, 4, e.Decimals, "the underlying's decimals travel as a display hint")
uassert.AbortsContains(t, cur, "already issues nred", func() {
Nativeify(cross(cur), grc20faucet.BlueKey, "nred")
})
uassert.AbortsContains(t, cur, "already native here", func() {
Nativeify(cross(cur), grc20faucet.RedKey, "nred2")
})
uassert.AbortsContains(t, cur, "unknown token", func() {
Nativeify(cross(cur), "gno.land/r/nope/nope.NOPE", "nnope")
})
}
func TestBaseNameFollowsTheChainsRule(cur realm, t *testing.T) {
bob := testutils.TestAddress("nf-bob")
testing.SetRealm(testing.NewUserRealm(bob))
// The chain's own rule, applied here so the caller reads a sentence instead
// of a banker stack trace: a lowercase letter, then 2 to 15 more lowercase
// letters or digits.
uassert.AbortsContains(t, cur, "is 2 characters", func() {
Nativeify(cross(cur), grc20faucet.BlueKey, "ab")
})
uassert.AbortsContains(t, cur, "is 17 characters", func() {
Nativeify(cross(cur), grc20faucet.BlueKey, strings.Repeat("a", 17))
})
uassert.AbortsContains(t, cur, "is not", func() {
Nativeify(cross(cur), grc20faucet.BlueKey, "nBLUE")
})
uassert.AbortsContains(t, cur, "is not", func() {
Nativeify(cross(cur), grc20faucet.BlueKey, "1blue")
})
uassert.AbortsContains(t, cur, "is not", func() {
Nativeify(cross(cur), grc20faucet.BlueKey, "n-blue")
})
// And one that is legal all the way through.
uassert.Equal(t, "/gno.land/r/moul/x/nativeify/v0:nblue1",
Nativeify(cross(cur), grc20faucet.BlueKey, "nblue1"))
}
func TestWrapNeedsAnAllowanceFirst(cur realm, t *testing.T) {
carol := testutils.TestAddress("nf-carol")
testing.SetRealm(testing.NewUserRealm(carol))
grc20faucet.Claim(cross(cur))
// Until the holder names this realm on the underlying token, this realm has
// no authority over their balance whatsoever. That is the GRC20 half of the
// trade, and it is the half a native coin does not have.
uassert.AbortsContains(t, cur, "allowance", func() { Wrap(cross(cur), "nred", 1_000) })
uassert.Equal(t, int64(0), envelope.BalanceOf(carol, Denom("nred")))
}
func TestWrapEscrowsAndIssues(cur realm, t *testing.T) {
dave := testutils.TestAddress("nf-dave")
testing.SetRealm(testing.NewUserRealm(dave))
grc20faucet.Claim(cross(cur))
grc20faucet.Approve(cross(cur), "RED", Home(), 1_000_000)
denom := Denom("nred")
redBefore := grc20faucet.BalanceOf("RED", dave)
escrowBefore, issuedBefore := Solvency("nred")
got := Wrap(cross(cur), "nred", 400_000)
uassert.Equal(t, int64(400_000), got)
uassert.Equal(t, redBefore-400_000, grc20faucet.BalanceOf("RED", dave), "the GRC20 left the holder")
uassert.Equal(t, escrowBefore+400_000, grc20faucet.BalanceOf("RED", Home()), "and landed in escrow")
uassert.Equal(t, int64(400_000), envelope.BalanceOf(dave, denom), "the native coin is at the bank, 1:1")
escrowAfter, issuedAfter := Solvency("nred")
uassert.Equal(t, escrowBefore+400_000, escrowAfter)
uassert.Equal(t, issuedBefore+400_000, issuedAfter)
uassert.True(t, IsSolvent("nred"), "every coin issued is backed")
uassert.AbortsContains(t, cur, "positive amount", func() { Wrap(cross(cur), "nred", 0) })
uassert.AbortsContains(t, cur, "does not issue", func() { Wrap(cross(cur), "ghost", 1) })
}
func TestUnwrapDestroysTheCoinAndReleasesTheBacking(cur realm, t *testing.T) {
erin := testutils.TestAddress("nf-erin")
denom := Denom("nred")
testing.SetRealm(testing.NewUserRealm(erin))
grc20faucet.Claim(cross(cur))
grc20faucet.Approve(cross(cur), "RED", Home(), 1_000_000)
Wrap(cross(cur), "nred", 300_000)
// On chain the -send envelope moves the coins to this realm's address before
// Unwrap runs. The harness has no bank-send primitive, so the credit is
// issued here; SetOriginSend is the half the realm actually reads.
sent := chain.NewCoins(chain.NewCoin(denom, 120_000))
testing.IssueCoins(Home(), sent)
testing.SetOriginSend(sent)
redBefore := grc20faucet.BalanceOf("RED", erin)
escrowBefore := grc20faucet.BalanceOf("RED", Home())
_, issuedBefore := Solvency("nred")
got := Unwrap(cross(cur), "nred")
uassert.Equal(t, int64(120_000), got)
uassert.Equal(t, redBefore+120_000, grc20faucet.BalanceOf("RED", erin), "the backing came back")
uassert.Equal(t, escrowBefore-120_000, grc20faucet.BalanceOf("RED", Home()), "escrow shrank by the same")
_, issuedAfter := Solvency("nred")
uassert.Equal(t, issuedBefore-120_000, issuedAfter,
"the coins were destroyed, not moved: total supply fell")
testing.SetOriginSend(nil)
uassert.AbortsContains(t, cur, "must be paid", func() { Unwrap(cross(cur), "nred") })
}
func TestRender(cur realm, t *testing.T) {
index := Render("")
uassert.True(t, strings.Contains(index, "# nativeify"), index)
uassert.True(t, strings.Contains(index, Home().String()), "the escrow address is on the page")
uassert.True(t, strings.Contains(index, "| [nred](/r/moul/x/nativeify/v0:nred) |"),
"the pair is listed:\n"+index)
one := Render("nred")
uassert.True(t, strings.Contains(one, "/gno.land/r/moul/x/nativeify/v0:nred"), one)
uassert.True(t, strings.Contains(one, "a display hint only"), one)
uassert.True(t, strings.Contains(Render("ghost"), "404"), "an unknown base renders a 404")
}
// attemptPull is the thing a GRC20 facade over a native coin would have to do,
// written out so it can be shown failing. It is in the test file, so it is not
// part of the deployed package.
func attemptPull(cur realm, from address, denom string, amount int64) {
banker.NewBanker(banker.BankerTypeRealmIssue, cur).
SendCoins(from, Home(), chain.NewCoins(chain.NewCoin(denom, amount)))
}
func TestARealmCannotPullANativeCoin(cur realm, t *testing.T) {
// The claim the package doc rests on, pinned rather than asserted: this
// realm holds the strongest banker the chain offers, the one that can mint
// and destroy this denom at will, and it still cannot MOVE a unit it does
// not already hold. There is no allowance to grant and no TransferFrom to
// call, which is why a grc20.Teller over a native coin cannot be written and
// why wugnot wraps in the direction it does.
frank := testutils.TestAddress("nf-frank")
denom := Denom("nred")
testing.IssueCoins(frank, chain.NewCoins(chain.NewCoin(denom, 1_000)))
msg := pullError(cur, frank, denom, 1_000)
uassert.True(t, strings.Contains(msg, "can only send coins from realm that created banker"),
"got: "+msg)
uassert.Equal(t, int64(1_000), envelope.BalanceOf(frank, denom), "and nothing moved")
}
// pullError runs attemptPull and returns the refusal as a string.
//
// uassert.PanicsContains cannot read this one. banker.SendCoins builds its
// message as `"..." + b.pkgAddr + "..."`, and in gno a string concatenated with
// an `address` has type `address`, so the panic value is an address rather than
// a string and the helper reports "recover: unsupported type". Measured
// 2026-09-28 against gno master; the message itself is correct, only its type is
// surprising.
func pullError(cur realm, from address, denom string, amount int64) (msg string) {
defer func() {
switch r := recover().(type) {
case nil:
msg = "it did not fail at all"
case address:
msg = string(r)
case string:
msg = r
case error:
msg = r.Error()
default:
msg = "panicked with an unexpected type"
}
}()
attemptPull(cur, from, denom, amount)
return ""
}
// ---------------------------------------------------------------------------
// p/moul/x/envelope's Forward is exercised here rather than in its own package:
// minting a BankerTypeOriginSend banker calls rlm.Previous(), and a p/ package's
// test has no realm frame to walk, so it dies with "frame not found: cannot seek
// beyond origin caller override". A p/ helper that needs a realm handle can only
// be tested from a realm.
func forwardDirect(cur realm, to address, coins chain.Coins) {
envelope.Forward(0, cur, to, coins)
}
func forwardOneDeeper(cur realm, to address, coins chain.Coins) {
forwardDirect(cur, to, coins)
}
func TestForwardIsBoundedByTheEnvelope(cur realm, t *testing.T) {
to := testutils.TestAddress("nf-forward-to")
denom := Denom("nred")
// The realm holds 5,000 of its own, and the envelope carried 250. A
// RealmSend banker could spend all 5,250; this one may spend 250.
testing.IssueCoins(Home(), chain.NewCoins(chain.NewCoin(denom, 5_000)))
sent := chain.NewCoins(chain.NewCoin(denom, 250))
testing.IssueCoins(Home(), sent)
testing.SetOriginSend(sent)
heldBefore := envelope.BalanceOf(Home(), denom)
forwardDirect(cur, to, sent)
uassert.Equal(t, int64(250), envelope.BalanceOf(to, denom))
uassert.Equal(t, heldBefore-250, envelope.BalanceOf(Home(), denom),
"exactly the envelope left, and none of the realm's own balance")
// Spending past the envelope is refused by the VM, not by any check here.
uassert.PanicsContains(t, cur, "limit", func() {
forwardDirect(cur, to, chain.NewCoins(chain.NewCoin(denom, 5_000)))
})
testing.SetOriginSend(nil)
}
func TestForwardFromOneFrameDeeper(cur realm, t *testing.T) {
// The frame-depth rule, measured rather than assumed: NewBanker refuses
// BankerTypeOriginSend unless rlm.Previous().IsUserCall(), and IsUserCall
// counts at most two call-boundary frames. Whatever this run reports is what
// the package doc says.
to := testutils.TestAddress("nf-deep-to")
denom := Denom("nred")
sent := chain.NewCoins(chain.NewCoin(denom, 90))
testing.IssueCoins(Home(), sent)
testing.SetOriginSend(sent)
forwardOneDeeper(cur, to, sent)
uassert.Equal(t, int64(90), envelope.BalanceOf(to, denom),
"one extra frame between the entry point and Forward")
testing.SetOriginSend(nil)
}
render.gno
package nativeify
import (
"strings"
"gno.land/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/kit/ui/v0"
"gno.land/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/md/v0"
"gno.land/p/nt/ufmt/v0"
)
// Render lists the pairs. `?<base>` shows one.
func Render(path string) string {
if path == "" {
return renderIndex()
}
return renderOne(path)
}
func renderIndex() string {
var sb strings.Builder
sb.WriteString(md.H1("nativeify: wugnot, backwards"))
sb.WriteString("\nwugnot takes a native coin and issues a GRC20, because a GRC20 can be " +
"pulled by a contract and a native coin cannot. This realm does the other one: escrow " +
"a GRC20, issue a native denom against it 1:1, and hand back something that moves with " +
"no realm call, rides the `-send` envelope of a transaction, and shows up beside GNOT " +
"on an account page.\n\n")
sb.WriteString(md.Blockquote("What you give up is everything downstream of `Approve`. A " +
"native coin has no allowance, so nothing can pull it: not an AMM, not an escrow, not " +
"a subscription. And its issuer can always delete a balance."))
sb.WriteString("\n")
sb.WriteString(ufmt.Sprintf("Escrow account to approve: `%s`\n\n", home.String()))
sb.WriteString(md.H2("Pairs") + "\n")
t := ui.NewTable("base", "underlying", "denom", "escrowed", "issued", "solvent")
for _, b := range bases {
p := mustPair(b)
escrowed, issued := Solvency(b)
solvent := "yes"
if escrowed < issued {
solvent = "**NO**"
}
t.Row(md.Link(b, "/r/moul/x/nativeify/v0:"+b),
ui.Cell(Underlying(b).GetSymbol()),
md.InlineCode(ui.ShortN(p.denom, 20, 10)),
ufmt.Sprintf("%d", escrowed), ufmt.Sprintf("%d", issued), solvent)
}
sb.WriteString(t.OrEmpty("Nothing wrapped yet.") + "\n")
sb.WriteString(md.H2("Try it") + "\n")
sb.WriteString("Claim play money, let this realm pull it, wrap, then send the result " +
"around like any other coin:\n\n")
sb.WriteString(md.LanguageCodeBlock("",
"# 1. get RED\n"+
"maketx call -pkgpath gno.land/r/moul/x/grc20faucet/v0 -func Claim\n\n"+
"# 2. let this realm pull your RED\n"+
"maketx call -pkgpath gno.land/r/moul/x/grc20faucet/v0 -func Approve \\\n"+
ufmt.Sprintf(" -args RED -args %s -args 1000000\n\n", home.String())+
"# 3. create the pair once, then wrap into it\n"+
"maketx call -pkgpath "+Path+" -func Nativeify \\\n"+
" -args gno.land/r/moul/x/grc20faucet/v0.RED -args nred\n"+
"maketx call -pkgpath "+Path+" -func Wrap -args nred -args 500000\n\n"+
"# 4. it is an ordinary coin now: no realm call, no approval\n"+
"maketx send -to <address> -send 1000/"+Path+":nred\n\n"+
"# 5. redeem, by sending the coins back\n"+
"maketx call -pkgpath "+Path+" -func Unwrap -args nred \\\n"+
" -send 1000/"+Path+":nred"))
sb.WriteString("\nEvery denom here is described in [nativereg](/r/moul/x/nativereg/v0), " +
"which is where a native coin says what it is, since the chain stores no name for it.\n")
return sb.String()
}
func renderOne(base string) string {
v := byBase.Get(base)
if v == nil {
return md.H1("404") + "\nThis realm does not issue " + md.InlineCode(base) + ".\n"
}
p := v.(*pair)
under := Underlying(base)
escrowed, issued := Solvency(base)
t := ui.NewTable("", "")
t.Row("denom", md.InlineCode(p.denom))
t.Row("underlying", ui.Cell(under.GetName())+" ("+ui.Cell(under.GetSymbol())+")")
t.Row("registry key", md.InlineCode(p.key))
t.Row("decimals", ufmt.Sprintf("%d, a display hint only", under.GetDecimals()))
t.Row("escrowed", ufmt.Sprintf("%d", escrowed))
t.Row("issued", ufmt.Sprintf("%d", issued))
t.Row("solvent", ufmt.Sprintf("%t", escrowed >= issued))
t.Row("created at block", ufmt.Sprintf("%d", p.height))
t.Row("created by", ui.Addr(p.creator))
s := md.H1(ui.Inline(base)) + "\n" + t.String() + "\n"
s += "Escrowed and issued are read from the GRC20 ledger and from the bank, not from " +
"this realm's own bookkeeping. If they disagree, the disagreement is the answer.\n\n"
s += md.LanguageCodeBlock("",
"maketx call -pkgpath "+Path+" -func Wrap -args "+base+" -args <amount>\n"+
"maketx call -pkgpath "+Path+" -func Unwrap -args "+base+" \\\n"+
" -send <amount>"+p.denom)
return s
}