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

# protocol\_fee\_reward\_state.gno

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

## Types

### ProtocolFeeRewardState

```go
type ProtocolFeeRewardState struct
```

ProtocolFeeRewardState tracks the protocol fee rewards of one staker.

Ordinary stake changes append one ProtocolFeeStakeEvent; Redelegate performs a remove plus an add and appends two events. Each token is settled on its own from those events, so the state keeps a per-token cursor into the event history rather than a reward debt for every token at once.

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

#### Methods

**AppendStakeEvent**

```go
func (p *ProtocolFeeRewardState) AppendStakeEvent(
	epoch int64,
	stakedAmount int64
)
```

AppendStakeEvent records that stakedAmount is staked from epoch on.

#### Parameters

| Name           | Type  | Description                                                |
| -------------- | ----- | ---------------------------------------------------------- |
| `epoch`        | int64 | accrual epoch at which this stake amount becomes effective |
| `stakedAmount` | int64 | stake amount in force from epoch onward                    |

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

**GetClaimedReward**

```go
func (p *ProtocolFeeRewardState) GetClaimedReward(
	tokenPath string
) int64
```

GetClaimedReward returns the total reward of tokenPath collected so far.

#### Parameters

| Name        | Type   | Description                                              |
| ----------- | ------ | -------------------------------------------------------- |
| `tokenPath` | string | token path whose accumulated claimed reward is requested |

#### Return Values

| Name    | Type  | Description                                                              |
| ------- | ----- | ------------------------------------------------------------------------ |
| `int64` | int64 | total reward collected for tokenPath, or zero when no token state exists |

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

**GetClaimedTimestamp**

```go
func (p *ProtocolFeeRewardState) GetClaimedTimestamp() int64
```

GetClaimedTimestamp returns the last timestamp at which all token rewards were collected.

#### Return Values

| Name    | Type  | Description                                                      |
| ------- | ----- | ---------------------------------------------------------------- |
| `int64` | int64 | Unix timestamp recorded for the most recent all-token collection |

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

**GetStakeEvent**

```go
func (p *ProtocolFeeRewardState) GetStakeEvent(
	index int64
) (*ProtocolFeeStakeEvent, bool)
```

GetStakeEvent returns the indexed stake event.

#### Parameters

| Name    | Type  | Description                  |
| ------- | ----- | ---------------------------- |
| `index` | int64 | zero-based stake-event index |

#### Return Values

| Name                     | Type                    | Description                                                        |
| ------------------------ | ----------------------- | ------------------------------------------------------------------ |
| `*ProtocolFeeStakeEvent` | \*ProtocolFeeStakeEvent | event at index, or nil when no event is stored there               |
| `bool`                   | bool                    | true when an event exists at index; false when the index is absent |

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

**GetStakeEventCount**

```go
func (p *ProtocolFeeRewardState) GetStakeEventCount() int64
```

GetStakeEventCount returns the number of stake-change events recorded.

#### Return Values

| Name    | Type  | Description                   |
| ------- | ----- | ----------------------------- |
| `int64` | int64 | count of indexed stake events |

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

**GetStakedAmount**

```go
func (p *ProtocolFeeRewardState) GetStakedAmount() int64
```

GetStakedAmount returns the current stake amount tracked for the staker.

#### Return Values

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

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

**GetTokenPaths**

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

GetTokenPaths returns every token path settled for this staker, in key order.

#### Return Values

| Name       | Type      | Description                                                                   |
| ---------- | --------- | ----------------------------------------------------------------------------- |
| `[]string` | \[]string | token paths with stored settlement state, ordered by the underlying tree keys |

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

**GetTokenState**

```go
func (p *ProtocolFeeRewardState) GetTokenState(
	tokenPath string
) (*ProtocolFeeTokenRewardState, bool)
```

GetTokenState returns the settlement state of tokenPath, or false when the token was never settled for this staker.

#### Parameters

| Name        | Type   | Description                                                          |
| ----------- | ------ | -------------------------------------------------------------------- |
| `tokenPath` | string | registered token path whose per-staker settlement state is requested |

#### Return Values

| Name                           | Type                          | Description                                                        |
| ------------------------------ | ----------------------------- | ------------------------------------------------------------------ |
| `*ProtocolFeeTokenRewardState` | \*ProtocolFeeTokenRewardState | token settlement state, or nil when it has not been initialized    |
| `bool`                         | bool                          | true when tokenPath has a stored settlement state, otherwise false |

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

**SetClaimedTimestamp**

```go
func (p *ProtocolFeeRewardState) SetClaimedTimestamp(
	claimedTimestamp int64
)
```

SetClaimedTimestamp records the timestamp at which all token rewards were collected.

#### Parameters

| Name               | Type  | Description                                |
| ------------------ | ----- | ------------------------------------------ |
| `claimedTimestamp` | int64 | Unix timestamp of the all-token collection |

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

**SetStakedAmount**

```go
func (p *ProtocolFeeRewardState) SetStakedAmount(
	stakedAmount int64
)
```

SetStakedAmount updates the current stake amount tracked for the staker.

#### Parameters

| Name           | Type  | Description               |
| -------------- | ----- | ------------------------- |
| `stakedAmount` | int64 | new current staked amount |

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

**SetTokenState**

```go
func (p *ProtocolFeeRewardState) SetTokenState(
	tokenPath string,
	tokenState *ProtocolFeeTokenRewardState
)
```

SetTokenState stores the settlement state for a token path.

