From 4638b624b0125da9ddf7e42ca241741b71c9588a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 23 Jun 2021 12:15:12 +0200 Subject: [PATCH] Governance: standarizing Voting program --- .../Docs-Concepts/C/Claim/Claim/claim.json | 2 +- .../UI/Function-Libraries/ClaimsProgram.js | 29 ++++++++++--------- .../UI/Function-Libraries/VotingProgram.js | 28 ++++++++++-------- .../UI/Function-Libraries/Weights.js | 10 +++---- 4 files changed, 37 insertions(+), 32 deletions(-) diff --git a/Projects/Governance/Schemas/Docs-Concepts/C/Claim/Claim/claim.json b/Projects/Governance/Schemas/Docs-Concepts/C/Claim/Claim/claim.json index 4ee202eac..a13490f27 100644 --- a/Projects/Governance/Schemas/Docs-Concepts/C/Claim/Claim/claim.json +++ b/Projects/Governance/Schemas/Docs-Concepts/C/Claim/Claim/claim.json @@ -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 }, { diff --git a/Projects/Governance/UI/Function-Libraries/ClaimsProgram.js b/Projects/Governance/UI/Function-Libraries/ClaimsProgram.js index 6efe7c6e1..17710622c 100644 --- a/Projects/Governance/UI/Function-Libraries/ClaimsProgram.js +++ b/Projects/Governance/UI/Function-Libraries/ClaimsProgram.js @@ -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 diff --git a/Projects/Governance/UI/Function-Libraries/VotingProgram.js b/Projects/Governance/UI/Function-Libraries/VotingProgram.js index baee81886..52a40796e 100644 --- a/Projects/Governance/UI/Function-Libraries/VotingProgram.js +++ b/Projects/Governance/UI/Function-Libraries/VotingProgram.js @@ -55,15 +55,17 @@ function newGovernanceFunctionLibraryVotingProgram() { 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 newGovernanceFunctionLibraryVotingProgram() { } } - 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. @@ -310,12 +314,12 @@ function newGovernanceFunctionLibraryVotingProgram() { 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') } } diff --git a/Projects/Governance/UI/Function-Libraries/Weights.js b/Projects/Governance/UI/Function-Libraries/Weights.js index a4dc6c2f1..9d04c8662 100644 --- a/Projects/Governance/UI/Function-Libraries/Weights.js +++ b/Projects/Governance/UI/Function-Libraries/Weights.js @@ -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 } } }