# Hooks

Available hooks that can be called by and from this module.

### Create or modify delegation distribution <a href="#create-or-modify-delegation-distribution" id="create-or-modify-delegation-distribution"></a>

* triggered-by: `staking.MsgDelegate`, `staking.MsgBeginRedelegate`, `staking.MsgUndelegate`

#### Before <a href="#before" id="before"></a>

* The delegation rewards are withdrawn to the withdraw address of the delegator. The rewards include the current period and exclude the starting period.
* The validator period is incremented. The validator period is incremented because the validator's power and share distribution might have changed.
* The reference count for the delegator's starting period is decremented.

#### After <a href="#after" id="after"></a>

The starting height of the delegation is set to the previous period. Because of the `Before`-hook, this period is the last period for which the delegator was rewarded.

### Validator created <a href="#validator-created" id="validator-created"></a>

* triggered-by: `staking.MsgCreateValidator`

When a validator is created, the following validator variables are initialized:

* Historical rewards
* Current accumulated rewards
* Accumulated commission
* Total outstanding rewards
* Period

By default, all values are set to a `0`, except period, which is set to `1`.

### Validator removed <a href="#validator-removed" id="validator-removed"></a>

* triggered-by: `staking.RemoveValidator`

Outstanding commission is sent to the validator's self-delegation withdrawal address. Remaining delegator rewards get sent to the community fee pool.

Note: The validator gets removed only when it has no remaining delegations. At that time, all outstanding delegator rewards will have been withdrawn. Any remaining rewards are dust amounts.

### Validator is slashed <a href="#validator-is-slashed" id="validator-is-slashed"></a>

* triggered-by: `staking.Slash`
* The current validator period reference count is incremented. The reference count is incremented because the slash event has created a reference to it.
* The validator period is incremented.
* The slash event is stored for later use. The slash event will be referenced when calculating delegator rewards.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.metanovaverse.com/protocol-developers/modules/distribution/hooks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
