Ready to implement Claims
This commit is contained in:
1 parent
0514361d30
commit
f712e1ee70
5 files changed
+156
-36
No files matched your search
@@ -5,7 +5,127 @@ function newGovernanceFunctionLibraryClaims() {
|
||||
|
||||
return thisObject
|
||||
|
||||
function calculate() {
|
||||
function calculate(
|
||||
pools,
|
||||
features,
|
||||
assets,
|
||||
positions
|
||||
) {
|
||||
/* Claim Calculation Follows */
|
||||
for (let i = 0; i < assets.length; i++) {
|
||||
let assetsNode = assets[i]
|
||||
calculateForNode(assetsNode)
|
||||
}
|
||||
|
||||
/* Claim Calculation Follows */
|
||||
for (let i = 0; i < features.length; i++) {
|
||||
let featuresNode = features[i]
|
||||
calculateForNode(featuresNode)
|
||||
}
|
||||
|
||||
/* Claim Calculation Follows */
|
||||
for (let i = 0; i < positions.length; i++) {
|
||||
let positionsNode = positions[i]
|
||||
calculateForNode(positionsNode)
|
||||
}
|
||||
}
|
||||
|
||||
function calculateForNode(node) {
|
||||
|
||||
let totalVotes = 0
|
||||
countVotesAndResetClaims(node)
|
||||
applyClaimCalculation(node)
|
||||
|
||||
function countVotesAndResetClaims(node) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
|
||||
if (
|
||||
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.
|
||||
*/
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument === undefined) { return }
|
||||
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
let childNode = node[property.name]
|
||||
countVotesAndResetClaims(childNode)
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let propertyArray = node[property.name]
|
||||
if (propertyArray !== undefined) {
|
||||
for (let m = 0; m < propertyArray.length; m++) {
|
||||
let childNode = propertyArray[m]
|
||||
countVotesAndResetClaims(childNode)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function applyClaimCalculation(node) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
|
||||
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.
|
||||
*/
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument === undefined) { return }
|
||||
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
let childNode = node[property.name]
|
||||
applyClaimCalculation(childNode)
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let propertyArray = node[property.name]
|
||||
if (propertyArray !== undefined) {
|
||||
for (let m = 0; m < propertyArray.length; m++) {
|
||||
let childNode = propertyArray[m]
|
||||
applyClaimCalculation(childNode)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,13 @@ function newGovernanceFunctionLibraryDistributionProcess() {
|
||||
assets,
|
||||
positions
|
||||
)
|
||||
|
||||
/*
|
||||
UI.projects.governance.functionLibraries.claims.calculate(
|
||||
features,
|
||||
assets,
|
||||
positions
|
||||
)
|
||||
*/
|
||||
UI.projects.governance.functionLibraries.tokens.calculate(
|
||||
pools
|
||||
)
|
||||
|
||||
@@ -20,20 +20,20 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
|
||||
/* Reset Votes at Features */
|
||||
for (let i = 0; i < features.length; i++) {
|
||||
let feature = features[i]
|
||||
resetVotes(feature)
|
||||
let featuresNode = features[i]
|
||||
resetVotes(featuresNode)
|
||||
}
|
||||
|
||||
/* Reset Votes at Features */
|
||||
for (let i = 0; i < assets.length; i++) {
|
||||
let asset = assets[i]
|
||||
resetVotes(asset)
|
||||
let assetsNode = assets[i]
|
||||
resetVotes(assetsNode)
|
||||
}
|
||||
|
||||
/* Reset Votes at Features */
|
||||
for (let i = 0; i < positions.length; i++) {
|
||||
let position = positions[i]
|
||||
resetVotes(position)
|
||||
let positionsNode = positions[i]
|
||||
resetVotes(positionsNode)
|
||||
}
|
||||
/*
|
||||
We will first reset all the voting power, and then distribute it.
|
||||
@@ -44,20 +44,11 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
}
|
||||
for (let i = 0; i < userProfiles.length; i++) {
|
||||
let userProfile = userProfiles[i]
|
||||
distributeVotes(userProfile)
|
||||
distributeForProfile(userProfile)
|
||||
}
|
||||
}
|
||||
|
||||
function resetVotes(userProfile) {
|
||||
resetVotingPower(userProfile)
|
||||
}
|
||||
|
||||
function distributeVotes(userProfile) {
|
||||
let votes = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(userProfile.payload, 'tokens')
|
||||
distributeVotingPower(userProfile, votes)
|
||||
}
|
||||
|
||||
function resetVotingPower(node) {
|
||||
function resetVotes(node) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
node.payload.votes = 0
|
||||
@@ -66,7 +57,7 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
transfered to it and not distributed among children.
|
||||
*/
|
||||
if (node.payload.referenceParent !== undefined) {
|
||||
resetVotingPower(node.payload.referenceParent)
|
||||
resetVotes(node.payload.referenceParent)
|
||||
return
|
||||
}
|
||||
/*
|
||||
@@ -94,7 +85,7 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
case 'node': {
|
||||
if (node.type === 'User Profile' && property.name === "votesDistribution") {
|
||||
let childNode = node[property.name]
|
||||
resetVotingPower(childNode)
|
||||
resetVotes(childNode)
|
||||
}
|
||||
}
|
||||
break
|
||||
@@ -103,7 +94,7 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
if (propertyArray !== undefined) {
|
||||
for (let m = 0; m < propertyArray.length; m++) {
|
||||
let childNode = propertyArray[m]
|
||||
resetVotingPower(childNode)
|
||||
resetVotes(childNode)
|
||||
}
|
||||
}
|
||||
break
|
||||
@@ -113,11 +104,16 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
}
|
||||
}
|
||||
|
||||
function distributeVotingPower(node, votes, switchPercentage) {
|
||||
function distributeForProfile(userProfile) {
|
||||
let votes = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(userProfile.payload, 'tokens')
|
||||
distributeVotes(userProfile, votes)
|
||||
}
|
||||
|
||||
function distributeVotes(node, votes, switchPercentage) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
node.payload.votes = node.payload.votes + votes
|
||||
drawVotingPower(node, node.payload.votes, switchPercentage)
|
||||
drawVotes(node, node.payload.votes, switchPercentage)
|
||||
/*
|
||||
When we reach certain node types, we will halt the distribution, because thse are targets for
|
||||
voting power.
|
||||
@@ -136,7 +132,7 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
transfered to it and not distributed among children.
|
||||
*/
|
||||
if (node.payload.referenceParent !== undefined) {
|
||||
distributeVotingPower(node.payload.referenceParent, votes)
|
||||
distributeVotes(node.payload.referenceParent, votes)
|
||||
return
|
||||
}
|
||||
/*
|
||||
@@ -214,7 +210,7 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
if (percentage === undefined || isNaN(percentage) === true) {
|
||||
percentage = defaultPercentage
|
||||
}
|
||||
distributeVotingPower(childNode, votes * percentage / 100, percentage)
|
||||
distributeVotes(childNode, votes * percentage / 100, percentage)
|
||||
}
|
||||
}
|
||||
break
|
||||
@@ -227,7 +223,7 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
if (percentage === undefined || isNaN(percentage) === true) {
|
||||
percentage = defaultPercentage
|
||||
}
|
||||
distributeVotingPower(childNode, votes * percentage / 100, percentage)
|
||||
distributeVotes(childNode, votes * percentage / 100, percentage)
|
||||
}
|
||||
}
|
||||
break
|
||||
@@ -237,7 +233,7 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
}
|
||||
}
|
||||
|
||||
function drawVotingPower(node, votes, percentage) {
|
||||
function drawVotes(node, votes, percentage) {
|
||||
votes = new Intl.NumberFormat().format(votes) + ' ' + 'Votes'
|
||||
if (node.payload !== undefined) {
|
||||
if (node.type === 'User Profile') {
|
||||
|
||||
@@ -13,20 +13,20 @@ function newGovernanceFunctionLibraryWeights() {
|
||||
) {
|
||||
/* Weight Calculation Follows */
|
||||
for (let i = 0; i < assets.length; i++) {
|
||||
let asset = assets[i]
|
||||
calculateForNode(asset)
|
||||
let assetsNode = assets[i]
|
||||
calculateForNode(assetsNode)
|
||||
}
|
||||
|
||||
/* Weight Calculation Follows */
|
||||
for (let i = 0; i < features.length; i++) {
|
||||
let feature = features[i]
|
||||
calculateForNode(feature)
|
||||
let featuresNode = features[i]
|
||||
calculateForNode(featuresNode)
|
||||
}
|
||||
|
||||
/* Weight Calculation Follows */
|
||||
for (let i = 0; i < positions.length; i++) {
|
||||
let position = positions[i]
|
||||
calculateForNode(position)
|
||||
let positionsNode = positions[i]
|
||||
calculateForNode(positionsNode)
|
||||
}
|
||||
|
||||
/* Weight Calculation Follows */
|
||||
|
||||
@@ -36,8 +36,6 @@ function newGovernanceUserProfileSpace() {
|
||||
|
||||
function physics() {
|
||||
if (UI.projects.superalgos.spaces.designSpace.workspace === undefined) { return }
|
||||
|
||||
|
||||
}
|
||||
|
||||
function draw() {
|
||||
|
||||
Reference in new issue
Block a user