package personal_world import ( "chain" "chain/runtime" "chain/banker" "gno.land/p/nt/ufmt" "gno.land/r/akkadia/admin" ) const ( SetFeeCollectorBPSEvent = "SetFeeCollectorBPS" SetListLimitEvent = "SetListLimit" SetBatchLimitEvent = "SetBatchLimit" ) var ( feeCollectorBPS int = 500 // 5% (500 BPS) listLimit int = 100 // Max items per list query batchLimit int = 1000 // Max keys per batch query ) // SetFeeCollectorBPS sets the feeCollector basis points (admin only) func SetFeeCollectorBPS(cur realm, bps int) { caller := runtime.PreviousRealm().Address() assertIsAdmin(caller) if bps < 0 || bps > 10000 { panic("bps must be between 0 and 10000") } oldBPS := feeCollectorBPS feeCollectorBPS = bps // Emit event chain.Emit( SetFeeCollectorBPSEvent, "admin", caller.String(), "oldBPS", ufmt.Sprintf("%d", oldBPS), "newBPS", ufmt.Sprintf("%d", bps), ) } // GetFeeCollectorBPS returns the feeCollector BPS func GetFeeCollectorBPS() int { return feeCollectorBPS } // SetListLimit sets the max items per list query (admin only) func SetListLimit(cur realm, limit int) { caller := runtime.PreviousRealm().Address() assertIsAdmin(caller) if limit < 1 { panic("limit must be at least 1") } oldLimit := listLimit listLimit = limit chain.Emit( SetListLimitEvent, "admin", caller.String(), "oldLimit", ufmt.Sprintf("%d", oldLimit), "newLimit", ufmt.Sprintf("%d", limit), ) } // GetListLimit returns the max items per list query func GetListLimit() int { return listLimit } // SetBatchLimit sets the max keys per batch query (admin only) func SetBatchLimit(cur realm, limit int) { caller := runtime.PreviousRealm().Address() assertIsAdmin(caller) if limit < 1 { panic("limit must be at least 1") } oldLimit := batchLimit batchLimit = limit chain.Emit( SetBatchLimitEvent, "admin", caller.String(), "oldLimit", ufmt.Sprintf("%d", oldLimit), "newLimit", ufmt.Sprintf("%d", limit), ) } // GetBatchLimit returns the max keys per batch query func GetBatchLimit() int { return batchLimit } func distributeFunds(amount int64) (int64, int64) { // Calculate feeCollector share (BPS) feeCollectorShare := (amount * int64(feeCollectorBPS)) / 10000 protocolShare := amount - feeCollectorShare // Send funds to feeCollector and protocol bnk := banker.NewBanker(banker.BankerTypeRealmSend) realmAddr := runtime.CurrentRealm().Address() if feeCollectorShare > 0 { coins := chain.Coins{chain.Coin{"ugnot", feeCollectorShare}} bnk.SendCoins(realmAddr, admin.GetFeeCollector(), coins) } if protocolShare > 0 { coins := chain.Coins{chain.Coin{"ugnot", protocolShare}} bnk.SendCoins(realmAddr, admin.GetProtocol(), coins) } return feeCollectorShare, protocolShare }