> For the complete documentation index, see [llms.txt](https://docs.gnoswap.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gnoswap.io/contracts/gov/staker/protocol_fee_reward_manager.gno.md).

# protocol\_fee\_reward\_manager.gno

{% embed url="<https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno>" %}

## Types

### ProtocolFeeRewardManager

```go
type ProtocolFeeRewardManager struct
```

ProtocolFeeRewardManager distributes protocol fees to stakers.

Protocol fees arrive in many tokens, so the manager keeps one accumulator per token instead of a single one. A stake change never touches those accumulators: it advances the accrual epoch, records the total stake in force from that epoch, and appends one event for an ordinary add/remove. Redelegate performs a remove plus an add and therefore appends two events. The per-token work happens when a token is collected, so stake-change cost does not depend on how many tokens ever collected a fee.

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L18)

#### Methods

**GetAccumulatedProtocolFeeX128PerStake**

```go
func (p *ProtocolFeeRewardManager) GetAccumulatedProtocolFeeX128PerStake(
	tokenPath string
) *u256.Uint
```

GetAccumulatedProtocolFeeX128PerStake returns the accumulated fee per stake of tokenPath (scaled by 2^128), or nil when the token never had a fee folded in.

#### Parameters

| Name        | Type   | Description                                                     |
| ----------- | ------ | --------------------------------------------------------------- |
| `tokenPath` | string | token package path whose accumulated per-stake fee is requested |

#### Return Values

| Name         | Type        | Description                                                                         |
| ------------ | ----------- | ----------------------------------------------------------------------------------- |
| `*u256.Uint` | \*u256.Uint | accumulated fee per stake scaled by 2^128, or nil when tokenPath has no accumulator |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L118)

**GetAccumulatedTimestamp**

```go
func (p *ProtocolFeeRewardManager) GetAccumulatedTimestamp() int64
```

GetAccumulatedTimestamp returns the last timestamp at which fee accrual state moved through a fold or stake change.

#### Return Values

| Name    | Type  | Description                             |
| ------- | ----- | --------------------------------------- |
| `int64` | int64 | last accumulated-state update timestamp |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L188)

**GetCurrentEpoch**

```go
func (p *ProtocolFeeRewardManager) GetCurrentEpoch() int64
```

GetCurrentEpoch returns the accrual epoch currently in force.

#### Return Values

| Name    | Type  | Description                        |
| ------- | ----- | ---------------------------------- |
| `int64` | int64 | current protocol-fee accrual epoch |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L145)

**GetProtocolFeeAmount**

```go
func (p *ProtocolFeeRewardManager) GetProtocolFeeAmount(
	tokenPath string
) int64
```

GetProtocolFeeAmount returns the total fee amount folded in for tokenPath.

#### Parameters

| Name        | Type   | Description                                                      |
| ----------- | ------ | ---------------------------------------------------------------- |
| `tokenPath` | string | token package path whose folded protocol-fee amount is requested |

#### Return Values

| Name    | Type  | Description                                                               |
| ------- | ----- | ------------------------------------------------------------------------- |
| `int64` | int64 | total fee amount folded for tokenPath, or zero when no accumulator exists |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L133)

**GetRewardState**

```go
func (p *ProtocolFeeRewardManager) GetRewardState(
	rewardID string
) (*ProtocolFeeRewardState, bool, error)
```

GetRewardState retrieves the reward state identified by rewardID. Missing IDs return nil and false; a stored value of the wrong type returns an error.

#### Parameters

| Name       | Type   | Description                                       |
| ---------- | ------ | ------------------------------------------------- |
| `rewardID` | string | identifier of the staker reward state to retrieve |

#### Return Values

| Name                      | Type                     | Description                                                                     |
| ------------------------- | ------------------------ | ------------------------------------------------------------------------------- |
| `*ProtocolFeeRewardState` | \*ProtocolFeeRewardState | stored reward state, or nil when rewardID is absent or invalid                  |
| `bool`                    | bool                     | true when a correctly typed reward state was found                              |
| `error`                   | error                    | nil when absent or found; a cast error when the stored value has the wrong type |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L64)

**GetTokenAccumulator**

```go
func (p *ProtocolFeeRewardManager) GetTokenAccumulator(
	tokenPath string
) (*ProtocolFeeTokenAccumulator, bool)
```

GetTokenAccumulator returns the accumulator of tokenPath, or false when the token never had a fee folded in.

#### Parameters

| Name        | Type   | Description                                                    |
| ----------- | ------ | -------------------------------------------------------------- |
| `tokenPath` | string | token package path whose protocol-fee accumulator is requested |

#### Return Values

