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

gnft source realm

Package gnft implements the position-NFT surface used by GnoSwap.

Readme View source

GNFT

GRC721-compatible NFT contract for GnoSwap LP positions.

Overview

GNFT represents each liquidity position as a unique NFT. It exposes ownership, transfer, approval, and metadata operations while generating compact SVG artwork for tokens whose URI is stored in GNFT's parameter format.

GNFT implements the position-NFT surface used by GnoSwap; it does not expose every optional GRC721 extension. In particular, this package has no token enumeration API and does not expose safeTransferFrom.

Core Features

Ownership and approvals

  • Transfer, single-token approval, and operator approval
  • Owner, balance, existence, and approval queries
  • Staked tokens are locked to the staker contract
  • Other transfers use the GRC721 owner and approval checks

Dynamic SVG generation

  • Generated tokens store compact gradient parameters
  • Parameters are rendered to SVG and returned as a base64-encoded data URI
  • Rendering occurs on TokenURI reads rather than storing the full SVG
  • A custom non-empty URI set with SetTokenURI is returned unchanged when it is not in GNFT parameter format

Storage

  • Compact parameter storage reduces per-token metadata size
  • Template-based SVG generation avoids storing repeated markup

Key Functions

Mint

Mints a new NFT for an LP position. Only the position role may call it.

Parameters:

  • cur realm: Current realm context
  • to address: Recipient address
  • tid grc721.TokenID: Token ID to mint

Returns: grc721.TokenID

Burn

Burns an NFT when its position is closed. Only the position role may call it.

Parameters:

  • cur realm: Current realm context
  • tid grc721.TokenID: Token ID to burn

TransferFrom

Transfers NFT ownership.

Parameters:

  • cur realm: Current realm context
  • from address: Current owner
  • to address: New owner
  • tid grc721.TokenID: Token ID to transfer

For a token held by the staker contract, only the staker can move it. For other tokens, the owner, token approval, or operator approval must authorize the transfer.

TokenURI

Returns metadata for a token. When the stored URI parses as GNFT image parameters (x1,y1,x2,y2,color1,color2), GNFT renders those parameters as an SVG and returns a base64-encoded data URI. A custom non-empty URI that is not in that parameter format is returned unchanged.

Parameters:

  • tid grc721.TokenID: Token ID

Returns: Token URI string and an error when the token or metadata is missing

SetTokenURI

Sets a non-empty token URI. Only the position role may call it.

Parameters:

  • cur realm: Current realm context
  • tid grc721.TokenID: Token ID
  • tURI string: Non-empty metadata URI

Approve

Approves an address to manage a specific token.

Parameters:

  • cur realm: Current realm context
  • approved address: Address to approve
  • tid grc721.TokenID: Token ID

SetApprovalForAll

Approves or revokes an operator for all tokens owned by the caller.

Parameters:

  • cur realm: Current realm context
  • operator address: Operator address
  • approved bool: Approval status

Queries

  • Name() string: Collection name
  • Symbol() string: Collection symbol
  • TotalSupply() int64: Number of minted NFTs
  • BalanceOf(owner address) (int64, error): Number of NFTs owned
  • OwnerOf(tid grc721.TokenID) (address, error): Current owner
  • MustOwnerOf(tid grc721.TokenID) address: Owner or panic on error
  • Exists(tid grc721.TokenID) bool: Whether a token exists
  • GetApproved(tid grc721.TokenID) (address, error): Token approval
  • IsApprovedForAll(owner, operator address) bool: Operator approval

SVG Generation

Parameter Format

Generated token URIs store compact parameters:

"x1,y1,x2,y2,#COLOR1,#COLOR2"
Example: "10,12,125,123,#FF5733,#33B5FF"

