forked from BIG-Labs/alliance-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
83 lines (64 loc) · 1.92 KB
/
test.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const SECONDS_IN_YEAR = 31_536_000;
const getLsdUsdValue = (data) => {
return data.totalLunaValueInUsd;
}
const getNativeUsdValue = (data) => {
return (data.tokenValue * parseInt(data.totalSupply) / 1_000_000);
}
const lsdLosePerYear = (row) => {
const usdStaked = getLsdUsdValue(row);
return usdStaked * getTakeRate(row);
}
const getTakeRate = (data) => {
return 1 - (1 - parseFloat(data.takeRate)) ** (SECONDS_IN_YEAR / parseInt(data.takeRateClaimInterval));
}
const annualRewardsToLunaStakers = (data) => {
const usdNative = getNativeUsdValue(data);
return (usdNative * data.inflation * (parseFloat(data.rewardWeight) / (1 + parseFloat(data.totalRewardWeight))));
}
const getAdditionalYield = (row) => {
const usdStaked = getLsdUsdValue(row);
return ((annualRewardsToLunaStakers(row) - lsdLosePerYear(row)) / usdStaked).toLocaleString('en-US');
}
const data = {
inflation: 0.04,
totalSupply: '1000000000000000',
rewardWeight: '0.01',
totalRewardWeight: '0.01',
tokenValue: 0.006
}
console.log(annualRewardsToLunaStakers(data));
const data1 = {
takeRate: '0.000000028581706446',
takeRateClaimInterval: 300
}
console.log(getTakeRate(data1));
const data3 = {
tokenValue: 0.006,
totalLunaValueInUsd: 13_363.23,
takeRate: '0.000000028581706446',
takeRateClaimInterval: 300
}
console.log(lsdLosePerYear(data3));
const final = {
inflation: 0.04,
totalSupply: '180801927220819786',
rewardWeight: '0.01',
totalRewardWeight: '0.02',
tokenValue: 0.005489635,
totalLunaValueInUsd: 16_292.65,
takeRate: '0.000000028581706446',
takeRateClaimInterval: 300
}
console.log(getAdditionalYield(final));
const finalMigaloo = {
inflation: 0.04,
totalSupply: '180801927220819786',
rewardWeight: '0.01',
totalRewardWeight: '0.02',
tokenValue: 0.005489635,
totalLunaValueInUsd: 21_264.5,
takeRate: '0.000000028581706446',
takeRateClaimInterval: 300
}
console.log(getAdditionalYield(finalMigaloo));