Agent (old)
The Agent is the key smart contract in the PowerAgent network
Overview
The PPAgentV2 (later The Agent) contract stores the state of the PowerAgent network. It includes the list of keepers, the logic of task execution, and keeper management. PPAgentV2 is an upgradeable descendant, direct or indirect, of PPAgentV2.sol
.
The Agent is responsible for the following operations:
Keeper Registration
To participate in the PowerAgent network, a keeper has to register in the system by calling the
registerAsKeeper
function and provide at least minimal CVP stake.Job Registration
The contract to be automated must be registered in The Agent. For this, the owner of the contract provides the address of the contract, and the configuration of the job, including the type, and tops up the job balance for keepers' reward.
Transaction xecution
To execute the task (once the conditions for execution are met), the keeper calls
execute
the Agent contract function. After a series of check-ups, the call is passed by The Agent to the Job contract and the task is executed, or in case of any errors, the execution will revert with a corresponding error.Job Update
Job owners can update the Job configuration at any time, for example, change the function of the contract to be executed, or update the conditions by which the contract should be executed. Each time a change is made, a Job with new id is created and attached to the same Job contract.
Slashing
The PowerAgent has the algorithm of punishment for malicious or negligent keepers. Various tasks can have different cost of no execution, and expensive tasks require stable and reliable execution. To prevent keepers from misbehavior, the slashing system is implemented in The Agent. If the execution of a task is failed (or not performed in time), the keeper is slashed for a certain portion of their CVP stake. This portion depends on the task specific minimal CVP stake and the cost of no execution.
Keeper Removal
Once a keeper wishes to quit participation in the PowerAgent network, they call the function
initiateRedeem
. A process of stake release is launched. After a cooldown period that is specified by the job parameters, the keeper can withdraw their CVP stake by invokingfinalizeRedeem
.
Specification
Internal constants
The Agent possesses the following internal (i.e., accessible to inheritors) constants:
//Capping of the maximum possible delay in fund withdrawal
uint256 MAX_PENDING_WITHDRAWAL_TIMEOUT_SECONDS = 30 days; //2_592_000 sec
//Capping the maximum fee in parts per million an Agent can set
uint256 MAX_FEE_PPM = 5e4;
//Multiplier for fixed (i.e. static) rewards
uint256 FIXED_PAYMENT_MULTIPLIER = 1e15;
Internal variables
The Agent possesses the following internal (i.e., accessible to inheritors) variables:
//Minimal acceptable CVP value for the keeper stake to have
uint256 minKeeperCvp;
//Minimal time interval between redeem initialization and redeem finalization
uint256 pendingWithdrawalTimeoutSeconds;
//The totality of fees the Agent has accrued thus far
uint256 feeTotal;
//Fee retained by the Agent for its services in parts per million
uint256 feePpm;
//The index of last keeper (having the meaning of the keeper pool size)
uint256 lastKeeperId;
Functions
Initialization
The Agent instance is initialized by an eponymous function initialize
which accepts the following arguments:
function initialize(
//Agent’s owner address
address owner;
//Minimal acceptable CVP value for the keeper stake to have
uint256 minKeeperCvp_;
//Minimal time interval between redeem initialization and redeem finalization
uint256 pendingWithdrawalTimeoutSeconds_;
)
This function sets the Agent’s configuration parameters and ownership to those specified.
Parameter update
Function setAgentParams
updates the configuration of the Agent. Appropriate parameters are capped by the corresponding internal constants.
function setAgentParams(
//Minimal acceptable CVP for the keeper to stake
uint256 minKeeperCvp_,
//The time a stake withdrawal must spend in a pending state
uint256 timeoutSeconds_,
//Fee retained by the Agent in parts per million
uint256 feePpm_
)
Fee withdrawal
The function withdrawFees
withdraws all fees the Agent has accrued to a specified address.
function withdrawFees(
//where to withdraw; needs to be payable to invoke transfer
address payable to_
) external {
//only Agent owner can call
_assertOnlyOwner();
//current accrued fees
uint256 amount = feeTotal;
//we withdraw all fees
feeTotal = 0;
//and transfer them to the specfieid address
to_.transfer(amount);
emit WithdrawFees(to_, amount);
}
Custom structures
The Agent contract contains custom data structures storing information about Keepers and Jobs.
Refer to the Keeper (Old) and Job (Old) pages for detailed description.
Last updated
Was this helpful?