Skip to content

Instantly share code, notes, and snippets.

@jafri
Last active July 27, 2019 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jafri/b3b99fad824b5e6ab221b0502776f881 to your computer and use it in GitHub Desktop.
Save jafri/b3b99fad824b5e6ab221b0502776f881 to your computer and use it in GitHub Desktop.
calculateVoteWeight () {
let decayWeeks = 13
let timestamp_epoch = 946684800000
let dates = (Date.now() / 1000) - (timestamp_epoch / 1000)
let weight = Math.floor(dates / (86400 * 7)) / decayWeeks
return Math.pow(2, weight)
}
async calculateVoteDecayPercentage (staked, last_vote_weight) {
let stake = staked / Math.pow(10, 8)
const lastVoteWeight = (last_vote_weight / calculateVoteWeight()) / Math.pow(10, 8)
return (lastVoteWeight / stake).toFixed(2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment