Members

(constant) LAMPORTS_PER_SOL

Important Notes on Delegation and Rewards:

  • Activation Epoch: The epoch when a delegation is activated.

  • Reward Beginning Epoch: Rewards start accruing one epoch after the Activation Epoch.

  • Withdrawal Implications: Upon withdrawal, the 'postBalance' will be less than the balance from the previous reward.

(constant) connectDB

Establishes a connection to the MongoDB using the provided configurations. Connection configurations are sourced from environment variables.

(constant) createDelegateTransaction

Create and persist a delegate transaction

(constant) cronHandles

Initialize and run essential services.

(constant) fetchLatestEpoch

Fetch the current epoch number from the Solana network.

(constant) fetchSolanaPriceAtDate

Fetch the Solana price at a specific date.

(constant) findAPRValue

Calculates and returns the APR value for a given delegator ID based on the rewards from the last month until the latestEpoch.

(constant) findDelegators

Fetches and returns active delegators for a given validator.

(constant) getAccountInfo

Get information about a specific account.

(constant) getBlockTime

Fetch the block time of a given effective slot.

(constant) getInflationReward

Fetch the inflation rewards of delegators for a specific epoch.

(constant) getProgramAccounts

Get the accounts associated with a given program.

(constant) getSignaturesForAddress

Fetch transaction signatures related to an address.

(constant) getTransaction

Fetch details of a transaction by its signature.

(constant) populateBody

Helper function to create a JSON-RPC request body.

(constant) populateSolUsd

Populate the solUsd field in all Reward model instances

(constant) setTimestampFormat

Sets the timestamp format to UTC 00:00:00.

Methods

convertSolUsd(amount, solUsd) → {Object}

Calculates the USD value of the post balance, reward, and staked amount.

Parameters:
NameTypeDescription
amountnumber

Amount to be converted to USD.

solUsdnumber

Current value of 1 SOL in USD.

Returns:
  • An object containing the USD values of the post balance, reward, and staked amount.
Type: 
Object

(async) delegatorCron()

Scheduled job to manage delegators.

(async) delegatorJob()

Job to create new delegators and update already populated ones.

(async) findRewards(delegatorId, epoch) → {Promise.<{reward: number, postBalance: number}>}

Fetches the inflation reward for a given delegatorId and epoch.

Parameters:
NameTypeDescription
delegatorIdstring

The public key of the delegator.

epochnumber

The epoch number.

Returns:

The reward and post balance.

Type: 
Promise.<{reward: number, postBalance: number}>

(async) findStakeInfo(pubkey) → {Promise.<({pubkey: string, activationEpoch: number, deactivationEpoch: number, stake: number}|undefined)>}

Fetches stake information for a given public key.

Parameters:
NameTypeDescription
pubkeystring

The public key to fetch stake info for.

Returns:

The stake information or undefined if not found.

Type: 
Promise.<({pubkey: string, activationEpoch: number, deactivationEpoch: number, stake: number}|undefined)>

(async) initializeRewardData(pubkey, delegatorReward, stakedAmount, solUsd) → {Object}

Initializes reward data for a delegator based on the reward amount and staked SOL.

Parameters:
NameTypeDescription
pubkeynumber

The public key of the delegator.

delegatorRewardRewardOfDelegation

The reward object containing the reward amount.

stakedAmountnumber

The amount staked in lamports.

solUsdnumber

Current value of 1 SOL in USD.

Returns:
  • An object containing initialized reward data, including total days, total reward, and pending rewards in both SOL and USD.
Type: 
Object

isRewardValidForEpoch(delegatorReward, epoch, activationEpoch, deactivationEpoch) → {boolean}

Checks if the reward is valid for the specified epoch based on activation and deactivation epochs.

Parameters:
NameTypeDescription
delegatorRewardRewardOfDelegation | null

The reward object containing information about the delegator's reward.

epochnumber

The current epoch number being evaluated.

activationEpochnumber

The epoch number when the delegator's stake was activated.

deactivationEpochnumber

The epoch number when the delegator's stake was deactivated.

Returns:
  • Returns true if the reward is valid for the specified epoch, otherwise false.
Type: 
boolean

(async) processDelegator()

Process individual delegator.

(async) processReward(rewards, epoch) → {Promise.<void>}

Processes reward information and stores it in the database.

Parameters:
NameTypeDescription
rewardsObject

The reward object containing information about rewards.

Properties
NameTypeDescription
effectiveSlotnumber

The effective slot number for the reward.

amountnumber

The amount of the reward in lamports.

postBalancenumber

The post balance in lamports after receiving the reward.

epochnumber

The epoch number for the reward.

epochnumber

The epoch number being processed.

Returns:

A promise that resolves once the reward has been processed.

Type: 
Promise.<void>

(async) processUnstaking()

Handle unstaking based on epoch conditions.

(async) rewardsCron() → {Object}

Initializes the function for rewards cron job.

Returns:
  • A schedule job to run every day at 1am.
Type: 
Object

(async) rewardsJob()

Job to populate rewards from the start epoch to the latest epoch for all delegators

(async) sleep(milliseconds) → {Promise.<void>}

Makes a delay for a given amount of time.

Parameters:
NameTypeDescription
millisecondsnumber

Time to delay in milliseconds.

Returns:
Type: 
Promise.<void>

(async) validatorRewardsCron() → {Object}

Initializes the function for rewards cron job.

Returns:
  • A schedule job to run every day at 1am.
Type: 
Object

(async) validatorRewardsJob()

Job to populate validator rewards from the start epoch to the latest epoch