Search Apps Documentation Source Content File Folder Download Copy Actions Download

community_pool.gno

1.30 Kb · 52 lines
 1package community_pool
 2
 3import (
 4	"chain"
 5	"strconv"
 6
 7	prbac "gno.land/p/gnoswap/rbac"
 8
 9	"gno.land/r/gnoswap/access"
10	"gno.land/r/gnoswap/common"
11	"gno.land/r/gnoswap/halt"
12)
13
14// GetBalanceOf returns the balance of a specific token held by the community pool.
15//
16// Parameters:
17//   - tokenPath: the path to the token contract (e.g., "gno.land/r/gnoswap/gns")
18//
19// Returns the balance of the specified token held by the community pool.
20func GetBalanceOf(tokenPath string) int64 {
21	communityPoolAddr := access.MustGetAddress(prbac.ROLE_COMMUNITY_POOL.String())
22
23	return common.BalanceOf(tokenPath, communityPoolAddr)
24}
25
26// TransferToken transfers tokens from the community pool.
27//
28// Parameters:
29//   - cur: current realm
30//   - tokenPath: token contract path
31//   - to: recipient address
32//   - amount: transfer amount
33//
34// Only callable by admin or governance.
35func TransferToken(cur realm, tokenPath string, to address, amount int64) {
36	halt.AssertIsNotHaltedWithdraw()
37
38	prevRealm := cur.Previous()
39	caller := prevRealm.Address()
40	access.AssertIsAdminOrGovernance(caller)
41
42	common.SafeGRC20Transfer(cross(cur), tokenPath, to, amount)
43
44	chain.Emit(
45		"TransferToken",
46		"prevAddr", caller.String(),
47		"prevRealm", prevRealm.PkgPath(),
48		"tokenPath", tokenPath,
49		"to", to.String(),
50		"amount", strconv.FormatInt(amount, 10),
51	)
52}