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

v0 source realm

Package pairreg is the registry every AMM pair instance announces itself to, and the unified frontend over all of them.

Readme View source

gno.land/r/moul/x/pairreg/v0

The registry every AMM pair instance announces itself to, and the unified frontend over all of them. Third artifact of the instance-per-realm pattern; the logic is in p/moul/x/pair/v0.

  • Registration is one line in an instance's init, so a single addpkg both creates a pair and lists it.
  • The key is the caller's own package path, taken from cur.Previous().PkgPath(), so an instance cannot claim a path that is not its own.
  • Entries hold a live *pair.Pair, not an address, so Render shows every instance's real reserves from one vm/qrender. No indexer, no multicall.
  • Permissionless, and spam is self funded: the registering transaction pays for the storage it adds.

What it cannot tell you

Nothing on chain can read a package's source, so the registry cannot check that an instance runs the shared template. Reserves shown in the index are claimed. Several instances may exist for the same couple, on purpose: there is no canonical pair and no factory to enforce one. Verify an instance by diffing its source (vm/qfile) against freshly generated output before funding it.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

Dependency graph:

gno.land/r/moul/x/pairreg/v0 dependency graph

🧪 Highly experimental — potentially vibe-coded. Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: DISCLAIMER.

Overview

Package pairreg is the registry every AMM pair instance announces itself to, and the unified frontend over all of them.

It is the third artifact of the instance-per-realm pattern: one shared p/moul/x/pair/v0 holding the logic, N tiny realms holding one pair each, and this realm knowing all of them.

Why registration cannot be faked, and code cannot be trusted

Register keys an instance by cur.Previous().PkgPath(), which the runtime supplies, so an instance cannot claim a path that is not its own. That is the whole on-chain guarantee. It is NOT a guarantee about the code at that path: gno has no way to read another package's source from inside a realm, so nothing here can check that an instance really runs the shared template. The mirror image of Ethereum's CREATE2, which proves the code and says nothing legible about who deployed it.

Consequences a reader of the index must keep in mind:

  • Reserves shown here are CLAIMED. They are read live from the instance's own struct, which is honest for an instance running the template and arbitrary for one that does not.
  • Several instances may exist for the same token couple. That is allowed on purpose; there is no canonical pair and no factory to enforce one.
  • Approving tokens to an instance risks exactly what was approved. Read the instance's source (vm/qfile on its path) before funding it.

Why the registry can read live state at all

Instances register a *pair.Pair pointer, not an address, the way grc20reg registers a *grc20.Token. One vm/qrender here therefore renders the real state of every instance, with no indexer and no multicall. It is safe because pair.Pair holds only concrete types: an interface or a func field would let a hostile instance hand foreign code to this realm's frame.

Functions 6

func Couples

Action
1func Couples() int
source

Couples returns how many distinct token couples are represented.

func InstancesFor

Action
1func InstancesFor(id string) []string
source

InstancesFor returns the instance paths claiming a given couple id.

func Register

crossing Action
1func Register(cur realm, p *pair.Pair)
source

Register records the calling realm as an instance. Call it from the instance's init, so that deploying and listing are one transaction:

Example
1func init(cur realm) {
2	p = pair.New(keyA, keyB, grc20reg.MustGet(keyA), grc20reg.MustGet(keyB))
3	pairreg.Register(cross(cur), p)
4}

Permissionless by design: anyone may deploy an instance under their own address namespace and land here. Spam is self funded, since the registering transaction pays for the storage it adds.

func Render

1func Render(path string) string
source

Render is the unified frontend: the index of every instance with its live state, or one instance's own page when path is an instance path.

func Size

Action
1func Size() int
source

Size returns how many instances are registered.

func Get

Action
1func Get(path string) *Entry
source

Get returns the entry for an instance path, or nil.

Types 1

type Entry

struct
1type Entry struct {
2	Path   string     // the instance realm's package path, supplied by the runtime
3	Pair   *pair.Pair // live pointer into the instance's own storage
4	Height int64      // chain height at registration
5}
source

Entry is one registered instance.

Imports 6

Source Files 4