Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

protocol_fee source realm

Package protocol\_fee manages fee collection and distribution for GnoSwap protocol operations.

Readme View source

Protocol Fee

Fee collection and distribution for protocol operations.

Overview

Protocol Fee contract collects fees from various protocol operations and distributes them to xGNS holders and DevOps.

Configuration

  • Router Fee: 0.15% of swap amount
  • Pool Creation Fee: 100 GNS
  • Withdrawal Fee: 1% of LP fees claimed
  • Unstaking Fee: 1% of staking rewards
  • Distribution: 100% to xGNS holders (default)

Fee Sources

  1. Swaps: 0.15% fee on all trades
  2. Pool Creation: 100 GNS per new pool
  3. LP Withdrawals: 1% of collected fees
  4. Staking Claims: 1% of rewards

Key Functions

DistributeProtocolFee

Distributes accumulated fees to recipients.

SetDevOpsPct

Sets DevOps funding percentage.

SetGovStakerPct

Sets xGNS holder percentage.

AddToProtocolFee

Adds fees to distribution queue.

Usage

1// Distribute accumulated fees
2tokenAmounts := DistributeProtocolFee()
3
4// Configure distribution
5SetDevOpsPct(2000)     // 20% to DevOps
6SetGovStakerPct(8000)  // 80% to xGNS holders
7
8// View tokens reserved for the next distribution
9GetReservedTokens()

Security

  • Admin-only configuration changes
  • Automatic fee accumulation
  • Multi-token support
  • Transparent distribution tracking

Overview

Package protocol_fee manages fee collection and distribution for GnoSwap protocol operations.

This contract collects fees from various protocol operations (swaps, pool creation, withdrawals, staking claims) and distributes them to DevOps and Governance Stakers according to configurable percentages.

Distribution Targets:

  • DevOps: Development and operations fund (default 0%)
  • GovStaker: Governance stakers / xGNS holders (default 100%)

Key Functions:

  • DistributeProtocolFee: Distributes accumulated fees to recipients
  • SetDevOpsPct/SetGovStakerPct: Configure distribution percentages
  • AddToProtocolFee: Adds fees to the distribution queue

The contract uses a version manager pattern for upgradeable implementations.

Constants 1

const StoreKeyDevOpsPct, StoreKeyAccuToGovStaker, StoreKeyAccuToDevOps, StoreKeyDistributedToGovStakerHistory, StoreKeyDistributedToDevOpsHistory, StoreKeyReservedTokens

 1const (
 2	// By default, devOps will get 0% of the protocol fee (which means gov/staker will get 100% of the protocol fee)
 3	// This percentage can be modified through governance.
 4	StoreKeyDevOpsPct StoreKey = "devOpsPct"
 5
 6	// accumulated amount distributed to gov/staker by token path
 7	StoreKeyAccuToGovStaker StoreKey = "accuToGovStaker" // tokenPath -> amount
 8	StoreKeyAccuToDevOps    StoreKey = "accuToDevOps"    // tokenPath -> amount
 9
10	// distributedToDevOpsHistory and distributedToGovStakerHistory are used to keep track of the distribution history
11	StoreKeyDistributedToGovStakerHistory StoreKey = "distributedToGovStakerHistory" // tokenPath -> amount
12	StoreKeyDistributedToDevOpsHistory    StoreKey = "distributedToDevOpsHistory"    // tokenPath -> amount
13
14	// reservedTokens tracks token paths collected but not yet distributed.
15	StoreKeyReservedTokens StoreKey = "reservedTokens"
16)
source

Functions 23

func AddToProtocolFee

crossing Action
1func AddToProtocolFee(cur realm, tokenPath string, amount int64) error
source

AddToProtocolFee adds tokens to the protocol fee pool.

Parameters:

  • tokenPath: path of the token
  • amount: amount to add

func DistributeProtocolFee

crossing Action
1func DistributeProtocolFee(cur realm)
source

DistributeProtocolFee distributes accumulated protocol fees to DevOps and GovStaker.

func NewBPTreeN

Action
1func NewBPTreeN(fanout int) *bptree.BPTree
source

NewBPTreeN allocates a BP-tree under /r/gnoswap/protocol_fee's realm context so tree.Set leaf-slot writes clear the readonly-taint gate regardless of which realm (protocol_fee/v1, mock, tests) calls Set. Callers must allocate protocol_fee trees through here rather than bptree.NewBPTreeN directly.

func RegisterInitializer

crossing Action
1func RegisterInitializer(cur realm, initializer func(_ int, rlm realm, protocolFeeStore IProtocolFeeStore) IProtocolFee)
source

RegisterInitializer registers a new pool implementation version. This function is called by each version (v1, v2, etc.) during initialization to register their implementation with the proxy system.

The initializer function creates a new instance of the implementation using the provided protocolFeeStore interface. It receives a realm value that resolves to the protocol_fee proxy realm — the only address with write permission on the shared KV store — so any per-version store bootstrapping performed inside the initializer passes the proxy's authorization check.

Security: Only contracts within the domain path can register initializers. Each package path can only register once to prevent duplicate registrations.

func SetDevOpsPct