| Name                           | Type                          | Description                                        |
| ------------------------------ | ----------------------------- | -------------------------------------------------- |
| `*ProtocolFeeTokenAccumulator` | \*ProtocolFeeTokenAccumulator | accumulator for tokenPath, or nil when none exists |
| `bool`                         | bool                          | true when tokenPath has a folded-fee accumulator   |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L85)

**GetTokenPaths**

```go
func (p *ProtocolFeeRewardManager) GetTokenPaths() []string
```

GetTokenPaths returns every token path that had a fee folded in, in key order.

#### Return Values

| Name       | Type      | Description                                                      |
| ---------- | --------- | ---------------------------------------------------------------- |
| `[]string` | \[]string | token paths present in the accumulator tree, ordered by tree key |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L101)

**GetTotalStakedAmount**

```go
func (p *ProtocolFeeRewardManager) GetTotalStakedAmount() int64
```

GetTotalStakedAmount returns the total amount currently staked.

#### Return Values

| Name    | Type  | Description                 |
| ------- | ----- | --------------------------- |
| `int64` | int64 | current total staked amount |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L153)

**GetTotalStakedAmountAt**

```go
func (p *ProtocolFeeRewardManager) GetTotalStakedAmountAt(
	epoch int64
) int64
```

GetTotalStakedAmountAt returns the total staked amount in force during epoch, using the latest recorded stake amount at or before that epoch.

#### Parameters

| Name    | Type  | Description                                            |
| ------- | ----- | ------------------------------------------------------ |
| `epoch` | int64 | accrual epoch whose effective total stake is requested |

#### Return Values

| Name    | Type  | Description                                                           |
| ------- | ----- | --------------------------------------------------------------------- |
| `int64` | int64 | total stake recorded at or before epoch, or zero for a negative epoch |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L165)

**SetAccumulatedTimestamp**

```go
func (p *ProtocolFeeRewardManager) SetAccumulatedTimestamp(
	accumulatedTimestamp int64
)
```

SetAccumulatedTimestamp records the timestamp at which accrual state last moved.

#### Parameters

| Name                   | Type  | Description                                             |
| ---------------------- | ----- | ------------------------------------------------------- |
| `accumulatedTimestamp` | int64 | timestamp to record for the latest fold or stake change |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L241)

**SetCurrentEpoch**

```go
func (p *ProtocolFeeRewardManager) SetCurrentEpoch(
	epoch int64
)
```

SetCurrentEpoch records the accrual epoch currently in force.

#### Parameters

| Name    | Type  | Description                            |
| ------- | ----- | -------------------------------------- |
| `epoch` | int64 | new current protocol-fee accrual epoch |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L216)

**SetRewardState**

```go
func (p *ProtocolFeeRewardManager) SetRewardState(
	rewardID string,
	rewardState *ProtocolFeeRewardState
)
```

SetRewardState stores rewardState under rewardID.

#### Parameters

| Name          | Type                     | Description                                              |
| ------------- | ------------------------ | -------------------------------------------------------- |
| `rewardID`    | string                   | identifier under which the staker reward state is stored |
| `rewardState` | \*ProtocolFeeRewardState | reward state to associate with rewardID                  |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L199)

**SetTokenAccumulator**

```go
func (p *ProtocolFeeRewardManager) SetTokenAccumulator(
	tokenPath string,
	accumulator *ProtocolFeeTokenAccumulator
)
```

SetTokenAccumulator stores accumulator under tokenPath.

#### Parameters

| Name          | Type                          | Description                                     |
| ------------- | ----------------------------- | ----------------------------------------------- |
| `tokenPath`   | string                        | token package path used as the accumulator key  |
| `accumulator` | \*ProtocolFeeTokenAccumulator | protocol-fee accumulator to store for tokenPath |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L208)

**SetTotalStakedAmount**

```go
func (p *ProtocolFeeRewardManager) SetTotalStakedAmount(
	totalStakedAmount int64
)
```

SetTotalStakedAmount records the total amount currently staked.

#### Parameters

| Name                | Type  | Description             |
| ------------------- | ----- | ----------------------- |
| `totalStakedAmount` | int64 | new total staked amount |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L224)

**SetTotalStakedAmountAt**

```go
func (p *ProtocolFeeRewardManager) SetTotalStakedAmountAt(
	epoch int64,
	totalStakedAmount int64
)
```

SetTotalStakedAmountAt records the total staked amount in force from epoch on.

#### Parameters

| Name                | Type  | Description                                                |
| ------------------- | ----- | ---------------------------------------------------------- |
| `epoch`             | int64 | first accrual epoch at which totalStakedAmount is in force |
| `totalStakedAmount` | int64 | total stake amount to record from epoch onward             |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L233)

#### Constructors

* `func NewProtocolFeeRewardManager() *ProtocolFeeRewardManager` ([source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_manager.gno#L37))
