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

common source realm

Package common provides shared realm utilities for GnoSwap protocol contracts.

Overview

Package common provides shared realm utilities for GnoSwap protocol contracts.

The package contains helpers that must keep a realm boundary, including GRC20 token operations and native coin validation. AMM math lives in gno.land/p/gnoswap/gnsmath.

Key components: - GRC20 Registry Helpers: convenient wrappers for GRC20 token operations - Coin Utilities: native coin handling and validation - Assertion Utilities: input validation and authorization checks

Functions 14

func Allowance

Action
1func Allowance(tokenKey string, owner, spender address) int64
source

Allowance returns the token allowance from owner to spender.

Parameters:

  • tokenKey: GRC20 registry key
  • owner: address of the token owner
  • spender: address of the spender

Returns the allowance amount as int64.

func Approve

crossing Action
1func Approve(cur realm, tokenKey string, spender address, amount int64) error
source

Approve crosses into common before forwarding to grc20.Teller.Approve. CallerTeller uses cur.Previous() as the approver, so this helper must remain a crossing adapter called with cross(cur).

Parameters:

  • cur: current realm
  • tokenKey: GRC20 registry key
  • spender: address allowed to spend the tokens
  • amount: amount of tokens to approve

Returns an error if the approval fails, nil otherwise.

func AssertIsNotHandleNativeCoin

Action
1func AssertIsNotHandleNativeCoin()
source

AssertIsNotHandleNativeCoin validates that no native coins were sent with the transaction. Panics with errNotHandleNativeCoin if any native coins were sent.

Use this when a function should only work with GRC20 tokens and not accept native coins.

func BalanceOf

Action
1func BalanceOf(tokenKey string, addr address) int64
source

BalanceOf returns the token balance for the specified address.

Parameters:

  • tokenKey: GRC20 registry key
  • addr: address to query the balance for

Returns the token balance as int64.

func GetToken

Action
1func GetToken(tokenKey string) *grc20.Token
source

GetToken returns a grc20.Token instance for the specified tokenKey, panicking if not registered.

Parameters:

  • tokenKey: GRC20 registry key

Returns a pointer to the grc20.Token instance.

Panics if the token is not registered in grc20reg.

func GetTokenTeller

Action
1func GetTokenTeller(tokenKey string) grc20.Teller
source

GetTokenTeller returns a CallerTeller for the specified tokenKey, panicking if not registered.

Parameters:

  • tokenKey: GRC20 registry key

Returns a grc20.Teller whose write methods derive the actor from the caller realm.

Panics if the token is not registered in grc20reg.

func IsRegistered

Action
1func IsRegistered(tokenKey string) error
source

IsRegistered checks if a token is registered in grc20reg, returning nil if registered or error if not.

Parameters:

  • tokenKey: GRC20 registry key

Returns nil if the token is registered, or an error describing the issue.

func MustRegistered

Action
1func MustRegistered(tokenKeys ...string)
source

MustRegistered checks if all provided tokens are registered, panicking if any is not registered.

Parameters:

  • tokenKeys: variable number of GRC20 registry keys to check

Panics if any of the provided tokens is not registered in grc20reg.

func SafeGRC20Approve

crossing Action
1func SafeGRC20Approve(cur realm, tokenKey string, spender address, amount int64)
source

SafeGRC20Approve crosses into common, approves tokens, and panics if it fails. CallerTeller uses cur.Previous() as the approver, so this helper must remain a crossing adapter called with cross(cur).

Parameters:

  • cur: current realm
  • tokenKey: GRC20 registry key
  • spender: address allowed to spend the tokens
  • amount: amount of tokens to approve

Panics if the approval fails.

func SafeGRC20Transfer

crossing Action
1func SafeGRC20Transfer(cur realm, tokenKey string, to address, amount int64)
source

SafeGRC20Transfer crosses into common, transfers tokens, and panics if it fails. CallerTeller uses cur.Previous() as the token actor, so this helper must remain a crossing adapter called with cross(cur).

Parameters:

  • cur: current realm
  • tokenKey: GRC20 registry key
  • to: recipient address
  • amount: amount of tokens to transfer

Panics if the transfer fails.

func SafeGRC20TransferFrom

crossing Action
1func SafeGRC20TransferFrom(cur realm, tokenKey string, from, to address, amount int64)
source

SafeGRC20TransferFrom crosses into common, transfers tokens, and panics if it fails. CallerTeller uses cur.Previous() as the spender, so this helper must remain a crossing adapter called with cross(cur).

Parameters:

  • cur: current realm
  • tokenKey: GRC20 registry key
  • from: sender address
  • to: recipient address
  • amount: amount of tokens to transfer

Panics if the transfer fails.

func TotalSupply

Action
1func TotalSupply(tokenKey string) int64
source

TotalSupply returns the total supply of the specified token.

Parameters:

  • tokenKey: GRC20 registry key

Returns the total supply of the token as int64.

func Transfer

crossing Action
1func Transfer(cur realm, tokenKey string, to address, amount int64) error
source

Transfer crosses into common before forwarding to grc20.Teller.Transfer. CallerTeller uses cur.Previous() as the token actor, so this helper must remain a crossing adapter called with cross(cur).

Parameters:

  • cur: current realm
  • tokenKey: GRC20 registry key
  • to: recipient address
  • amount: amount of tokens to transfer

Returns an error if the transfer fails, nil otherwise.

func TransferFrom

crossing Action
1func TransferFrom(cur realm, tokenKey string, from, to address, amount int64) error
source

TransferFrom crosses into common before forwarding to grc20.Teller.TransferFrom. CallerTeller uses cur.Previous() as the spender, so this helper must remain a crossing adapter called with cross(cur).

Parameters:

  • cur: current realm
  • tokenKey: GRC20 registry key
  • from: sender address
  • to: recipient address
  • amount: amount of tokens to transfer

Returns an error if the transfer fails, nil otherwise.

Imports 5

Source Files 5