-
Notifications
You must be signed in to change notification settings - Fork 1
/
eth2.js
52 lines (40 loc) · 1.35 KB
/
eth2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const SECONDS_PER_YEAR = 60 * 60 * 24 * 365;
const SECONDS_PER_SLOT = 6;
const SLOTS_PER_EPOCH = 64;
const SECONDS_PER_EPOCH = SECONDS_PER_SLOT * SLOTS_PER_EPOCH;
const EPOCHS_PER_YEAR = SECONDS_PER_YEAR / SECONDS_PER_EPOCH;
function toGwei(eth) {
return eth * Math.pow(10, 9);
}
function numberOfValidators(numberOfShards, validatorsPerShard) {
return numberOfShards * validatorsPerShard;
}
function numberOfValidatorsByStake(networkStake, deposit) {
return Math.floor(networkStake / deposit);
}
function baseReward(deposit, baseRewardQuotient, networkStake, p) {
const adjustedQuotient = Math.floor(Math.pow(networkStake, p)) / baseRewardQuotient;
return deposit / adjustedQuotient / 5;
}
function issuancePerEpoch(numberOfValidators, baseReward) {
return numberOfValidators * baseReward;
}
function issuancePerYear(issuancePerEpoch) {
return EPOCHS_PER_YEAR * issuancePerEpoch;
}
function issuanceRate(issuancePerYear, ethInCirculation) {
return issuancePerYear / ethInCirculation * 100;
}
function validatorInterest(baseReward, deposit) {
return EPOCHS_PER_YEAR * baseReward / deposit * 100;
}
const eth2 = {
SECONDS_PER_YEAR: SECONDS_PER_YEAR,
toGwei: toGwei,
economics: {
numberOfValidators, numberOfValidatorsByStake, baseReward,
issuancePerEpoch, issuancePerYear,
issuanceRate, validatorInterest
}
};
module.exports = eth2;