crossing Action
1func SetDevOpsPct(cur realm, pct int64)
source

SetDevOpsPct sets the percentage of protocol fees allocated to DevOps.

Parameters:

  • pct: percentage (0-100)

func SetGovStakerPct

crossing Action
1func SetGovStakerPct(cur realm, pct int64)
source

SetGovStakerPct sets the percentage of protocol fees allocated to GovStaker.

Parameters:

  • pct: percentage (0-100)

func UpgradeImpl

crossing Action
1func UpgradeImpl(cur realm, packagePath string)
source

UpgradeImpl switches the active protocol fee implementation to a different version. This function allows seamless upgrades from one version to another without data migration or downtime.

Security: Only admin or governance can perform upgrades. The new implementation must have been previously registered via RegisterInitializer.

func NewProtocolFeeStore

Action
1func NewProtocolFeeStore(kvStore store.KVStore) IProtocolFeeStore
source

NewprotocolFeeStore creates a new protocol fee store instance with the provided KV store. This function is used by the upgrade system to create storage instances for each implementation.

Types 5

type IProtocolFee

interface
1type IProtocolFee interface {
2	IProtocolFeeManager
3	IProtocolFeeGetter
4}
source

type IProtocolFeeGetter

interface
 1type IProtocolFeeGetter interface {
 2	GetDevOpsPct() int64
 3	GetGovStakerPct() int64
 4	GetReservedTokens() []string
 5	GetAccuTransfersToGovStaker() map[string]int64
 6	GetAccuTransfersToDevOps() map[string]int64
 7	GetAccuTransferToGovStakerByTokenPath(path string) int64
 8	GetAccuTransferToDevOpsByTokenPath(path string) int64
 9	GetActualDistributedToGovStaker() map[string]int64
10	GetActualDistributedToDevOps() map[string]int64
11	GetActualDistributedToGovStakerByTokenPath(path string) int64
12	GetActualDistributedToDevOpsByTokenPath(path string) int64
13}
source

type IProtocolFeeManager

interface
 1type IProtocolFeeManager interface {
 2	// Mutating methods take `_ int, rlm realm` so the realm token is threaded
 3	// from the proxy entry points down to the cross-realm token transfers and
 4	// store writes performed inside each implementation. The `_ int` sentinel
 5	// surfaces at every call site as a literal `0`, making the realm threading
 6	// visible to readers.
 7	DistributeProtocolFee(_ int, rlm realm)
 8	DistributeProtocolFeeByTokenPath(_ int, rlm realm, tokenPath string)
 9	SetDevOpsPct(_ int, rlm realm, pct int64)
10	SetGovStakerPct(_ int, rlm realm, pct int64)
11	AddToProtocolFee(_ int, rlm realm, tokenPath string, amount int64) error
12}
source

type IProtocolFeeStore

interface
 1type IProtocolFeeStore interface {
 2	HasDevOpsPctStoreKey() bool
 3	InitializeDevOpsPct(_ int, rlm realm) error
 4	GetDevOpsPct() int64
 5	SetDevOpsPct(_ int, rlm realm, pct int64) error
 6
 7	HasAccuToGovStakerStoreKey() bool
 8	InitializeAccuToGovStaker(_ int, rlm realm) error
 9	GetAccuToGovStaker() *bptree.BPTree
10	GetAccuToGovStakerItem(tokenPath string) (int64, bool)
11	SetAccuToGovStakerItem(_ int, rlm realm, tokenPath string, amount int64) error
12
13	HasAccuToDevOpsStoreKey() bool
14	InitializeAccuToDevOps(_ int, rlm realm) error
15	GetAccuToDevOps() *bptree.BPTree
16	GetAccuToDevOpsItem(tokenPath string) (int64, bool)
17	SetAccuToDevOpsItem(_ int, rlm realm, tokenPath string, amount int64) error
18
19	HasDistributedToGovStakerHistoryStoreKey() bool
20	InitializeDistributedToGovStakerHistory(_ int, rlm realm) error
21	GetDistributedToGovStakerHistory() *bptree.BPTree
22	GetDistributedToGovStakerHistoryItem(tokenPath string) (int64, bool)
23	SetDistributedToGovStakerHistoryItem(_ int, rlm realm, tokenPath string, amount int64) error
24
25	HasDistributedToDevOpsHistoryStoreKey() bool
26	InitializeDistributedToDevOpsHistory(_ int, rlm realm) error
27	GetDistributedToDevOpsHistory() *bptree.BPTree
28	GetDistributedToDevOpsHistoryItem(tokenPath string) (int64, bool)
29	SetDistributedToDevOpsHistoryItem(_ int, rlm realm, tokenPath string, amount int64) error
30
31	HasReservedTokensStoreKey() bool
32	InitializeReservedTokens(_ int, rlm realm) error
33	GetReservedTokens() []string
34	SetReservedTokens(_ int, rlm realm, reservedTokens []string) error
35	AddReservedToken(_ int, rlm realm, tokenPath string) error
36}
source

type StoreKey

ident
1type StoreKey string
source

Methods on StoreKey

func String

method on StoreKey
1func (s StoreKey) String() string
source

Imports 7

Source Files 10