#### Parameters

| Name         | Type                          | Description                                 |
| ------------ | ----------------------------- | ------------------------------------------- |
| `tokenPath`  | string                        | token path used as the settlement-state key |
| `tokenState` | \*ProtocolFeeTokenRewardState | per-token settlement state to store         |

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

#### Constructors

* `func NewProtocolFeeRewardState() *ProtocolFeeRewardState` ([source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_state.gno#L69))

### ProtocolFeeStakeEvent

```go
type ProtocolFeeStakeEvent struct
```

ProtocolFeeStakeEvent is one stake change: from epoch on, stakedAmount was staked.

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

#### Methods

**GetEpoch**

```go
func (e *ProtocolFeeStakeEvent) GetEpoch() int64
```

GetEpoch returns the accrual epoch from which this stake event applies.

#### Return Values

| Name    | Type  | Description                                      |
| ------- | ----- | ------------------------------------------------ |
| `int64` | int64 | epoch at which the stake amount became effective |

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

**GetStakedAmount**

```go
func (e *ProtocolFeeStakeEvent) GetStakedAmount() int64
```

GetStakedAmount returns the stake amount in force for this event.

#### Return Values

| Name    | Type  | Description                             |
| ------- | ----- | --------------------------------------- |
| `int64` | int64 | staked amount associated with the event |

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

### ProtocolFeeTokenRewardState

```go
type ProtocolFeeTokenRewardState struct
```

ProtocolFeeTokenRewardState is the settlement state of one token for one staker.

Stake events up to eventCursor are folded into earnedX128. The open segment starts where the last folded event left the accumulator (segmentStartX128) with segmentStakedAmount staked.

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

#### Methods

**GetClaimedReward**

```go
func (t *ProtocolFeeTokenRewardState) GetClaimedReward() int64
```

GetClaimedReward returns the total reward collected for this token state.

#### Return Values

| Name    | Type  | Description                        |
| ------- | ----- | ---------------------------------- |
| `int64` | int64 | cumulative collected reward amount |

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

**GetEarnedX128**

```go
func (t *ProtocolFeeTokenRewardState) GetEarnedX128() *u256.Uint
```

GetEarnedX128 returns closed-segment earnings awaiting collection.

#### Return Values

| Name         | Type        | Description                                  |
| ------------ | ----------- | -------------------------------------------- |
| `*u256.Uint` | \*u256.Uint | unclaimed reward accumulator scaled by 2^128 |

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

**GetEventCursor**

```go
func (t *ProtocolFeeTokenRewardState) GetEventCursor() int64
```

GetEventCursor returns the number of stake events already folded for this token.

#### Return Values

| Name    | Type  | Description                  |
| ------- | ----- | ---------------------------- |
| `int64` | int64 | count of folded stake events |

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

**GetSegmentStakedAmount**

```go
func (t *ProtocolFeeTokenRewardState) GetSegmentStakedAmount() int64
```

GetSegmentStakedAmount returns the stake amount in the open segment.

#### Return Values

| Name    | Type  | Description                                       |
| ------- | ----- | ------------------------------------------------- |
| `int64` | int64 | stake amount used while settling the open segment |

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

**GetSegmentStartX128**

```go
func (t *ProtocolFeeTokenRewardState) GetSegmentStartX128() *u256.Uint
```

GetSegmentStartX128 returns the accumulator value at the open segment start.

#### Return Values

| Name         | Type        | Description                                                 |
| ------------ | ----------- | ----------------------------------------------------------- |
| `*u256.Uint` | \*u256.Uint | fee-per-stake accumulator at segment start, scaled by 2^128 |

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

**SetClaimedReward**

```go
func (t *ProtocolFeeTokenRewardState) SetClaimedReward(
	claimedReward int64
)
```

SetClaimedReward replaces the cumulative collected reward amount.

#### Parameters

| Name            | Type  | Description                                 |
| --------------- | ----- | ------------------------------------------- |
| `claimedReward` | int64 | total reward collected for this token state |

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

**SetEarnedX128**

```go
func (t *ProtocolFeeTokenRewardState) SetEarnedX128(
	earnedX128 *u256.Uint
)
```

SetEarnedX128 replaces the closed-segment earnings accumulator.

#### Parameters

| Name         | Type        | Description                                    |
| ------------ | ----------- | ---------------------------------------------- |
| `earnedX128` | \*u256.Uint | unclaimed earnings accumulator scaled by 2^128 |

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

**SetSegment**

```go
func (t *ProtocolFeeTokenRewardState) SetSegment(
	eventCursor int64,
	segmentStakedAmount int64,
	segmentStartX128 *u256.Uint
)
```

SetSegment moves the open segment: events up to eventCursor are folded, and the segment starts at segmentStartX128 with segmentStakedAmount staked.

#### Parameters

| Name                  | Type        | Description                                                         |
| --------------------- | ----------- | ------------------------------------------------------------------- |
| `eventCursor`         | int64       | number of stake events folded into the new segment                  |
| `segmentStakedAmount` | int64       | stake amount in force for the new open segment                      |
| `segmentStartX128`    | \*u256.Uint | fee-per-stake accumulator at the new segment start, scaled by 2^128 |

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

#### Constructors

* `func NewProtocolFeeTokenRewardState(eventCursor int64, segmentStakedAmount int64, segmentStartX128 *u256.Uint) *ProtocolFeeTokenRewardState` ([source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/gov/staker/protocol_fee_reward_state.gno#L89))
