> 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_token_accumulator.gno.md).

# protocol\_fee\_token\_accumulator.gno

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

## Types

### ProtocolFeeTokenAccumulator

```go
type ProtocolFeeTokenAccumulator struct
```

ProtocolFeeTokenAccumulator tracks the accumulated protocol fee per stake of one token.

Fees are folded in per accrual epoch, each against the total stake in force during that epoch. The value after folding each epoch is kept in history so that a staker's reward can be settled later against the accumulator as it stood at any epoch.

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

#### Methods

**GetAccumulatedX128PerStake**

```go
func (a *ProtocolFeeTokenAccumulator) GetAccumulatedX128PerStake() *u256.Uint
```

GetAccumulatedX128PerStake returns the latest accumulated protocol fee per stake, scaled by 2^128.

#### Return Values

| Name         | Type        | Description                                                      |
| ------------ | ----------- | ---------------------------------------------------------------- |
| `*u256.Uint` | \*u256.Uint | latest accumulated fee-per-stake value in Q128 fixed-point form. |

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

**GetAccumulatedX128PerStakeAt**

```go
func (a *ProtocolFeeTokenAccumulator) GetAccumulatedX128PerStakeAt(
	epoch int64
) *u256.Uint
```

GetAccumulatedX128PerStakeAt returns the accumulated value after the fees of the latest folded epoch at or before epoch, or zero when no fee was folded by then.

#### Parameters

| Name    | Type  | Description                                              |
| ------- | ----- | -------------------------------------------------------- |
| `epoch` | int64 | accrual epoch whose latest post-fold value is requested. |

#### Return Values

| Name         | Type        | Description                                                                                  |
| ------------ | ----------- | -------------------------------------------------------------------------------------------- |
| `*u256.Uint` | \*u256.Uint | accumulated fee per stake in Q128 fixed-point form, or zero when no fee was folded by epoch. |

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

**GetFirstEpoch**

```go
func (a *ProtocolFeeTokenAccumulator) GetFirstEpoch() int64
```

GetFirstEpoch returns the first epoch for which a fee was folded.

#### Return Values

| Name    | Type  | Description                                            |
| ------- | ----- | ------------------------------------------------------ |
| `int64` | int64 | first folded epoch, or -1 when no fee has been folded. |

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

**GetFoldedEpoch**

```go
func (a *ProtocolFeeTokenAccumulator) GetFoldedEpoch() int64
```

GetFoldedEpoch returns the last epoch known to be fully folded.

#### Return Values

| Name    | Type  | Description                                                   |
| ------- | ----- | ------------------------------------------------------------- |
| `int64` | int64 | last fully folded epoch, or -1 when no epoch is fully folded. |

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

**GetProtocolFeeAmount**

```go
func (a *ProtocolFeeTokenAccumulator) GetProtocolFeeAmount() int64
```

GetProtocolFeeAmount returns the total protocol fee amount folded into the accumulator.

#### Return Values

| Name    | Type  | Description                             |
| ------- | ----- | --------------------------------------- |
| `int64` | int64 | total fee amount folded for this token. |

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

**SetAccumulatedX128PerStakeAt**

```go
func (a *ProtocolFeeTokenAccumulator) SetAccumulatedX128PerStakeAt(
	epoch int64,
	value *u256.Uint
)
```

SetAccumulatedX128PerStakeAt stores value as the accumulated amount after epoch's fees and makes it the latest value.

#### Parameters

| Name    | Type        | Description                                               |
| ------- | ----------- | --------------------------------------------------------- |
| `epoch` | int64       | epoch whose post-fold accumulator value is being stored.  |
| `value` | \*u256.Uint | accumulated fee-per-stake value in Q128 fixed-point form. |

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

**SetFoldedEpoch**

```go
func (a *ProtocolFeeTokenAccumulator) SetFoldedEpoch(
	epoch int64
)
```

SetFoldedEpoch records the last epoch whose protocol fees are fully folded.

#### Parameters

| Name    | Type  | Description                        |
| ------- | ----- | ---------------------------------- |
| `epoch` | int64 | latest fully folded accrual epoch. |

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

**SetProtocolFeeAmount**

```go
func (a *ProtocolFeeTokenAccumulator) SetProtocolFeeAmount(
	amount int64
)
```

SetProtocolFeeAmount records the total protocol fee amount folded so far.

#### Parameters

| Name     | Type  | Description                                      |
| -------- | ----- | ------------------------------------------------ |
| `amount` | int64 | total folded protocol fee amount for this token. |

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

#### Constructors

* `func NewProtocolFeeTokenAccumulator() *ProtocolFeeTokenAccumulator` ([source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_token_accumulator.gno#L33))
