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

community_pool.gno

2.09 Kb · 63 lines
 1package community_pool
 2
 3import (
 4	"chain"
 5	"strconv"
 6
 7	prbac "gno.land/p/gnoswap/rbac/v1"
 8
 9	"gno.land/r/gnoswap/access/v1"
10	"gno.land/r/gnoswap/common"
11	"gno.land/r/gnoswap/halt/v1"
12)
13
14// GetBalanceOf returns the community pool's balance for a registered token.
15//
16// Parameters:
17//   - tokenPath: registry key/path of the token contract whose balance is queried
18//
19// Returns:
20//   - balance: token units held by the configured community-pool address, or 0 when validation fails
21//   - err: nil when tokenPath is valid and registered; non-nil for an invalid or unregistered tokenPath
22func GetBalanceOf(tokenPath string) (int64, error) {
23	communityPoolAddr := access.MustGetAddress(prbac.ROLE_COMMUNITY_POOL.String())
24
25	if err := common.IsRegistered(tokenPath); err != nil {
26		return 0, err
27	}
28
29	return common.BalanceOf(tokenPath, communityPoolAddr), nil
30}
31
32// TransferToken transfers token units from the community pool to an address.
33//
34// Parameters:
35//   - cur: current realm context; callers use cross(cur) when crossing into this realm
36//   - tokenPath: registry key/path of the registered token to transfer
37//   - to: recipient address for the token units
38//   - amount: number of token units to transfer; transfer failure panics through the safe wrapper
39//
40// Only callable by admin or governance while withdrawals are not halted.
41// Governance is the recommended normal route. While governance is not yet
42// mature, admin access is retained for emergency-only use as an operational
43// policy, not a contract-enforced condition. Admin calls do not require an
44// approved proposal; emergency status is not checked and admin access does
45// not expire automatically.
46func TransferToken(cur realm, tokenPath string, to address, amount int64) {
47	halt.AssertIsNotHaltedWithdraw()
48
49	prevRealm := cur.Previous()
50	caller := prevRealm.Address()
51	access.AssertIsAdminOrGovernance(caller)
52
53	common.SafeGRC20Transfer(0, cur, tokenPath, to, amount)
54
55	chain.Emit(
56		"TransferToken",
57		"prevAddr", caller.String(),
58		"prevRealm", prevRealm.PkgPath(),
59		"tokenPath", tokenPath,
60		"to", to.String(),
61		"amount", strconv.FormatInt(amount, 10),
62	)
63}