From 6242f28bfefebcb9070ff87275a7d4ff818973cd Mon Sep 17 00:00:00 2001 From: Timotej Vesel Date: Thu, 12 Oct 2023 14:55:02 +0200 Subject: [PATCH] remove default fee; start readme --- README.md | 42 ++++++++++++++++++- .../reward-epochs-126-126/data.json | 1 - src/processStakingRewards.ts | 4 +- src/services/CalculatingRewardsService.ts | 9 ++-- src/services/ConfigurationService.ts | 1 - src/utils/interfaces.ts | 1 - 6 files changed, 46 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4765186..74972fe 100644 --- a/README.md +++ b/README.md @@ -1 +1,41 @@ -# reward-scripts \ No newline at end of file +# 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/.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-_`, where `LAST-REWARD-EPOCH` is calculated as ` - + 1`. + +To verify the official results posted in this repository one needs to update its configuration file with values from file `data.json`. \ No newline at end of file diff --git a/generated-files/reward-epochs-126-126/data.json b/generated-files/reward-epochs-126-126/data.json index e55c8a2..33a4fac 100644 --- a/generated-files/reward-epochs-126-126/data.json +++ b/generated-files/reward-epochs-126-126/data.json @@ -242,7 +242,6 @@ "uptimeVotingPeriodLengthSeconds": 600, "uptimeVotingThreshold": 3, "minForBEBGwei": "1000000000000000", - "defaultFeePPM": 200000, "firstRewardEpoch": 126, "numUnrewardedEpochs": 1, "rewardAmountEpochWei": "5179462900021549230386701", diff --git a/src/processStakingRewards.ts b/src/processStakingRewards.ts index 194bf5e..ac9bee2 100644 --- a/src/processStakingRewards.ts +++ b/src/processStakingRewards.ts @@ -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; @@ -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() diff --git a/src/services/CalculatingRewardsService.ts b/src/services/CalculatingRewardsService.ts index b3850a6..b7e0dde 100644 --- a/src/services/CalculatingRewardsService.ts +++ b/src/services/CalculatingRewardsService.ts @@ -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...`); @@ -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) { @@ -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(); @@ -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 { + public async nodeGroup(node: NodeData, ftsoAddress: string, boostingAddresses: string[], pChainAddresses: PAddressData[]): Promise { let nodeObj = {} as ActiveNode; nodeObj.nodeId = node.nodeID; nodeObj.bondingAddress = node.inputAddresses[0]; @@ -371,7 +370,7 @@ export class CalculatingRewardsService { nodeObj.pChainAddress.push(obj.pChainAddress); } } - nodeObj.fee = defaultFee; + nodeObj.fee = 200000; nodeObj.group = 1; return nodeObj; } diff --git a/src/services/ConfigurationService.ts b/src/services/ConfigurationService.ts index 5fca176..89a6683 100644 --- a/src/services/ConfigurationService.ts +++ b/src/services/ConfigurationService.ts @@ -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; } diff --git a/src/utils/interfaces.ts b/src/utils/interfaces.ts index 6e8ee9f..cb3259a 100644 --- a/src/utils/interfaces.ts +++ b/src/utils/interfaces.ts @@ -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; }