# Keeper activation and deactivation in PPAgentV2RANDAO

## Deactivating the keeper

When a keeper admin desires to disable his keeper, he invokes the function `disableKeeper(uint256 keeperId_)`.&#x20;

### Arguments

1. `uint256 keeperId_`:  the id of the keeper to disable

### Assertions

1. `_assertOnlyKeeperAdmin` ensures that only the keeper admin can disable a keeper
2. `_ensureCanReleaseKeeper` asserts that the keeper to be disabled is not currently assigned to any pending job
3. It is also asserted that the keeper to be disabled is not already inactive.

After the checks are performed, the keeperId is removed from the `EnumerableSet.UintSet internal activeKeepers` where all active keepers are stored, and the keeper (stored in the mapping `mapping(uint256 => Keeper) internal keepers` at the index of `keeperId`) has its activation status set to `False`.&#x20;

### Keeper disabling event

Having disabled the specified keeper, the function emits the event `DisableKeeper(keeperId_)`

## Activating the keeper

Keeper activation is done with a delay, much like the CVP token withdrawal. This is done to curb the possibility of the active keeper pool oscillating violently.&#x20;

### Initialising

When the admin of an inactive keeper deems it fit to reactivate the keeper once again, he invokes the function `initiateKeeperActivation(uint256 keeperId_)`.&#x20;

#### Arguments

1. `uint256 keeperId_`:  the id of the keeper to activate

#### Assertions

1. `_assertOnlyKeeperAdmin` ensures that only the keeper admin may invoke this function
2. An additional assertion is made, checking that the keeper with this ID is not active already.

When all assertions have been satisfied, the finalisation time `uint256 canBeFinalizedAt` is calculated by adding to the current block timestamp the keeper activation finalisation delay in hours `uint8 keeperActivationTimeoutHours`. This variable is a parameter of the instance of PPAgentV2RANDAO and is set by the agent owner. It can never exceed 255 hours due to the datatype employed.  The calculated finalisation time is stored in the mapping `mapping(uint256 => uint256) public keeperActivationCanBeFinalizedAt`, with the key being the `keeperId`.&#x20;

#### Activation initialisation event

Having computed and stored the activation time, the function emits the event `InitiateKeeperActivation(keeperId_, canBeFinalizedAt)`.

### Finalising

When the admin of an inactive keeper, having initialised the activation process before, desires to finalise it, he invokes the function `finalizeKeeperActivation(uint256 keeperId_)`.&#x20;

#### Arguments

1. `uint256 keeperId_`:  the id of the keeper to activate

#### Assertions

1. `_assertOnlyKeeperAdmin` ensures that only the keeper admin may invoke this function
2. An additional assertion is made, checking that the current block timestamp is not exceeded by the finalisation permission time, stored beforehand at activation initialisation in the mapping `mapping(uint256 => uint256) public keeperActivationCanBeFinalizedAt`, with the key being the `keeperId`.&#x20;

When all assertions have been satisfied, the `keeperId` is added back to the active keeper set `EnumerableSet.UintSet internal activeKeepers` whence it was removed at deactivation, the finalisation time stored in the mapping `mapping(uint256 => uint256) public keeperActivationCanBeFinalizedAt`, with the key being the `keeperId`, is zeroed, and the keeper stored in the mapping `mapping(uint256 => Keeper) internal keepers` at the index of `keeperId`) has its activation status set to `True`.

#### Activation finalisation event

Having reactivated the keeper, the function emits the event `FinalizeKeeperActivation(keeperId_)`.


---

# 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.powerpool.finance/powerpool-and-poweragent-network/power-agent/old-pages/keeper-old/keeper-staking-withdrawal-and-deactivation/keeper-activation-and-deactivation-in-ppagentv2randao.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.
