Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Playground

community_pool.gno

package community_pool

import (
	"chain"
	"strconv"

	prbac "gno.land/p/gnoswap/rbac/v1"

	"gno.land/r/gnoswap/access/v1"
	"gno.land/r/gnoswap/common"
	"gno.land/r/gnoswap/halt/v1"
)

// GetBalanceOf returns the community pool's balance for a registered token.
//
// Parameters:
//   - tokenPath: registry key/path of the token contract whose balance is queried
//
// Returns:
//   - balance: token units held by the configured community-pool address, or 0 when validation fails
//   - err: nil when tokenPath is valid and registered; non-nil for an invalid or unregistered tokenPath
func GetBalanceOf(tokenPath string) (int64, error) {
	communityPoolAddr := access.MustGetAddress(prbac.ROLE_COMMUNITY_POOL.String())

	if err := common.IsRegistered(tokenPath); err != nil {
		return 0, err
	}

	return common.BalanceOf(tokenPath, communityPoolAddr), nil
}

// TransferToken transfers token units from the community pool to an address.
//
// Parameters:
//   - cur: current realm context; callers use cross(cur) when crossing into this realm
//   - tokenPath: registry key/path of the registered token to transfer
//   - to: recipient address for the token units
//   - amount: number of token units to transfer; transfer failure panics through the safe wrapper
//
// Only callable by admin or governance while withdrawals are not halted.
// Governance is the recommended normal route. While governance is not yet
// mature, admin access is retained for emergency-only use as an operational
// policy, not a contract-enforced condition. Admin calls do not require an
// approved proposal; emergency status is not checked and admin access does
// not expire automatically.
func TransferToken(cur realm, tokenPath string, to address, amount int64) {
	halt.AssertIsNotHaltedWithdraw()

	prevRealm := cur.Previous()
	caller := prevRealm.Address()
	access.AssertIsAdminOrGovernance(caller)

	common.SafeGRC20Transfer(0, cur, tokenPath, to, amount)

	chain.Emit(
		"TransferToken",
		"prevAddr", caller.String(),
		"prevRealm", prevRealm.PkgPath(),
		"tokenPath", tokenPath,
		"to", to.String(),
		"amount", strconv.FormatInt(amount, 10),
	)
}

doc.gno

// Package community_pool manages the GnoSwap community treasury.
//
// This contract holds registered protocol-owned assets. The emission system
// routes its configured community-pool share here, and external governance may
// use proposal execution to authorize a spend. Proposal and voting state are
// outside this package: TransferToken is a direct admin-or-governance entry
// point subject to the withdrawal halt and token-transfer validation.
//
// Governance is the recommended normal route. While governance is not yet
// mature, admin access is retained for emergency-only use as an operational
// policy. The contract does not verify an emergency or require proposal
// approval for admin calls, and admin access does not expire automatically.
package community_pool

gnomod.toml

module = "gno.land/r/gnoswap/community_pool/v1"
gno = "0.9"

[addpkg]
  creator = "g1q5tjjv3kkslzwf2na9y9wk7e5a8ugph8xfsk04"
  height = 77259
  max_deposit = "100000000ugnot"

render.gno

package community_pool

import (
	prbac "gno.land/p/gnoswap/rbac/v1"
	"gno.land/p/moul/md/v0"
	"gno.land/p/moul/mdtable/v0"
	ufmt "gno.land/p/nt/ufmt/v0"

	"gno.land/r/gnoswap/access/v1"
	"gno.land/r/gnoswap/halt/v1"
)

// Render shows the authorities and withdrawal gate used by treasury transfers.
func Render(path string) string {
	if path != "" {
		return "404\n"
	}

	out := md.H1("Gnoswap Community Pool") +
		"\n" +
		md.Paragraph(
			"The community treasury holds tokens for ecosystem funding.\n"+
				"Balances are queried per token; this page does not report a total treasury value.",
		) +
		md.H2("Transfers") +
		"\n" +
		md.Paragraph("Transfers require the admin or governance role and are blocked when withdrawals are halted.")

	statusTable := mdtable.Table{
		Headers: []string{"Restriction", "Enabled"},
		Rows: [][]string{
			{"Withdrawals halted", ufmt.Sprintf("%t", halt.IsHaltedWithdraw())},
		},
	}
	out += statusTable.String() + "\n"

	out += md.H2("Transfer authorities") + "\n"
	authorityTable := mdtable.Table{
		Headers: []string{"Role", "Address"},
	}
	for _, role := range []prbac.SystemRole{prbac.ROLE_ADMIN, prbac.ROLE_GOVERNANCE} {
		value := "Unassigned"
		if addr, ok := access.GetAddress(role.String()); ok {
			value = md.InlineCode(addr.String())
		}
		authorityTable.Append([]string{role.String(), value})
	}
	return out + authorityTable.String()
}