Skip to content

Commit

Permalink
remove default fee; start readme
Browse files Browse the repository at this point in the history
  • Loading branch information
timotejvesel committed Oct 12, 2023
1 parent 2116688 commit 6242f28
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,41 @@
# reward-scripts
# Staking Reward Script
For each reward epoch (every 3.5 days) script that calculates staking rewards will be run. Relevant data will be posted on this repository.

## The process

- Clone this repository
```bash
git checkout https://github.com/flare-foundation/reward-scripts.git
```
- Set up (network) configuration file `configs/networks/network_name.json`
- `NETWORK`: name of the network (e.g. `flare`). It should match the file name for the address configuration file `deploys/<NETWORK>.json` (e.g. [flare](deploys/flare.json))
- `RPC`: RPC URL for the network
- `MAX_BLOCKS_FOR_EVENT_READS`: how many blocks can be read with a single web3 API call (e.g. `getAllEvents`)
- `MAX_REQUESTS_PER_SECOND`: how many requests per second can be made
- `FIRST_REWARD_EPOCH`: first reward epoch for which rewards will be calculated
- `NUM_UNREWARDED_EPOCHS`: number of reward epochs to calculate rewards for
- `REQUIRED_FTSO_PERFORMANCE_WEI`: the amount of FTSO rewards that an FTSO provider needs to receive in a given epoch for its node to be eligible to receive staking rewards
- `BOOSTING_FACTOR`: factor of boosting eligibility bond (BEB) validator received as a boost
- `MIN_FOR_BEB_GWEI`: minimum total self-bond needed to be eligible to receive a boost
- `VOTE_POWER_CAP_BIPS`: percentage of the network's total stake amount node can have for rewarding
- `UPTIME_VOTING_PERIOD_LENGTH_SECONDS`: length of a period (starting at the given reward epoch) in which voters can cast a vote regarding nodes with high enough uptime
- `UPTIME_VOTING_THRESHOLD`: number of votes a node needs to receive to be eligible for a reward
- `API_PATH`: path to APIs which list active validators and delegators
- `REWARD_AMOUNT_EPOCH_WEI`: reward amount to distribute in a given reward epoch


If a configuration file doesn't exist or some parameters are missing, (those) parameters will have default values from [configuration service](./src/services/ConfigurationService.ts). If a default value is `undefined` it will be read from the blockchain.

