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/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/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/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/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/Votes.js b/Projects/Governance/UI/Function-Libraries/VotingProgram.js similarity index 91% rename from Projects/Governance/UI/Function-Libraries/Votes.js rename to Projects/Governance/UI/Function-Libraries/VotingProgram.js index 6c6b814b4..fa8cfb53c 100644 --- a/Projects/Governance/UI/Function-Libraries/Votes.js +++ b/Projects/Governance/UI/Function-Libraries/VotingProgram.js @@ -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') + } + } } } 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 } } } 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",