Playground
doc.gno
// Package xgns implements the GRC20-compliant xGNS token that represents // staked GNS. It manages balances, total supply, and the gov/staker-authorized // mint and burn operations used by delegation and launchpad accounting. // // xGNS does not maintain a separate voting-power ledger. Governance and // gov/staker read xGNS balances and supply, then apply delegation history and // proposal rules outside this package. package xgns
gnomod.toml
module = "gno.land/r/gnoswap/gov/xgns" gno = "0.9" [addpkg] creator = "g1q5tjjv3kkslzwf2na9y9wk7e5a8ugph8xfsk04" height = 557753 max_deposit = "100000000ugnot"
xgns.gno
package xgns
import (
"chain"
"errors"
"strings"
"gno.land/p/nt/grc20/v0"
"gno.land/p/nt/ownable/v0"
"gno.land/p/nt/ufmt/v0"
"gno.land/r/gnoswap/access/v1"
"gno.land/r/gnoswap/halt/v1"
prbac "gno.land/p/gnoswap/rbac/v1"
)
const tokenID = 0
var (
admin = ownable.NewWithAddress(chain.PackageAddress(prbac.ROLE_GOV_STAKER.String()))
token *grc20.Token
ledger *grc20.PrivateLedger
)
func init(cur realm) {
token, ledger = grc20.NewToken("XGNS", "xGNS", 6, tokenID, cur)
}
// TotalSupply returns the total supply of xGNS tokens.
//
// Returns:
// - supply: total xGNS token supply
func TotalSupply() int64 {
return token.TotalSupply()
}
// BalanceOf returns token balance for address.
//
// Parameters:
// - owner: address to check balance for
//
// Returns:
// - balance: token balance amount
func BalanceOf(owner address) int64 {
return token.BalanceOf(owner)
}
// Render returns a formatted representation of the token state.
//
// Parameters:
// - path: render path for specific views
//
// Returns:
// - output: formatted token state representation
func Render(path string) string {
if path == "" {
return token.RenderHome()
}
parts := strings.Split(path, "/")
switch parts[0] {
case "balance":
if len(parts) != 2 {
return "404\n"
}
balance := token.BalanceOf(address(parts[1]))
return ufmt.Sprintf("%d\n", balance)
default:
return "404\n"
}
}
// Mint mints tokens to an address.
//
// Parameters:
// - cur: current realm context; callers use cross(cur) when crossing into this
// realm.
// - to: recipient address receiving the newly minted tokens.
// - amount: number of xGNS token units to mint.
//
// Only callable by governance staker contract.
func Mint(cur realm, to address, amount int64) {
halt.AssertIsNotHaltedXGns()
caller := cur.Previous().Address()
access.AssertIsGovStaker(caller)
checkErr(ledger.Mint(to, amount))
}
// Burn burns tokens from an address.
//
// Parameters:
// - cur: current realm context; callers use cross(cur) when crossing into this
// realm.
// - from: address whose xGNS balance is burned.
// - amount: number of xGNS token units to burn.
//
// Only callable by governance staker contract.
func Burn(cur realm, from address, amount int64) {
halt.AssertIsNotHaltedWithdraw()
caller := cur.Previous().Address()
access.AssertIsGovStaker(caller)
checkErr(ledger.Burn(from, amount))
}
// SupplyInfo returns supply breakdown information.
//
// Returns:
// - totalIssued: total xGNS tokens issued
// - issuedByDelegate: tokens issued through governance delegation
// - issuedByDepositGns: tokens issued through launchpad deposit
// - err: nil when the launchpad address is registered; an error when it cannot
// be found.
func SupplyInfo() (totalIssued, issuedByDelegate, issuedByDepositGns int64, err error) {
launchpad, ok := access.GetAddress(prbac.ROLE_LAUNCHPAD.String())
if !ok {
return 0, 0, 0, errors.New("launchpad address not found")
}
totalIssued = token.TotalSupply()
issuedByDepositGns = token.BalanceOf(launchpad)
issuedByDelegate = totalIssued - issuedByDepositGns
return totalIssued, issuedByDelegate, issuedByDepositGns, nil
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}