Merge pull request #1205 from Luis-Fernando-Molina/develop
Contribution: Governance Voting Program Improvements
This commit is contained in:
8 files changed
+71
-42
No files matched your search
@@ -54,7 +54,7 @@
|
||||
},
|
||||
{
|
||||
"style": "Javascript",
|
||||
"text": "/*\nWe will use the concept of Vote Ratio for the situation in which the total votes in claims exeeds the\namount of votes for wigthing. When this happen the Votes Ratio will be used to redude the amount of \ntokens awarded proportionally to how much was exeeded.\n*/\nlet votesRatio = node.payload.referenceParent.payload.votes / node.payload.referenceParent.payload.claimsVotes\nif (votesRatio > 1) { votesRatio = 1 }\n/*\n Share Count means the amount to claims pointing to the same potential tokens reward.\n*/\nlet shareCount = node.payload.referenceParent.payload.claimsCount\nlet sharePercentage = node.payload.votes * 100 / node.payload.referenceParent.payload.claimsVotes\nlet awarded = node.payload.votes / node.payload.referenceParent.payload.votes * node.payload.referenceParent.payload.tokens * votesRatio\nlet awardedPercentage = node.payload.votes / node.payload.referenceParent.payload.votes * 100 * votesRatio",
|
||||
"text": "/*\nWe will use the concept of Vote Ratio for the situation in which the total votes in claims exeeds the\namount of votes for wigthing. When this happen the Votes Ratio will be used to redude the amount of \ntokens awarded proportionally to how much was exeeded.\n*/\nlet votesRatio = node.payload.referenceParent.payload.votingProgram.votes / node.payload.referenceParent.payload.claimsVotes\nif (votesRatio > 1) { votesRatio = 1 }\n/*\n Share Count means the amount to claims pointing to the same potential tokens reward.\n*/\nlet shareCount = node.payload.referenceParent.payload.claimsCount\nlet sharePercentage = node.payload.votingProgram.votes * 100 / node.payload.referenceParent.payload.claimsVotes\nlet awarded = node.payload.votingProgram.votes / node.payload.referenceParent.payload.votingProgram.votes * node.payload.referenceParent.payload.tokens * votesRatio\nlet awardedPercentage = node.payload.votingProgram.votes / node.payload.referenceParent.payload.votingProgram.votes * 100 * votesRatio",
|
||||
"updated": 1623007674072
|
||||
},
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ function newGovernanceActionSwitch() {
|
||||
}
|
||||
case 'Install Missing Votes':
|
||||
{
|
||||
UI.projects.governance.functionLibraries.votes.installMissingVotes(action.node, action.rootNodes)
|
||||
UI.projects.governance.functionLibraries.votingProgram.installMissingVotes(action.node, action.rootNodes)
|
||||
break
|
||||
}
|
||||
case 'Install Missing Claims':
|
||||
|
||||
@@ -84,7 +84,7 @@ function newGovernanceFunctionLibraryClaimsProgram() {
|
||||
node.type !== 'Feature Class' &&
|
||||
node.type !== 'Position Class'
|
||||
) {
|
||||
if (node.payload.votes !== undefined) {
|
||||
if (node.payload.votingProgram.votes !== undefined) {
|
||||
node.payload.claimsProgram = {
|
||||
count: 0,
|
||||
votes: 0
|
||||
@@ -173,19 +173,20 @@ function newGovernanceFunctionLibraryClaimsProgram() {
|
||||
node.type !== 'Claims Program'
|
||||
) {
|
||||
if (
|
||||
node.payload.votes !== undefined &&
|
||||
node.payload.votes > 0 &&
|
||||
node.payload.votingProgram !== undefined &&
|
||||
node.payload.votingProgram.votes !== undefined &&
|
||||
node.payload.votingProgram.votes > 0 &&
|
||||
node.payload.referenceParent !== undefined &&
|
||||
node.payload.referenceParent.payload !== undefined &&
|
||||
node.payload.referenceParent.payload.votes !== undefined &&
|
||||
node.payload.referenceParent.payload.votes > 0 &&
|
||||
node.payload.referenceParent.payload.votingProgram.votes !== undefined &&
|
||||
node.payload.referenceParent.payload.votingProgram.votes > 0 &&
|
||||
node.payload.referenceParent.payload.weight !== undefined &&
|
||||
node.payload.referenceParent.payload.weight > 0 &&
|
||||
node.payload.referenceParent.payload.claimsProgram.count !== undefined &&
|
||||
node.payload.referenceParent.payload.claimsProgram.votes !== undefined
|
||||
) {
|
||||
node.payload.referenceParent.payload.claimsProgram.count++
|
||||
node.payload.referenceParent.payload.claimsProgram.votes = node.payload.referenceParent.payload.claimsProgram.votes + node.payload.votes
|
||||
node.payload.referenceParent.payload.claimsProgram.votes = node.payload.referenceParent.payload.claimsProgram.votes + node.payload.votingProgram.votes
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,12 +248,12 @@ function newGovernanceFunctionLibraryClaimsProgram() {
|
||||
) {
|
||||
if (
|
||||
node.payload.claimsProgram !== undefined &&
|
||||
node.payload.votes !== undefined &&
|
||||
node.payload.votes > 0 &&
|
||||
node.payload.votingProgram.votes !== undefined &&
|
||||
node.payload.votingProgram.votes > 0 &&
|
||||
node.payload.referenceParent !== undefined &&
|
||||
node.payload.referenceParent.payload !== undefined &&
|
||||
node.payload.referenceParent.payload.votes !== undefined &&
|
||||
node.payload.referenceParent.payload.votes > 0 &&
|
||||
node.payload.referenceParent.payload.votingProgram.votes !== undefined &&
|
||||
node.payload.referenceParent.payload.votingProgram.votes > 0 &&
|
||||
node.payload.referenceParent.payload.weight !== undefined &&
|
||||
node.payload.referenceParent.payload.weight > 0 &&
|
||||
node.payload.referenceParent.payload.claimsProgram.count !== undefined &&
|
||||
@@ -264,17 +265,17 @@ function newGovernanceFunctionLibraryClaimsProgram() {
|
||||
the Votes Rewards Claims Ratio will be used to redude the amount of tokens awarded
|
||||
proportionally to how much was exeeded.
|
||||
*/
|
||||
let votesRatio = node.payload.referenceParent.payload.votes / node.payload.referenceParent.payload.claimsProgram.votes
|
||||
let votesRatio = node.payload.referenceParent.payload.votingProgram.votes / node.payload.referenceParent.payload.claimsProgram.votes
|
||||
if (votesRatio > 1) { votesRatio = 1 }
|
||||
/*
|
||||
Share Count means the amount to claims pointing to the same potential tokens reward.
|
||||
*/
|
||||
node.payload.claimsProgram.share.count = node.payload.referenceParent.payload.claimsProgram.count
|
||||
node.payload.claimsProgram.share.percentage = node.payload.votes * 100 / node.payload.referenceParent.payload.claimsProgram.votes
|
||||
node.payload.claimsProgram.share.percentage = node.payload.votingProgram.votes * 100 / node.payload.referenceParent.payload.claimsProgram.votes
|
||||
node.payload.claimsProgram.awarded.tokens =
|
||||
Math.min(
|
||||
node.payload.votes / node.payload.referenceParent.payload.votes * node.payload.referenceParent.payload.tokens * votesRatio,
|
||||
node.payload.votes,
|
||||
node.payload.votingProgram.votes / node.payload.referenceParent.payload.votingProgram.votes * node.payload.referenceParent.payload.tokens * votesRatio,
|
||||
node.payload.votingProgram.votes,
|
||||
programPower
|
||||
)
|
||||
node.payload.claimsProgram.awarded.percentage = node.payload.claimsProgram.awarded.tokens / node.payload.referenceParent.payload.tokens * 100
|
||||
|
||||
@@ -17,7 +17,7 @@ function newGovernanceFunctionLibraryDistributionProcess() {
|
||||
userProfiles
|
||||
)
|
||||
|
||||
UI.projects.governance.functionLibraries.votes.calculate(
|
||||
UI.projects.governance.functionLibraries.votingProgram.calculate(
|
||||
pools,
|
||||
features,
|
||||
assets,
|
||||
|
||||
@@ -168,7 +168,7 @@ function newGovernanceFunctionLibraryTokens() {
|
||||
let status
|
||||
if (weight !== undefined && weight !== 0) {
|
||||
status = parseFloat(tokens.toFixed(2)).toLocaleString('en')
|
||||
+ ' ' + 'SA Tokens Reward' + ' - ' + 'Weight: ' + weight.toFixed(2)
|
||||
+ ' ' + 'SA Tokens Reward' + ' - ' + 'Weight: ' + (weight * 100).toFixed(2) + " %"
|
||||
} else {
|
||||
status = parseFloat(tokens.toFixed(2)).toLocaleString('en')
|
||||
+ ' ' + 'SA Tokens Reward'
|
||||
|
||||
+44
-16
@@ -1,4 +1,4 @@
|
||||
function newGovernanceFunctionLibraryVotes() {
|
||||
function newGovernanceFunctionLibraryVotingProgram() {
|
||||
let thisObject = {
|
||||
calculate: calculate,
|
||||
installMissingVotes: installMissingVotes
|
||||
@@ -55,15 +55,17 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
if (userProfile.tokenPowerSwitch.votingProgram === undefined) { continue }
|
||||
if (userProfile.tokenPowerSwitch.votingProgram.payload === undefined) { continue }
|
||||
|
||||
userProfile.tokenPowerSwitch.votingProgram.payload.votes = userProfile.tokenPowerSwitch.votingProgram.payload.tokenPower
|
||||
userProfile.tokenPowerSwitch.votingProgram.payload.votingProgram.votes = userProfile.tokenPowerSwitch.votingProgram.payload.tokenPower
|
||||
|
||||
distributeVotingProgram(userProfile.tokenPowerSwitch.votingProgram)
|
||||
distributeProgram(userProfile.tokenPowerSwitch.votingProgram)
|
||||
}
|
||||
|
||||
function resetVotes(node) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
node.payload.votes = 0
|
||||
node.payload.votingProgram = {
|
||||
votes: 0
|
||||
}
|
||||
/*
|
||||
When we reach certain node types, we will halt the distribution, because these are targets for
|
||||
voting power.
|
||||
@@ -126,17 +128,19 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
}
|
||||
}
|
||||
|
||||
function distributeVotingProgram(votingProgram) {
|
||||
if (votingProgram.payload === undefined) { return }
|
||||
let votes = votingProgram.payload.votes
|
||||
distributeProgramPower(votingProgram, votes)
|
||||
function distributeProgram(programNode) {
|
||||
if (programNode.payload === undefined) { return }
|
||||
|
||||
let votes = programNode.payload.votingProgram.votes
|
||||
programNode.payload.votingProgram.ownPower = votes
|
||||
distributeProgramPower(programNode, votes)
|
||||
}
|
||||
|
||||
function distributeProgramPower(node, votes, percentage) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
node.payload.votes = node.payload.votes + votes
|
||||
drawVotes(node, node.payload.votes, percentage)
|
||||
node.payload.votingProgram.votes = node.payload.votingProgram.votes + votes
|
||||
drawVotes(node, node.payload.votingProgram.votes, percentage)
|
||||
/*
|
||||
When we reach certain node types, we will halt the distribution, because these are targets for
|
||||
voting power.
|
||||
@@ -266,14 +270,11 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
}
|
||||
|
||||
function drawVotes(node, votes, percentage) {
|
||||
votes = parseFloat(votes.toFixed(2)).toLocaleString('en') + ' ' + 'Votes'
|
||||
|
||||
if (node.payload !== undefined) {
|
||||
|
||||
if (node.type === 'Voting Program') {
|
||||
node.payload.uiObject.statusAngleOffset = 0
|
||||
node.payload.uiObject.statusAtAngle = false
|
||||
|
||||
node.payload.uiObject.setStatus("Votes = Tokens Power")
|
||||
drawProgram(node)
|
||||
|
||||
if (percentage !== undefined) {
|
||||
node.payload.uiObject.setPercentage(percentage.toFixed(2))
|
||||
@@ -303,13 +304,40 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
node.payload.uiObject.percentageAngleOffset = 180
|
||||
node.payload.uiObject.percentageAtAngle = true
|
||||
}
|
||||
let voteType = 'Voting Power'
|
||||
|
||||
node.payload.uiObject.setValue(votes)
|
||||
if (
|
||||
node.type.indexOf('Weight') >= 0 ||
|
||||
node.type.indexOf('Pool') >= 0 ||
|
||||
node.type.indexOf('Feature') >= 0 ||
|
||||
node.type.indexOf('Asset') >= 0
|
||||
) {
|
||||
voteType = 'Weight Power'
|
||||
}
|
||||
|
||||
if (node.type.indexOf('Claim') >= 0) {
|
||||
voteType = 'Claim Support Power'
|
||||
}
|
||||
|
||||
const votesText = parseFloat(votes.toFixed(2)).toLocaleString('en') + ' ' + voteType
|
||||
node.payload.uiObject.setValue(votesText)
|
||||
|
||||
if (percentage !== undefined) {
|
||||
node.payload.uiObject.setPercentage(percentage.toFixed(2))
|
||||
}
|
||||
}
|
||||
|
||||
function drawProgram(node) {
|
||||
if (node.payload !== undefined) {
|
||||
|
||||
const ownPowerText = parseFloat(node.payload.votingProgram.ownPower.toFixed(2)).toLocaleString('en')
|
||||
|
||||
node.payload.uiObject.statusAngleOffset = 0
|
||||
node.payload.uiObject.statusAtAngle = false
|
||||
|
||||
node.payload.uiObject.setStatus(ownPowerText + ' Voting Power')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ function newGovernanceFunctionLibraryWeights() {
|
||||
node.payload.referenceParent !== undefined
|
||||
)
|
||||
) {
|
||||
if (node.payload.votes !== undefined) {
|
||||
totalVotes = totalVotes + node.payload.votes
|
||||
if (node.payload.votingProgram.votes !== undefined) {
|
||||
totalVotes = totalVotes + node.payload.votingProgram.votes
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,9 +114,9 @@ function newGovernanceFunctionLibraryWeights() {
|
||||
node.payload.referenceParent !== undefined
|
||||
)
|
||||
) {
|
||||
if (node.payload.votes !== undefined) {
|
||||
if (node.payload.votes !== undefined) {
|
||||
node.payload.weight = node.payload.votes / totalVotes
|
||||
if (node.payload.votingProgram.votes !== undefined) {
|
||||
if (node.payload.votingProgram.votes !== undefined) {
|
||||
node.payload.weight = node.payload.votingProgram.votes / totalVotes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -969,9 +969,9 @@
|
||||
"functionName": "newGovernanceFunctionLibraryTokenPower"
|
||||
},
|
||||
{
|
||||
"name": "Votes",
|
||||
"propertyName": "votes",
|
||||
"functionName": "newGovernanceFunctionLibraryVotes"
|
||||
"name": "Voting Program",
|
||||
"propertyName": "votingProgram",
|
||||
"functionName": "newGovernanceFunctionLibraryVotingProgram"
|
||||
},
|
||||
{
|
||||
"name": "Tokens",
|
||||
|
||||
Reference in new issue
Block a user