Parameter Ranges

  • x1: 7-13
  • y1: 7-13
  • x2: 121-126
  • y2: 121-126
  • colors: 6-digit hex (#RRGGBB)

Rendering Process

  1. Mint: Generate pseudo-random parameters and store them as a CSV string
  2. TokenURI: Parse the CSV, generate SVG, encode it as base64, and return a data URI
  3. Display: The browser decodes the data URI and renders the SVG

The parameters use time-seeded math/rand; this is pseudo-random artwork generation, not a security or cryptographic randomness source.

Usage

These helpers illustrate calls from an integrating realm. mintExample and burnExample require that realm to hold the position role; transferExample requires the caller to satisfy the ownership/approval rules described above.

 1import (
 2    "gno.land/p/nt/grc721/v0"
 3    "gno.land/r/gnoswap/gnft"
 4)
 5
 6func mintExample(cur realm, owner address, tokenID grc721.TokenID) grc721.TokenID {
 7    return gnft.Mint(cross(cur), owner, tokenID)
 8}
 9
10func metadataExample(tokenID grc721.TokenID) (string, error) {
11    return gnft.TokenURI(tokenID)
12}
13
14func transferExample(cur realm, from, to address, tokenID grc721.TokenID) error {
15    return gnft.TransferFrom(cross(cur), from, to, tokenID)
16}
17
18func burnExample(cur realm, tokenID grc721.TokenID) {
19    gnft.Burn(cross(cur), tokenID)
20}

Security and Access Control

  • Mint, SetTokenURI, and Burn require the position role
  • Staker-held tokens can only be moved by the staker contract
  • Other transfers are checked by the owner/approval rules in the GRC721 ledger
  • Token URI parameters are validated before generated artwork is rendered
  • Generated artwork uses pseudo-random, time-seeded parameters and must not be treated as a source of secure randomness

Architecture

Dependencies

  • gno.land/p/nt/grc721/v0: GRC721 token and ledger implementation
  • gno.land/p/nt/grc721/metadata/v0: Metadata storage
  • gno.land/r/gnoswap/rbac/v1: Access control
  • gno.land/r/gnoswap/access/v1: Position-role authorization and role mirror

State Variables

  • token: GRC721 token metadata and supply state
  • ledger: Ownership, transfer, and approval ledger
  • meta: Token URI metadata
  • metaLedger: Metadata update ledger

Generated image tokens store compact parameters in metadata; the full SVG data URI is generated when TokenURI is called.

Overview

Package gnft implements the position-NFT surface used by GnoSwap.

It provides GRC721-compatible ownership, transfer, approval, and metadata operations for LP positions. Generated parameter-format URIs become SVG data URIs on read; custom non-empty URIs are returned unchanged. Enumeration and safeTransferFrom are not exposed by this package.

Functions 14

func Approve

crossing Action
1func Approve(cur realm, approved address, tid grc721.TokenID) error
source

Approve grants permission to transfer a specific token ID to another address.

Parameters:

  • cur: Current realm context; callers use cross(cur) when crossing into this realm.
  • approved: address to approve
  • tid: token ID to approve for transfer

Returns:

  • error: nil after approval is stored; invalid addresses, ownership, or ledger failures panic through checkApproveErr

func BalanceOf

Action
1func BalanceOf(owner address) (int64, error)
source

BalanceOf returns the number of NFTs owned by the specified address.

Parameters:

  • owner: address whose NFT balance is queried

Returns:

  • balance: number of NFTs owned by owner
  • error: token-ledger balance lookup error; an invalid owner address panics before the lookup

func Burn

crossing Action
1func Burn(cur realm, tid grc721.TokenID)
source

Burn removes a specific token ID.

Parameters:

  • cur: Current realm context; callers use cross(cur) when crossing into this realm.
  • tid: token ID to burn

Only callable by position.

func Exists

Action
1func Exists(tid grc721.TokenID) bool
source

Exists checks if token ID exists.

Parameters:

  • tid: token ID to check

Returns:

  • exists: true when the ledger can resolve an owner for tid; false otherwise

func IsApprovedForAll

Action
1func IsApprovedForAll(owner, operator address) bool
source

IsApprovedForAll checks if operator can manage all owner's tokens.

Parameters:

  • owner: token owner address
  • operator: operator address to check

Returns:

  • approved: true when operator is approved for every token owned by owner

func Mint

crossing Action
1func Mint(cur realm, to address, tid grc721.TokenID) grc721.TokenID
source

Mint creates new NFT and transfers it to to.

Parameters:

  • cur: Current realm context; callers use cross(cur) when crossing into this realm.
  • to: recipient address
  • tid: token ID to mint

Returns:

  • tokenID: minted token ID

Only callable by position contract.

func Name

Action
1func Name() string
source

Name returns the NFT collection name.

Returns:

  • name: collection name

func Render

1func Render(path string) string
source

Render returns the HTML representation of the NFT.

Parameters:

  • path: render path; the empty path selects the collection home page

Returns:

  • html: collection HTML for the home path, or "404\n" for unsupported paths

func SetApprovalForAll

crossing Action
1func SetApprovalForAll(cur realm, operator address, approved bool) error
source

SetApprovalForAll enables/disables operator approval for all tokens.

Parameters:

  • cur: Current realm context; callers use cross(cur) when crossing into this realm.
  • operator: address to set approval for
  • approved: true to approve, false to revoke

Returns:

  • error: nil after the operator approval is stored; ledger failures panic before a non-nil error can be returned

func SetTokenURI

crossing Action
1func SetTokenURI(cur realm, tid grc721.TokenID, tURI string) (bool, error)
source

SetTokenURI sets the metadata URI for the specified token.

Parameters:

  • cur: Current realm context; callers use cross(cur) when crossing into this realm.
  • tid: token ID whose metadata URI is replaced
  • tURI: non-empty metadata URI or parameter-format image description

Returns:

  • updated: true after the URI is stored and re-read successfully
  • error: nil on success; validation and storage failures panic before a non-nil error can be returned

Only callable by position contract.

func Symbol

Action
1func Symbol() string
source

Symbol returns the NFT collection symbol.

Returns:

  • symbol: collection symbol

func TokenURI

Action
1func TokenURI(tid grc721.TokenID) (string, error)
source

TokenURI returns the metadata URI for the specified token ID. Parameter-format values (x1,y1,x2,y2,color1,color2) are rendered as a base64-encoded SVG data URI; other non-empty stored URIs are returned unchanged.

Parameters:

  • tid: token ID whose metadata URI is requested

Returns:

  • uri: stored URI, or a generated SVG data URI for parameter-format metadata
  • error: metadata lookup error when tid has no retrievable metadata

func TotalSupply

Action
1func TotalSupply() int64
source

TotalSupply returns the total number of NFTs minted.

Returns:

  • supply: number of NFTs minted by the collection

func TransferFrom

crossing Action
1func TransferFrom(cur realm, from, to address, tid grc721.TokenID) error
source

TransferFrom transfers a token from one address to another.

Parameters:

  • cur: Current realm context; callers use cross(cur) when crossing into this realm.
  • from: current owner address
  • to: recipient address
  • tid: token ID to transfer

Returns:

  • error: nil after a successful transfer; invalid addresses, authorization, ownership, or ledger failures panic through checkTransferErr

Permission model:

  • Tokens held by the staker contract (i.e. currently staked) can only be moved by the staker itself; the underlying staked LP position is non-transferable.
  • Otherwise, ownership and approval are enforced by the GRC721 layer (owner / approved-for-token / approved-for-all).

Types 1

type ImageParams

struct
1type ImageParams struct {
2	x1, y1, x2, y2 int
3	color1, color2 string
4}
source

ImageParams holds parsed and validated image parameters.

Imports 14

Source Files 8