# RewardsPool
# Overview
The Rewards Pool using the Cobb-Douglas production function for PAYG and Open Agreement
# Pool
struct Pool {
uint256 totalStake;
uint256 totalReward;
uint256 unclaimTotalLabor;
uint256 unclaimReward;
mapping(address => uint256) stake;
mapping(address => uint256) labor;
}
# IndexerDeployment
struct IndexerDeployment {
uint256 unclaim;
bytes32[] deployments;
mapping(bytes32 => uint256) index;
}
# EraPool
struct EraPool {
uint256 unclaimDeployment;
mapping(address => struct RewardsPool.IndexerDeployment) indexerUnclaimDeployments;
mapping(bytes32 => struct RewardsPool.Pool) pools;
}
# STATES
# settings
Settings info
contract ISettings settings
# pools
Era Rewards Pools: era => Era Pool
mapping(uint256 => struct RewardsPool.EraPool) pools
# alphaNumerator
the numerator of Percentage of the stake and labor (1-alpha) in the total
int32 alphaNumerator
# alphaDenominator
the denominator of the alpha
int32 alphaDenominator
# EVENTS
# Alpha
Emitted when update the alpha for cobb-douglas function
event Alpha(int32 alphaNumerator, int32 alphaDenominator)
# Labor
Emitted when add Labor(reward) for current era pool
event Labor(bytes32 deploymentId, address indexer, uint256 amount, uint256 total)
# Collect
Emitted when collect reward (stake) from era pool
event Collect(bytes32 deploymentId, address indexer, uint256 era, uint256 amount)
# FUNCTIONS
# initialize
Initialize the contract, setup the alphaNumerator, alphaDenominator
function initialize(contract ISettings _settings) external
Name | Type | Description |
---|---|---|
_settings | contract ISettings | settings contract address |
# setSettings
update the settings
function setSettings(contract ISettings _settings) external
Name | Type | Description |
---|---|---|
_settings | contract ISettings | settings contract address |
# setAlpha
Update the alpha for cobb-douglas function
function setAlpha(int32 _alphaNumerator, int32 _alphaDenominator) public
Name | Type | Description |
---|---|---|
_alphaNumerator | int32 | the numerator of the alpha |
_alphaDenominator | int32 | the denominator of the alpha |
# getReward
get the Pool reward by deploymentId, era and indexer. returns my labor and total reward
function getReward(bytes32 deploymentId, uint256 era, address indexer) public view returns (uint256, uint256)
Name | Type | Description |
---|---|---|
deploymentId | bytes32 | deployment id |
era | uint256 | era number |
indexer | address | indexer address |
# labor
Add Labor(reward) for current era pool
function labor(bytes32 deploymentId, address indexer, uint256 amount) external
Name | Type | Description |
---|---|---|
deploymentId | bytes32 | deployment id |
indexer | address | indexer address |
amount | uint256 | the labor of services |
# collect
Collect reward (stake) from previous era Pool
function collect(bytes32 deploymentId, address indexer) external
Name | Type | Description |
---|---|---|
deploymentId | bytes32 | deployment id |
indexer | address | indexer address |
# batchCollect
Batch collect all deployments from previous era Pool
function batchCollect(address indexer) external
Name | Type | Description |
---|---|---|
indexer | address | indexer address |
# collectEra
Collect reward (stake) from era pool
function collectEra(uint256 era, bytes32 deploymentId, address indexer) external
Name | Type | Description |
---|---|---|
era | uint256 | era number |
deploymentId | bytes32 | deployment id |
indexer | address | indexer address |
# batchCollectEra
Batch collect all deployments in pool
function batchCollectEra(uint256 era, address indexer) external
Name | Type | Description |
---|---|---|
era | uint256 | era number |
indexer | address | indexer address |
# isClaimed
Determine is the pool claimed on the era
function isClaimed(uint256 era, address indexer) external view returns (bool)
Name | Type | Description |
---|---|---|
era | uint256 | era number |
indexer | address | indexer address |
Return: bool -> bool is claimed or not
# getUnclaimDeployments
Get unclaim deployments for the era
function getUnclaimDeployments(uint256 era, address indexer) external view returns (bytes32[])
Name | Type | Description |
---|---|---|
era | uint256 | era number |
indexer | address | indexer address |
Return: bytes32[] -> bytes32List list of deploymentIds
PRIVATE FUNCTIONS
# _batchCollect
work for batchCollect() and batchCollectEra()
function _batchCollect(uint256 era, address indexer) private
# _collect
work for collect() and collectEra()
function _collect(uint256 era, bytes32 deploymentId, address indexer) private
# _cobbDouglas
The cobb-doublas function has the form:
reward * feeRatio ^ alpha * stakeRatio ^ (1-alpha)
This is equivalent to:
reward * stakeRatio * e^(alpha * (ln(feeRatio / stakeRatio)))
However, because ln(x)
has the domain of 0 < x < 1
and exp(x)
has the domain of x < 0
,
and fixed-point math easily overflows with multiplication,
we will choose the following if stakeRatio > feeRatio
:
reward * stakeRatio / e^(alpha * (ln(stakeRatio / feeRatio)))
function _cobbDouglas(uint256 reward, uint256 myLabor, uint256 myStake, uint256 totalStake) private view returns (uint256)