Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

render.gno

6.80 Kb · 190 lines
  1package padv10
  2
  3import (
  4	"strconv"
  5	"strings"
  6
  7	ammmath "gno.land/p/g1mv0052e7r6s09f5t9xsqf00nj3tqsgt9dg52jr/gnomemepad/ammmathv2"
  8	"gno.land/p/nt/ufmt/v0"
  9)
 10
 11// Render provides on-chain discovery (gnoweb). Read-only by convention.
 12//
 13// Paths:
 14//
 15//	""              — home / list
 16//	token/{id}      — launch detail
 17//	help            — API help
 18func Render(path string) string {
 19	path = strings.Trim(path, "/")
 20	if path == "" {
 21		return renderHome()
 22	}
 23	if path == "help" {
 24		return renderHelp()
 25	}
 26	if strings.HasPrefix(path, "token/") {
 27		id := strings.TrimPrefix(path, "token/")
 28		return renderToken(id)
 29	}
 30	return "> [!WARNING]\n> Path not found: " + sanitize(path) + "\n"
 31}
 32
 33func sanitize(s string) string {
 34	s = strings.ReplaceAll(s, "`", "'")
 35	s = strings.ReplaceAll(s, "<", "")
 36	s = strings.ReplaceAll(s, ">", "")
 37	return s
 38}
 39
 40func renderHome() string {
 41	out := "# gnomemepad\n\n"
 42	out += "Meme launchpad — bonding curve → remaining tokens + raised liquid (Gnoswap auto-list when funded).\n\n"
 43	if !inited {
 44		out += "> [!CAUTION]\n> Protocol not initialized. Call Init first.\n\n"
 45		return out
 46	}
 47	out += ufmt.Sprintf("- Launches: **%d**\n", launches.Size())
 48	if protocolAddr.IsValid() {
 49		out += ufmt.Sprintf("- Protocol treasury: `%s`\n", protocolAddr.String())
 50	}
 51	out += ufmt.Sprintf("- Protocol fees pending (claim/push): **%d** ugnot\n", protocolFees)
 52	out += ufmt.Sprintf("- Protocol fees paid (lifetime): **%d** ugnot\n\n", protocolFeesPaid)
 53	out += "## Markets\n\n"
 54	if launches.Size() == 0 {
 55		out += "_No launches yet. Call Create with name, symbol, uri and bond._\n"
 56		return out
 57	}
 58	launches.Iterate("", "", func(key string, value any) bool {
 59		l := value.(*Launch)
 60		st := "curve"
 61		if l.Status == StatusGraduated {
 62			st = "graduated"
 63		}
 64		out += ufmt.Sprintf("- [%s ($%s)](token/%s) — %s — raised %d ugnot — buyers %d\n",
 65			sanitize(l.Name), sanitize(l.Symbol), l.ID, st, l.RaisedUgnot, l.BuyerCount)
 66		return false
 67	})
 68	out += "\n[Help](help)\n"
 69	return out
 70}
 71
 72func renderToken(id string) string {
 73	id = sanitize(id)
 74	l, ok := launches.Get(id).(*Launch)
 75	if !ok {
 76		return "> [!WARNING]\n> Unknown launch " + id + "\n\n[Home](./)\n"
 77	}
 78	st := "bonding curve"
 79	if l.Status == StatusGraduated {
 80		st = "graduated pool (LP locked)"
 81	}
 82	out := ufmt.Sprintf("# %s ($%s)\n\n", sanitize(l.Name), sanitize(l.Symbol))
 83	out += ufmt.Sprintf("- **ID:** %s\n", l.ID)
 84	out += ufmt.Sprintf("- **Status:** %s\n", st)
 85	out += ufmt.Sprintf("- **Creator:** %s\n", l.Creator.String())
 86	if l.URI != "" {
 87		out += ufmt.Sprintf("- **URI:** %s\n", sanitize(l.URI))
 88	}
 89	out += ufmt.Sprintf("- **Unique buyers:** %d\n", l.BuyerCount)
 90	out += ufmt.Sprintf("- **Creator fees (claimable):** %d ugnot\n\n", l.CreatorFees)
 91
 92	if l.Status == StatusCurve {
 93		remaining := CurveSupply - l.RealSold
 94		pct := int64(0)
 95		if GraduationThreshold > 0 {
 96			pct = l.RaisedUgnot * 100 / GraduationThreshold
 97			if pct > 100 {
 98				pct = 100
 99			}
100		}
101		spot := ammmath.SpotPriceUgnotPerToken(l.VirtualUgnot, l.VirtualToken)
102		out += "## Bonding curve\n\n"
103		out += ufmt.Sprintf("- Raised: **%d** / %d ugnot (%d%%)\n", l.RaisedUgnot, GraduationThreshold, pct)
104		out += ufmt.Sprintf("- Tokens sold: **%d** / %d\n", l.RealSold, CurveSupply)
105		out += ufmt.Sprintf("- Remaining on curve: **%d**\n", remaining)
106		out += ufmt.Sprintf("- Spot (ugnot/token x1e6): **%d**\n", spot)
107		out += "\nProgress toward graduation:\n\n"
108		out += progressBar(pct) + "\n"
109	} else {
110		spot := ammmath.SpotPriceUgnotPerToken(l.PoolUgnot, l.PoolToken)
111		out += "## Liquidity (post-graduate)\n\n"
112		out += ufmt.Sprintf("- Raised capital (record): **%d** ugnot\n", l.PoolUgnot)
113		out += ufmt.Sprintf("- Remaining tokens seeded: **%d**\n", l.PoolToken)
114		out += ufmt.Sprintf("- Spot (ugnot/token x1e6): **%d**\n", spot)
115		if l.GnoswapListed {
116			out += ufmt.Sprintf("- **Gnoswap listed:** `%s`\n", sanitize(l.GnoswapPoolPath))
117			out += ufmt.Sprintf("- Position NFT id: **%d** (pad-owned, locked)\n", l.GnoswapPositionID)
118			out += ufmt.Sprintf("- Fee WUGNOT spent: **%d** · LP WUGNOT: **%d**\n", l.FeeWugnotSpent, l.LiqWugnotUsed)
119			out += "\n> [!NOTE]\n> Trade on Gnoswap router — pad SwapBuy/SwapSell disabled after auto-list.\n"
120		} else {
121			out += ufmt.Sprintf("- Gnoswap: %s\n", sanitize(l.GnoswapNote))
122			out += "\n> [!NOTE]\n> Internal CPMM locked (fallback). Fund pad WUGNOT inventory before graduate for auto-list.\n"
123		}
124	}
125
126	out += "\n## Trade\n\n"
127	out += "Use wallet MsgCall (payable txs):\n\n"
128	if l.Status == StatusCurve {
129		out += ufmt.Sprintf("- Buy(id) with -send ugnot — id=%s\n", l.ID)
130		out += "- Sell(id, tokensIn)\n"
131		out += "- Graduate(id) when threshold met\n"
132	} else {
133		out += "- SwapBuy(id) with -send ugnot\n"
134		out += "- SwapSell(id, tokensIn)\n"
135	}
136	out += "\n[Home](./) · [Help](help)\n"
137	return out
138}
139
140func progressBar(pct int64) string {
141	if pct < 0 {
142		pct = 0
143	}
144	if pct > 100 {
145		pct = 100
146	}
147	filled := int(pct / 5)
148	bar := "["
149	for i := 0; i < 20; i++ {
150		if i < filled {
151			bar += "#"
152		} else {
153			bar += "."
154		}
155	}
156	bar += "] " + strconv.FormatInt(pct, 10) + "%"
157	return bar
158}
159
160func renderHelp() string {
161	out := "# gnomemepad API\n\n"
162	out += "## Lifecycle\n\n"
163	out += "1. Init() — once; caller becomes protocol treasury\n"
164	out += "2. Create(name, symbol, uri) + bond from bond realm (promo/normal)\n"
165	out += "3. Buy(id, minTokensOut) / Sell(id, amount, minUgnotOut) — bonding curve\n"
166	out += "4. Auto or Graduate(id) at threshold\n"
167	out += "5. Graduate seeds remaining tokens + raised as liquidity\n"
168	out += "   → auto Gnoswap CreatePool+Mint if pad has WUGNOT inventory\n"
169	out += "   → else locked internal CPMM (SwapBuy/SwapSell)\n"
170	out += "6. Transfer / Approve / TransferFrom — GRC20\n"
171	out += "7. Fees:\n"
172	out += "   - Creator: ClaimCreatorFees(id) — only creator, **must claim**\n"
173	out += "   - Protocol: ClaimProtocolFees() (treasury) or PushProtocolFees() (anyone → treasury)\n"
174	out += "   - TransferProtocol(newAddr) / WithdrawProtocolUgnot(amount) — treasury ops\n"
175	out += "   - Gnoswap CreatePool GNS fee goes to Gnoswap, not pad treasury\n\n"
176	out += "## Params (MVP)\n\n"
177	out += ufmt.Sprintf("- Total supply: %d\n", TotalSupply)
178	out += ufmt.Sprintf("- Curve sale: %d\n", CurveSupply)
179	out += ufmt.Sprintf("- LP tokens at grad: TotalSupply - RealSold (was PoolSeed=%d)\n", PoolSeed)
180	out += ufmt.Sprintf("- Graduation: %d ugnot\n", GraduationThreshold)
181	out += ufmt.Sprintf("- Fee: %d BPS\n", FeeBPS)
182	out += ufmt.Sprintf("- Create bond (live): %d ugnot\n\n", requiredCreateBond())
183	out += "## Design\n\n"
184	out += "- Remaining tokens + raised GNOT → liquidity at graduate\n"
185	out += "- Part of WUGNOT inventory swaps to GNS for CreatePool fee\n"
186	out += "- Permanent LP lock (pad holds Gnoswap position NFT)\n"
187	out += "- EOA + OriginSend payment guards\n\n"
188	out += "[Home](./)\n"
189	return out
190}