fix(grc20)!: decouple token id from symbol#5908
Conversation
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
|
@davd-gzl I just checked your review comments and applied all the suggestions. If you have a chance, please take another look. Thank you! |
|
Review note — no correctness/determinism blockers; the decoupling is complete (all in-repo Warnings worth addressing before merge:
🤖 Posted autonomously by an AI review agent on @moul's behalf; not human-reviewed before posting. |
|
Heads-up — this now has a semantic conflict with
So a naive merge lands in one of two broken states:
Additionally the auto-merge left Please decide how the decoupled 🤖 Posted autonomously by an AI agent on @moul's behalf; not human-reviewed before posting. |
|
I just started to resolving conflicts now |
# Conflicts: # examples/gno.land/p/demo/tokens/grc20/token.gno # examples/gno.land/p/demo/tokens/grc20/types.gno # examples/quarantined/gno.land/r/matijamarjanovic/tokenhub/tokenhub_test.gno
|
done 8e0aabc |
After gnolang#5907 merged, consumers (atomicswap, treasury) that look tokens up by rlmPath.symbol broke because gnolang#5908 had switched the registry key to Token.ID() (rlmPath.symbol.<seqid>). Keep the registry keyed by rlmPath.symbol (one token per realm+symbol, preserving gnolang#5907's overwrite/alias guards); Token.ID() keeps its trailing sequence id for event/identity uniqueness only. Register now returns the key; tokenhub and tests migrated off Token.ID()-based lookups.
|
Pushed a fix for the red CI (the atomicswap / treasury
Verified locally: This is the less-disruptive of the two options (keeps existing 🤖 Pushed & posted autonomously by an AI agent on @moul's behalf; not human-reviewed before posting. |
Description
Related to gnoswap-labs/gnoswap#1334
GRC20 event identifiers previously used
<origin realm>.<symbol>. Becausenameandsymbolare display metadata, multiple token instances created in the same realm could emit identicaltokenattributes.This PR separates token identity from display metadata.
Token.ID()now returns<origin realm path>.<realm-local ID>, and stateful token creators are responsible for allocating non-reusable IDs.Changes
GRC20 API and validation
idfield togrc20.Token.NewToken(name, symbol, decimals, id, cur), with the realm parameter last and no dummy argument.[A-Za-z0-9_-]with a 13-byte maximum, including the fullseqid.ID.String()encoding.nameandsymbolas display metadata.Realm-owned ID allocation
grc20factoryto maintain one persistentseqid.IDshared by every token creation."token"in examples that create only one token.Tests
TransferandApprovalevent IDs differ.Callers and documentation
seqid.IDallocation in the constructor example and factory code.cross(cur)examples.Design rationale
A helper such as
grc20.GenerateID()cannot guarantee uniqueness becausep/packages do not own persistent state. Instead, the realm path provides namespace isolation, while a stateful realm or factory owns a persistent sequence for IDs within that namespace.This keeps
grc20stateless and makes the ownership of the uniqueness guarantee explicit.Breaking changes
grc20.NewToken(0, cur, name, symbol, decimals)becomesgrc20.NewToken(name, symbol, decimals, id, cur).Token.ID()is no longer derived fromsymbol.Limitations
The
grc20package validates only the ID format. It cannot prevent a stateful caller from reusing an ID. Realms and factories that create multiple tokens must use one persistent sequence across all creation paths and must not reset or reuse it.