From c07b8c5740baf1398f02acadc42b7c00b21626de Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 6 Jun 2021 04:24:02 +0200 Subject: [PATCH] token distribution and weight implemented --- .../UI/Function-Libraries/Weights.js | 26 ++++++++++++++++--- .../UI/Spaces/Assets-Space/Assets.js | 8 ++++++ .../Governance/UI/Spaces/Pools-Space/Pools.js | 11 ++++---- .../UI/Spaces/Positions-Space/Positions.js | 8 ++++++ 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/Projects/Governance/UI/Function-Libraries/Weights.js b/Projects/Governance/UI/Function-Libraries/Weights.js index 7841eb22d..e988f3097 100644 --- a/Projects/Governance/UI/Function-Libraries/Weights.js +++ b/Projects/Governance/UI/Function-Libraries/Weights.js @@ -14,9 +14,17 @@ function newGovernanceFunctionLibraryWeights() { if (node === undefined) { return } if (node.payload === undefined) { return } - if (node.payload.votes !== undefined) { - totalVotes = totalVotes + node.payload.votes + if ( + node.type !== 'Pool Class' && + node.type !== 'Asset Class' && + node.type !== 'Feature Class' && + node.type !== 'Position Class' + ) { + if (node.payload.votes !== undefined) { + totalVotes = totalVotes + node.payload.votes + } } + node.payload.weight = 0 /* Now we will count the voting power of this node's children. @@ -52,9 +60,19 @@ function newGovernanceFunctionLibraryWeights() { if (node === undefined) { return } if (node.payload === undefined) { return } - if (node.payload.votes !== undefined) { - node.payload.weight = node.payload.votes / totalVotes + if ( + node.type !== 'Pool Class' && + node.type !== 'Asset Class' && + node.type !== 'Feature Class' && + node.type !== 'Position Class' + ) { + if (node.payload.votes !== undefined) { + if (node.payload.votes !== undefined) { + node.payload.weight = node.payload.votes / totalVotes + } + } } + /* Now we will count the voting power of this node's children. */ diff --git a/Projects/Governance/UI/Spaces/Assets-Space/Assets.js b/Projects/Governance/UI/Spaces/Assets-Space/Assets.js index b67bb468f..b299efd07 100644 --- a/Projects/Governance/UI/Spaces/Assets-Space/Assets.js +++ b/Projects/Governance/UI/Spaces/Assets-Space/Assets.js @@ -25,7 +25,15 @@ function newGobernanceAssetsSpace() { } function physics() { + if (UI.projects.superalgos.spaces.designSpace.workspace === undefined) { return } + let assets = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('Assets') + + /* Weight Calculation Follows */ + for (let i = 0; i < assets.length; i++) { + let asset = assets[i] + UI.projects.governance.functionLibraries.weights.calculateWeights(asset) + } } function getContainer(point) { diff --git a/Projects/Governance/UI/Spaces/Pools-Space/Pools.js b/Projects/Governance/UI/Spaces/Pools-Space/Pools.js index c7941e35c..f861a0262 100644 --- a/Projects/Governance/UI/Spaces/Pools-Space/Pools.js +++ b/Projects/Governance/UI/Spaces/Pools-Space/Pools.js @@ -63,7 +63,7 @@ function newGovernancePoolsSpace() { function poolsDistribute(pools) { let tokenFlow = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(pools.payload, 'tokens') - distributeTokenFlow(pools, tokenFlow) + distributeTokens(pools, tokenFlow) } function resetTokenFlow(node) { @@ -119,7 +119,7 @@ function newGovernancePoolsSpace() { } } - function distributeTokenFlow(node, tokenFlow) { + function distributeTokens(node, tokenFlow) { if (node === undefined) { return } if (node.payload === undefined) { return } /* @@ -151,7 +151,7 @@ function newGovernancePoolsSpace() { transfered to it and not distributed among children. */ if (node.payload.referenceParent !== undefined) { - distributeTokenFlow(node.payload.referenceParent, tokenFlow) + distributeTokens(node.payload.referenceParent, node.payload.tokenFlow) return } /* @@ -163,7 +163,6 @@ function newGovernancePoolsSpace() { node.type === 'Feature' ) { return } - if (schemaDocument.childrenNodesProperties !== undefined) { for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) { let property = schemaDocument.childrenNodesProperties[i] @@ -172,7 +171,7 @@ function newGovernancePoolsSpace() { case 'node': { if (node.type === 'Pools' && property.name === "votesDistribution") { let childNode = node[property.name] - distributeTokenFlow(childNode, tokenFlow) + distributeTokens(childNode, tokenFlow) } } break @@ -181,7 +180,7 @@ function newGovernancePoolsSpace() { if (propertyArray !== undefined) { for (let m = 0; m < propertyArray.length; m++) { let childNode = propertyArray[m] - distributeTokenFlow(childNode, tokenFlow) + distributeTokens(childNode, tokenFlow) } } break diff --git a/Projects/Governance/UI/Spaces/Positions-Space/Positions.js b/Projects/Governance/UI/Spaces/Positions-Space/Positions.js index f6407b32c..91a45f5d6 100644 --- a/Projects/Governance/UI/Spaces/Positions-Space/Positions.js +++ b/Projects/Governance/UI/Spaces/Positions-Space/Positions.js @@ -27,7 +27,15 @@ function newGovernancePositionsSpace() { } function physics() { + if (UI.projects.superalgos.spaces.designSpace.workspace === undefined) { return } + let positions = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('Positions') + + /* Weight Calculation Follows */ + for (let i = 0; i < positions.length; i++) { + let position = positions[i] + UI.projects.governance.functionLibraries.weights.calculateWeights(position) + } } function getContainer(point) {