-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathstats-sponsors-shares.js
70 lines (55 loc) · 2.54 KB
/
stats-sponsors-shares.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
import Sponsor from './server/models/sponsor.model';
import Stats from './server/models/stats.model';
import config from './config/config';
import steemApi from './server/steemAPI';
import * as R from 'ramda';
const mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
mongoose.connect(`${config.mongo.host}`);
const conn = mongoose.connection;
conn.once('open', function ()
{
const dedicatedPercentageSponsors = 20;
Sponsor.listAll()
.then(sponsors => {
if (sponsors.length > 0) {
let total_vesting_shares = 0;
sponsors.forEach(sponsor => total_vesting_shares = total_vesting_shares + sponsor.vesting_shares);
sponsors.forEach((sponsor, index) => {
steemApi.getVestingDelegations(sponsor.account, -1, 1000, function(err, delegations) {
Stats.get()
.then(stats => {
const isDelegating = R.find(R.propEq('delegatee', 'utopian-io'))(delegations);
if (isDelegating) {
const currentVestingShares = parseInt(isDelegating.vesting_shares);
const percentageTotalShares = (currentVestingShares / total_vesting_shares) * 100;
const total_paid_authors = stats.total_paid_authors;
const totalDedicatedSponsors = (total_paid_authors * dedicatedPercentageSponsors) / 100;
const shouldHaveReceivedRewards = (percentageTotalShares * totalDedicatedSponsors) / 100;
const total_paid_rewards = sponsor.total_paid_rewards;
if (shouldHaveReceivedRewards > total_paid_rewards) {
const mustReceiveRewards = shouldHaveReceivedRewards - total_paid_rewards;
sponsor.should_receive_rewards = mustReceiveRewards;
}
if (shouldHaveReceivedRewards < total_paid_rewards) {
const waitForNextRewards = 0;
sponsor.should_receive_rewards = waitForNextRewards;
}
sponsor.vesting_shares = currentVestingShares;
sponsor.percentage_total_vesting_shares = percentageTotalShares;
} else {
sponsor.vesting_shares = 0;
sponsor.percentage_total_vesting_shares = 0;
}
sponsor.save(savedSponsor => {
if ((index + 1) === sponsors.length) {
conn.close();
process.exit(0);
}
});
});
});
})
}
});
});