Search Apps Documentation Source Content File Folder Download Copy Actions Download

acr.gno

3.61 Kb · 145 lines
  1package acr
  2
  3import (
  4	"chain"
  5	"strconv"
  6
  7	"gno.land/p/g1nqnrt3aldzhu6zzeg75yw97wvavqy7wr77g56q/deploy-test/v2/accesscontrol"
  8	"gno.land/r/g1nqnrt3aldzhu6zzeg75yw97wvavqy7wr77g56q/deploy-test/v2/admin"
  9)
 10
 11const (
 12	MintEvent = "Mint"
 13)
 14
 15var acrStore *ACRStore
 16
 17func init(cur realm) {
 18	acrStore = newACRStore(cur)
 19}
 20
 21// ==================== GRC-20 Standard ====================
 22
 23func GetName() string {
 24	assertMigrationStateAvailable()
 25	return acrStore.GetName()
 26}
 27
 28func GetSymbol() string {
 29	assertMigrationStateAvailable()
 30	return acrStore.GetSymbol()
 31}
 32
 33func GetDecimals() int {
 34	assertMigrationStateAvailable()
 35	return acrStore.GetDecimals()
 36}
 37
 38func TotalSupply() int64 {
 39	assertMigrationStateAvailable()
 40	return acrStore.TotalSupply()
 41}
 42
 43func BalanceOf(account address) int64 {
 44	assertMigrationStateAvailable()
 45	return acrStore.BalanceOf(account)
 46}
 47
 48func Transfer(cur realm, to address, amount int64) {
 49	assertNotFrozen()
 50	caller := accesscontrol.MustGetUserCaller(0, cur)
 51	acrStore.Transfer(caller, to, amount)
 52}
 53
 54func Allowance(owner, spender address) int64 {
 55	assertMigrationStateAvailable()
 56	return acrStore.Allowance(owner, spender)
 57}
 58
 59func Approve(cur realm, spender address, amount int64) {
 60	assertNotFrozen()
 61	caller := accesscontrol.MustGetUserCaller(0, cur)
 62	acrStore.Approve(caller, spender, amount)
 63}
 64
 65func TransferFrom(cur realm, from, to address, amount int64) {
 66	assertNotFrozen()
 67	spender := accesscontrol.MustGetUserCaller(0, cur)
 68	acrStore.TransferFrom(from, spender, to, amount)
 69}
 70
 71// ==================== Admin Functions ====================
 72
 73// Mint mints ACR tokens to a user
 74func Mint(cur realm, requestID string, to address, amount int64) {
 75	assertNotFrozen()
 76	accesscontrol.AssertIsAdminOrOperator(0, cur, admin.IsAdmin, admin.IsOperator)
 77	if requestID == "" {
 78		panic("requestID is required")
 79	}
 80	if amount <= 0 {
 81		panic("amount must be positive")
 82	}
 83	acrStore.Mint(requestID, to, amount)
 84
 85	chain.Emit(
 86		MintEvent,
 87		"requestID", requestID,
 88		"to", to.String(),
 89		"amount", strconv.FormatInt(amount, 10),
 90	)
 91}
 92
 93// IsRequestProcessed checks if a requestID has been processed
 94func IsRequestProcessed(requestID string) bool {
 95	assertMigrationStateAvailable()
 96	return acrStore.IsRequestProcessed(requestID)
 97}
 98
 99// ListRequestProcessed checks multiple requestIDs and returns their processed status
100func ListRequestProcessed(requestIDs ...string) map[string]bool {
101	assertMigrationStateAvailable()
102	if len(requestIDs) > listLimit {
103		panic("requestIDs exceeds listLimit")
104	}
105	return acrStore.ListRequestProcessed(requestIDs...)
106}
107
108// Burn burns ACR tokens from caller
109func Burn(cur realm, amount int64) {
110	assertNotFrozen()
111	caller := accesscontrol.MustGetUserCaller(0, cur)
112	if amount <= 0 {
113		panic("amount must be positive")
114	}
115	acrStore.Burn(caller, amount)
116}
117
118// ListTopUsersByBalance returns top users sorted by balance (descending) with pagination
119func ListTopUsersByBalance(page int, count int) []map[string]string {
120	assertMigrationStateAvailable()
121	assertListPageCount(page, count)
122	return acrStore.ListTopUsersByBalance(page, count)
123}
124
125func GetBalanceRankingSize() int {
126	assertMigrationStateAvailable()
127	return acrStore.BalanceRankingCount()
128}
129
130func MintedOf(account address) int64 {
131	assertMigrationStateAvailable()
132	return acrStore.MintedOf(account)
133}
134
135// ListTopUsersByMinting returns top users sorted by total minted amount (descending) with pagination
136func ListTopUsersByMinting(page int, count int) []map[string]string {
137	assertMigrationStateAvailable()
138	assertListPageCount(page, count)
139	return acrStore.ListTopUsersByMinting(page, count)
140}
141
142func GetMintingRankingSize() int {
143	assertMigrationStateAvailable()
144	return acrStore.MintingRankingCount()
145}