- Install packages
```bash
yarn
````
- Run the calculating staking rewards process
```bash
yarn process-staking-rewards
```
You can also run it with optional parameters from [file](./src/processProviders.ts) (e.g. `yarn process-staking-rewards -b 8 -f 111`), which will override parameters set in the configuration file.

For each run output of the process is in folder `generated-files/reward-epochs-<FIRST_REWARD_EPOCH>_<LAST-REWARD_EPOCH>`, where `LAST-REWARD-EPOCH` is calculated as `<FIRST_REWARD_EPOCH> - <NUM_UNREWARDED_EPOCHS> + 1`.

To verify the official results posted in this repository one needs to update its configuration file with values from file `data.json`.
1 change: 0 additions & 1 deletion generated-files/reward-epochs-126-126/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@
"uptimeVotingPeriodLengthSeconds": 600,
"uptimeVotingThreshold": 3,
"minForBEBGwei": "1000000000000000",
"defaultFeePPM": 200000,
"firstRewardEpoch": 126,
"numUnrewardedEpochs": 1,
"rewardAmountEpochWei": "5179462900021549230386701",
Expand Down
4 changes: 1 addition & 3 deletions src/processStakingRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ let args = yargs
.option('rps', { alias: 'r', type: 'number', description: 'Request per second' })
.option('uptimeVotingThreshold', { alias: 't', type: 'number', description: 'Required number of votes for uptime to be considered high enough' })
.option('minForBEBGwei', { alias: 'm', type: 'string', description: 'Minimal amount (in gwei) of total self-bond to be eligible for boosting' })
.option('defaultFeePPM', { alias: 'd', type: 'number', description: 'Default fee (for group 1 nodes)' })
.option('rewardAmountEpochWei', { alias: 'a', type: 'string', description: 'Reward amount (in wei) to be distributed per reward epoch' })
.option('apiPath', { alias: 'y', type: 'string', description: 'Api for validators and delegators' })
.argv;
Expand All @@ -52,11 +51,10 @@ async function runProcessCalculateRewards() {
let rps = args['rps'] ? args['rps'] : configurationService.maxRequestsPerSecond;
let uptimeVotingThreshold = args['uptimeVotingThreshold'] ? args['uptimeVotingThreshold'] : configurationService.uptimeVotingThreshold;
let minForBEBGwei = args['minForBEBGwei'] ? args['minForBEBGwei'] : configurationService.minForBEBGwei;
let defaultFeePPM = args['defaultFeePPM'] ? args['defaultFeePPM'] : configurationService.defaultFeePPM;
let rewardAmountEpochWei = args['rewardAmountEpochWei'] ? args['rewardAmountEpochWei'] : configurationService.rewardAmountEpochWei;
let apiPath = args['apiPath'] ? args['apiPath'] : configurationService.apiPath;

await calculatingRewardsService.calculateRewards(firstRewardEpoch, requiredFtsoPerformanceWei, boostingFactor, votePowerCapBIPS, numUnrewardedEpochs, uptimeVotigPeriodLengthSeconds, rps, batchSize, uptimeVotingThreshold, minForBEBGwei, defaultFeePPM, rewardAmountEpochWei, apiPath);
await calculatingRewardsService.calculateRewards(firstRewardEpoch, requiredFtsoPerformanceWei, boostingFactor, votePowerCapBIPS, numUnrewardedEpochs, uptimeVotigPeriodLengthSeconds, rps, batchSize, uptimeVotingThreshold, minForBEBGwei,rewardAmountEpochWei, apiPath);
}

runProcessCalculateRewards()
Expand Down
9 changes: 4 additions & 5 deletions src/services/CalculatingRewardsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class CalculatingRewardsService {
return this.loggerService.logger;
}

public async calculateRewards(firstRewardEpoch: number, ftsoPerformanceForRewardWei: string, boostingFactor: number, votePowerCapBIPS: number, numUnrewardedEpochs: number, uptimeVotingPeriodLengthSeconds: number, rps: number, batchSize: number, uptimeVotingThreshold: number, minForBEBGwei: string, defaultFeePPM: number, rewardAmountEpochWei: string, apiPath: string) {
public async calculateRewards(firstRewardEpoch: number, ftsoPerformanceForRewardWei: string, boostingFactor: number, votePowerCapBIPS: number, numUnrewardedEpochs: number, uptimeVotingPeriodLengthSeconds: number, rps: number, batchSize: number, uptimeVotingThreshold: number, minForBEBGwei: string, rewardAmountEpochWei: string, apiPath: string) {
await this.contractService.waitForInitialization();
this.logger.info(`waiting for network connection...`);

Expand Down Expand Up @@ -110,7 +110,7 @@ export class CalculatingRewardsService {
let [eligible, ftsoAddress] = await this.isEligibleForReward(activeNode, eligibleNodesUptime, ftsoAddresses, ftsoRewardManager, epoch, ftsoPerformanceForRewardWei);

// decide to which group node belongs
let node = await this.nodeGroup(activeNode, ftsoAddress, boostingAddresses, pChainAddresses, defaultFeePPM);
let node = await this.nodeGroup(activeNode, ftsoAddress, boostingAddresses, pChainAddresses);
node.eligible = eligible;

if (node.group === 1) {
Expand Down Expand Up @@ -214,7 +214,6 @@ export class CalculatingRewardsService {
rewardsData.uptimeVotingPeriodLengthSeconds = uptimeVotingPeriodLengthSeconds;
rewardsData.uptimeVotingThreshold = uptimeVotingThreshold;
rewardsData.minForBEBGwei = minForBEBGwei;
rewardsData.defaultFeePPM = defaultFeePPM;
rewardsData.firstRewardEpoch = firstRewardEpoch;
rewardsData.numUnrewardedEpochs = numUnrewardedEpochs;
rewardsData.rewardAmountEpochWei = rewardAmount.toString();
Expand Down Expand Up @@ -354,7 +353,7 @@ export class CalculatingRewardsService {
return [BigInt(ftsoPerformance[0]) > BigInt(ftsoPerformanceForReward), ftsoObj.ftsoAddress];
}

public async nodeGroup(node: NodeData, ftsoAddress: string, boostingAddresses: string[], pChainAddresses: PAddressData[], defaultFee: number): Promise<ActiveNode> {
public async nodeGroup(node: NodeData, ftsoAddress: string, boostingAddresses: string[], pChainAddresses: PAddressData[]): Promise<ActiveNode> {
let nodeObj = {} as ActiveNode;
nodeObj.nodeId = node.nodeID;
nodeObj.bondingAddress = node.inputAddresses[0];
Expand All @@ -371,7 +370,7 @@ export class CalculatingRewardsService {
nodeObj.pChainAddress.push(obj.pChainAddress);
}
}
nodeObj.fee = defaultFee;
nodeObj.fee = 200000;
nodeObj.group = 1;
return nodeObj;
}
Expand Down
1 change: 0 additions & 1 deletion src/services/ConfigurationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export class ConfigurationService {
this.uptimeVotigPeriodLengthSeconds = configFile.UPTIME_VOTING_PERIOD_LENGTH_SECONDS ? configFile.UPTIME_VOTING_PERIOD_LENGTH_SECONDS : 600;
this.uptimeVotingThreshold = configFile.UPTIME_VOTING_THRESHOLD ? configFile.UPTIME_VOTING_THRESHOLD : undefined;
this.minForBEBGwei = configFile.MIN_FOR_BEB_GWEI ? configFile.MIN_FOR_BEB_GWEI : "1000000000000000";
this.defaultFeePPM = configFile.DEFAULT_FEE_PPM ? configFile.DEFAULT_FEE_PPM : 200000;
this.rewardAmountEpochWei = configFile.REWARD_AMOUNT_EPOCH_WEI ? configFile.REWARD_AMOUNT_EPOCH_WEI : undefined;
this.apiPath = configFile.API_PATH ? configFile.API_PATH : undefined;
}
Expand Down
1 change: 0 additions & 1 deletion src/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export interface INetworkConfigJson {
UPTIME_VOTING_PERIOD_LENGTH_SECONDS: number;
UPTIME_VOTING_THRESHOLD: number;
MIN_FOR_BEB_GWEI: string;
DEFAULT_FEE_PPM: number;
REWARD_AMOUNT_EPOCH_WEI: string;
API_PATH: string;
}

0 comments on commit 6242f28

Please sign in to comment.