Telescope In Depth

Calculating the "balanceIncrease"

The parameters of the function with which Telescope interacts with the Portal, are given below.
// Portal.sol
function reportOracle(
uint256 _reportedTimeStamp,
uint256 _planetId,
uint256[] memory _opIds,
uint256[] memory _pBalanceIncreases)
  • _reportedTimeStamp is the exact start time of daemon run on the Telescope.
  • _planetId is unique integer that indicates the corresponding representative.
  • _opIds is an array of unique integers that indicates the each node operator in the planet.
  • _pBalanceIncreases is the array of each total earnings of given operator array. The telescope's main task is to calculate this array.
Each pBank address can earn AVAX in 3 different ways:
  1. 1.
    By staking minimum 2000 AVAX for a validator.
  2. 2.
    By taking a fee from your validator's delegators.
  3. 3.
    By staking minimum 25 AVAX for a delegator.
The data is obtained from P-Chain api call have also startTime and endTime parameters which indicates the timestamp of when the staking will start and end. Telescope uses these parameters to estimate the reward amount in AVAX that the pBank earned by delegators and validators.
  • Being a Validator
// param: potentialReward is calculated by Avalance P-Chain
// param: profitSeconds is time difference between previous price update and
// the first second of the current update interval(day).
// param: totalInSeconds is difference between endTime - startTime for given validator
pureStaking = potentialReward * profitSeconds / totalInSeconds
  • By your Delegators
totalDelegatorReward is calculated for each validator by the iterative sum of each related delegators' potentialReward.
// param: totalDelegatorReward is calculated by Avalance P-Chain
// param: delegationFee is given by Avalance P-Chain specificly
// param: profitSeconds is time difference between previous run and next run.
// param: totalInSeconds is difference between endTime - startTime
// NOTE: we divide it to 100 because the delegationFee is a percentage
delegatorsProfit = (totalDelegatorReward * delegationFee *
profitSeconds / (totalInSeconds)) / 100
  • Being a Delegator
Each validator takes a pre-determined percentage which is called delegationFee of delegator's earning. Therefore, we multiply the reward by ( 100 - delegationFee / 100 ).
// param: potentialReward is given by Avalance P-Chain
// param: profitSeconds is time difference between previous price update and
// the first second of the current update interval(day).
// param: delegationFee is given by Avalance P-Chain
// param: totalInSeconds is difference between endTime - startTime
delegationProfit = (potentialReward * profitSeconds *
(100 - delegationFee)) / (totalInSeconds * 100)

Now, Telescope knows how much Pool gained from Staking Operations, rest is easy:

CurrentSystemBalance = EstimatedStakingRewards + TotalStakedBalance + pBankBalance + PlanetClaimableSurplus - PlanetUnclaimedFees

OldSystemBalance = TotalSupply * price

balanceIncrease = CurrentSystemBalance - OldSystemBalance

PlanetClaimableSurplus is a Portal function, returns how much Avax is waiting to be staked after gAvax is minted for the depositor of a given Planet's staking pool.
PlanetUnclaimedFees is the distributed fees that are yet not cliamed by the Planet Maintainers, resulting in "debt" for the system.

Finally,

Each daemon run can also be recorded to a MongoDB instance for monitoring purposes:
{
"_id" : {"$oid":"628ac06a2e256912c4d52b8e"},
"user" : "<username>",
"pbank" : "P-avax000000000000000000000000000000000000",
"balanceIncrease" : { "$numberLong" : "9338152653440664" },
"state" : { "$numberInt":"3" },
"height" : { "$numberInt":"1624453" },
"lastAPIcalltime" :
[ { "$numberInt" : "1653260378" },
"2022-05-23 01:59:38" ]}
In addition, it saves console outputs to logs folder and P-Chain data to jsonRecords folder to your local machine.
Copy link
On this page
Calculating the "balanceIncrease"
Now, Telescope knows how much Pool gained from Staking Operations, rest is easy:
balanceIncrease = CurrentSystemBalance - OldSystemBalance
Finally,