Created
May 21, 2017 08:01
-
-
Save aaroncox/b94f49f831b9f0c984bac084d472fb8c to your computer and use it in GitHub Desktop.
steem-calc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Converts Steem Dollars to STEEM | |
var to_steem = function( sbd, feed_history ) { | |
return sbd / numberValue(feed_history.base); | |
}; | |
// Converts STEEM to Steem Dollars | |
var to_sbd = function( steem, feed_history ) { | |
return steem * numberValue(feed_history.base); | |
}; | |
// Calculates vshares from rshares | |
var calculate_vshares = function( rshares ) { | |
var s = 2000000000000; | |
return ( rshares + s ) * ( rshares + s ) - s * s; | |
}; | |
// | |
var claim_rshare_reward = function( state, rshares, reward_weight, max_steem ) { | |
var props = state.props, | |
rf = numberValue(props.total_reward_fund_steem), | |
total_rshares2 = parseInt(props.total_reward_shares2), | |
rs2 = calculate_vshares( rshares ), | |
payout, sbd_payout_value; | |
rs2 = ( rs2 * reward_weight ) / 100; | |
payout = ( rf * rs2 ) / total_rshares2; | |
sbd_payout_value = to_sbd( payout, state.feed_price ); | |
payout = Math.min( payout, max_steem ); | |
return payout; | |
}; | |
var pay_curators = function( comment, max_rewards ) { | |
var total_weight = comment.total_vote_weight, | |
unclaimed_rewards = max_rewards; | |
if(comment.total_vote_weight > 0 && comment.allow_curation_rewards) { | |
angular.forEach(comment.active_votes, function(vote, idx) { | |
var claim = ( max_rewards * vote.weight ) / total_weight; | |
if( claim > 0 ) { | |
comment.active_votes[idx]._claim = claim; | |
unclaimed_rewards -= claim; | |
} | |
console.log(vote, unclaimed_rewards, max_rewards); | |
}); | |
if( !comment.allow_curation_rewards ) { | |
props.total_reward_fund_steem += unclaimed_rewards; | |
unclaimed_rewards = 0; | |
} | |
} | |
return unclaimed_rewards; | |
}; | |
var numberValue = function(string) { | |
return parseFloat(string.split(" ")[0]); | |
}; | |
var cashout_comment_helper = function( state, comment ) { | |
if( comment.net_rshares > 0 ) { | |
var reward_tokens = claim_rshare_reward( | |
state, | |
parseInt(comment.net_rshares), | |
parseInt(comment.reward_weight), | |
to_steem( numberValue(comment.max_accepted_payout), state.feed_price ) | |
); | |
console.log(reward_tokens); | |
if( reward_tokens > 0 ) { | |
var sbd_steem, vesting_steem, author_tokens, | |
discussion_tokens = 0, | |
curation_tokens = ( reward_tokens * 25 ) / 100; | |
if( comment.parent_author.length === 0 ) { | |
discussion_tokens = ( reward_tokens * 75 ) / 100; | |
console.log(discussion_tokens) | |
author_tokens = reward_tokens - discussion_tokens - curation_tokens; | |
author_tokens += pay_curators( comment, curation_tokens ); | |
// author_tokens += pay_discussions( comment, discussion_tokens ); | |
// The amount of Steem Dollars to an author | |
sbd_steem = ( author_tokens * comment.percent_steem_dollars ) / ( 2 * 100 ); | |
// The amount vested to an author | |
vesting_steem = author_tokens - sbd_steem; | |
console.log(comment.title, author_tokens, sbd_steem, vesting_steem) | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment