Search Apps Documentation Source Content File Folder Download Copy Actions Download

community_pool.gno

1.34 Kb ยท 53 lines
 1package community_pool
 2
 3import (
 4	"chain"
 5	"chain/runtime"
 6	"strconv"
 7
 8	prbac "gno.land/p/gnoswap/rbac"
 9
10	"gno.land/r/gnoswap/access"
11	"gno.land/r/gnoswap/common"
12	"gno.land/r/gnoswap/halt"
13)
14
15// GetBalanceOf returns the balance of a specific token held by the community pool.
16//
17// Parameters:
18//   - tokenPath: the path to the token contract (e.g., "gno.land/r/gnoswap/gns")
19//
20// Returns the balance of the specified token held by the community pool.
21func GetBalanceOf(tokenPath string) int64 {
22	communityPoolAddr := access.MustGetAddress(prbac.ROLE_COMMUNITY_POOL.String())
23
24	return common.BalanceOf(tokenPath, communityPoolAddr)
25}
26
27// TransferToken transfers tokens from the community pool.
28//
29// Parameters:
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.AssertIsNotHaltedCommunityPool()
37	halt.AssertIsNotHaltedWithdraw()
38
39	prevRealm := runtime.PreviousRealm()
40	caller := prevRealm.Address()
41	access.AssertIsAdminOrGovernance(caller)
42
43	common.SafeGRC20Transfer(cross, tokenPath, to, amount)
44
45	chain.Emit(
46		"TransferToken",
47		"prevAddr", caller.String(),
48		"prevRealm", prevRealm.PkgPath(),
49		"tokenPath", tokenPath,
50		"to", to.String(),
51		"amount", strconv.FormatInt(amount, 10),
52	)
53}