From d345ee19a3be7620735ccefa7268ba4050f73417 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 23 Jun 2021 11:40:20 +0200 Subject: [PATCH 1/4] Governance Voting Program Improvements --- Projects/Governance/UI/Function-Libraries/ActionSwitch.js | 2 +- .../Governance/UI/Function-Libraries/DistributionProcess.js | 2 +- Projects/Governance/UI/Function-Libraries/Votes.js | 2 +- Projects/ProjectsSchema.json | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Projects/Governance/UI/Function-Libraries/ActionSwitch.js b/Projects/Governance/UI/Function-Libraries/ActionSwitch.js index 45fba9257..b9ac27c78 100644 --- a/Projects/Governance/UI/Function-Libraries/ActionSwitch.js +++ b/Projects/Governance/UI/Function-Libraries/ActionSwitch.js @@ -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': diff --git a/Projects/Governance/UI/Function-Libraries/DistributionProcess.js b/Projects/Governance/UI/Function-Libraries/DistributionProcess.js index b242d9a8d..c279ceab2 100644 --- a/Projects/Governance/UI/Function-Libraries/DistributionProcess.js +++ b/Projects/Governance/UI/Function-Libraries/DistributionProcess.js @@ -17,7 +17,7 @@ function newGovernanceFunctionLibraryDistributionProcess() { userProfiles ) - UI.projects.governance.functionLibraries.votes.calculate( + UI.projects.governance.functionLibraries.votingProgram.calculate( pools, features, assets, diff --git a/Projects/Governance/UI/Function-Libraries/Votes.js b/Projects/Governance/UI/Function-Libraries/Votes.js index 6c6b814b4..44b823711 100644 --- a/Projects/Governance/UI/Function-Libraries/Votes.js +++ b/Projects/Governance/UI/Function-Libraries/Votes.js @@ -1,4 +1,4 @@ -function newGovernanceFunctionLibraryVotes() { +function newGovernanceFunctionLibraryVotingProgram() { let thisObject = { calculate: calculate, installMissingVotes: installMissingVotes diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index 1a1301477..416eb29b3 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -969,9 +969,9 @@ "functionName": "newGovernanceFunctionLibraryTokenPower" }, { - "name": "Votes", - "propertyName": "votes", - "functionName": "newGovernanceFunctionLibraryVotes" + "name": "Voting Program", + "propertyName": "votingProgram", + "functionName": "newGovernanceFunctionLibraryVotingProgram" }, { "name": "Tokens", From c0cd4e18dc201175151fb8a09c1568594602252a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 23 Jun 2021 11:52:23 +0200 Subject: [PATCH 2/4] File Ranamed --- .../{Votes.js => VotingProgram.js} | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) rename Projects/Governance/UI/Function-Libraries/{Votes.js => VotingProgram.js} (97%) diff --git a/Projects/Governance/UI/Function-Libraries/Votes.js b/Projects/Governance/UI/Function-Libraries/VotingProgram.js similarity index 97% rename from Projects/Governance/UI/Function-Libraries/Votes.js rename to Projects/Governance/UI/Function-Libraries/VotingProgram.js index 44b823711..baee81886 100644 --- a/Projects/Governance/UI/Function-Libraries/Votes.js +++ b/Projects/Governance/UI/Function-Libraries/VotingProgram.js @@ -266,14 +266,11 @@ function newGovernanceFunctionLibraryVotingProgram() { } function drawVotes(node, votes, percentage) { - votes = parseFloat(votes.toFixed(2)).toLocaleString('en') + ' ' + 'Votes' + votes = parseFloat(votes.toFixed(2)).toLocaleString('en') + ' ' + 'Voting Power' 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)) @@ -310,6 +307,18 @@ function newGovernanceFunctionLibraryVotingProgram() { 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') + } + } } } From 4638b624b0125da9ddf7e42ca241741b71c9588a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 23 Jun 2021 12:15:12 +0200 Subject: [PATCH 3/4] 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 } } } From 2a2698d4ba5072e3a3335b5be88d3b7f8e8717d3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 23 Jun 2021 12:33:22 +0200 Subject: [PATCH 4/4] Labels Improved --- .../UI/Function-Libraries/Tokens.js | 2 +- .../UI/Function-Libraries/VotingProgram.js | 21 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Projects/Governance/UI/Function-Libraries/Tokens.js b/Projects/Governance/UI/Function-Libraries/Tokens.js index 805f56807..f8fca3438 100644 --- a/Projects/Governance/UI/Function-Libraries/Tokens.js +++ b/Projects/Governance/UI/Function-Libraries/Tokens.js @@ -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' diff --git a/Projects/Governance/UI/Function-Libraries/VotingProgram.js b/Projects/Governance/UI/Function-Libraries/VotingProgram.js index 52a40796e..fa8cfb53c 100644 --- a/Projects/Governance/UI/Function-Libraries/VotingProgram.js +++ b/Projects/Governance/UI/Function-Libraries/VotingProgram.js @@ -130,7 +130,7 @@ function newGovernanceFunctionLibraryVotingProgram() { function distributeProgram(programNode) { if (programNode.payload === undefined) { return } - + let votes = programNode.payload.votingProgram.votes programNode.payload.votingProgram.ownPower = votes distributeProgramPower(programNode, votes) @@ -270,7 +270,7 @@ function newGovernanceFunctionLibraryVotingProgram() { } function drawVotes(node, votes, percentage) { - votes = parseFloat(votes.toFixed(2)).toLocaleString('en') + ' ' + 'Voting Power' + if (node.payload !== undefined) { if (node.type === 'Voting Program') { @@ -304,8 +304,23 @@ function newGovernanceFunctionLibraryVotingProgram() { 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))