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

pairreg/v0 package

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.

Function

Couples

func Couples() int

Couples returns how many distinct token couples are represented.

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/pairreg/v0.Couples()"

Result