Merge pull request #1139 from Luis-Fernando-Molina/develop

Contribution: Governance: Referral Calculation Implemented
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2021-06-13 15:42:08 -04:00
commit f0cfec5386
11 files changed
+5810 -32

No files matched your search

-1
View File
@@ -1100,7 +1100,6 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
getAllFilesInDirectoryAndSubdirectories(folder, onFilesReady)
function onFilesReady(files) {
console.log(files)
respondWithContent(JSON.stringify(files), httpResponse)
}
}
File diff suppressed because it is too large. Load diff
@@ -1 +1,60 @@
{"type":"Positions","name":"Superalgos","project":"Governance","positionClasss":[],"positions":[{"type":"Position","name":"Project Leader","config":"{\n \"description\": \"\", \"relativeWeight\": 0 \n}","project":"Governance","positions":[],"positionClasss":[],"id":"5f694173-4568-46b2-a52c-4244320919f7","savedPayload":{"position":{"x":30231,"y":38070},"targetPosition":{"x":30231,"y":37770},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}}],"id":"50c68665-5da2-48a8-b229-7a1563ae82d2","savedPayload":{"position":{"x":30231,"y":37770},"targetPosition":{"x":30231,"y":37770},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":true,"angleToParent":1,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}}
{
"type": "Positions",
"name": "Superalgos",
"project": "Governance",
"positionClasss": [],
"positions": [
{
"type": "Position",
"name": "Project Leader",
"config": "{\n \"description\": \"\", \"relativeWeight\": 0 \n}",
"project": "Governance",
"positions": [],
"positionClasss": [],
"id": "5f694173-4568-46b2-a52c-4244320919f7",
"savedPayload": {
"position": {
"x": 30231,
"y": 38070
},
"targetPosition": {
"x": 30231,
"y": 37770
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
}
],
"id": "50c68665-5da2-48a8-b229-7a1563ae82d2",
"savedPayload": {
"position": {
"x": 30231,
"y": 37770
},
"targetPosition": {
"x": 30231,
"y": 37770
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": true,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
}
@@ -1 +1,439 @@
{"type":"User Profile","name":"Julian-Molina","config":"{\n \"codeName\": \"\",\n \"tokens\": 500000\n}","project":"Governance","contributionClaims":{"type":"Contribution Claims","name":"New Contribution Claims","config":"{}","project":"Governance","assetContributionsFolder":[{"type":"Asset Contributions Folder","name":"Tutorials","config":"{}","project":"Governance","assetContributionsFolder":[{"type":"Asset Contributions Folder","name":"Tutorials Created","config":"{}","project":"Governance","assetContributionsFolder":[],"assetContributionClaims":[{"type":"Asset Contribution Claim","name":"","config":"{\n \"description\": \"\"\n}","project":"Governance","id":"b62215fd-405b-4b81-a446-d667de2fd23b","savedPayload":{"position":{"x":26082.78190893733,"y":22758.100619195047},"targetPosition":{"x":25822.974287801997,"y":22908.100619195047},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":1,"distanceToParent":3,"arrangementStyle":0},"uiObject":{},"referenceParent":{"type":"Asset","name":"Getting Started Tutorial","id":"6c3f251e-cb80-42b7-935b-23bcbe218f97"}}}],"id":"30c01eef-80cf-4fb8-9231-af6694be0af9","savedPayload":{"position":{"x":25822.974287801997,"y":22908.100619195047},"targetPosition":{"x":25563.166666666664,"y":23058.100619195047},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}},{"type":"Asset Contributions Folder","name":"Tutorials Mantainance","config":"{}","project":"Governance","assetContributionsFolder":[],"assetContributionClaims":[{"type":"Asset Contribution Claim","name":"","config":"{\n \"description\": \"\"\n}","project":"Governance","id":"4a841aaa-0730-4783-91be-87d718ee4e15","savedPayload":{"position":{"x":26082.78190893733,"y":23358.100619195047},"targetPosition":{"x":25822.974287801997,"y":23208.100619195047},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{},"referenceParent":{"type":"Asset","name":"Getting Started Tutorial","id":"6c3f251e-cb80-42b7-935b-23bcbe218f97"}}}],"id":"03cd14ee-432e-4c7c-b2b0-79dc24d07820","savedPayload":{"position":{"x":25822.974287801997,"y":23208.100619195047},"targetPosition":{"x":25563.166666666664,"y":23058.100619195047},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":2,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}}],"assetContributionClaims":[],"id":"9318707a-afa0-4c84-8028-473eb448f96b","savedPayload":{"position":{"x":25563.166666666664,"y":23058.100619195047},"targetPosition":{"x":25263.166666666664,"y":23058.100619195047},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":1,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}}],"featureContributionsFolder":[],"positionContributionsFolder":[],"id":"43a4118b-fc68-46a9-a7d8-fa4baafa5ad6","savedPayload":{"position":{"x":25263.166666666664,"y":23058.100619195047},"targetPosition":{"x":24963.166666666664,"y":23058.100619195047},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":1,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}},"votesDistribution":{"type":"Votes Distribution","name":"New Votes Distribution","config":"{\n\"codeName\": \"\"\n}","project":"Governance","votesSwitch":[{"type":"Votes Switch","name":"Test","config":"{\n \"description\": \"\"\n}","project":"Governance","votesSwitch":[],"claimVotesSwitch":[],"weightVotesSwitch":[],"userProfileVotesSwitch":[],"id":"f4127f8b-eb94-4e5e-aea9-71ea43ba5b5b","savedPayload":{"position":{"x":24663.166666666664,"y":23577.715861465713},"targetPosition":{"x":24813.166666666664,"y":23317.90824033038},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":1,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}}],"id":"84b2e7e0-577a-4edc-98fd-003905decb99","savedPayload":{"position":{"x":24813.166666666664,"y":23317.90824033038},"targetPosition":{"x":24963.166666666664,"y":23058.100619195047},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":1,"distanceToParent":3,"arrangementStyle":0},"uiObject":{"isRunning":false}}},"userReferrer":{"type":"User Referrer","name":"","config":"{\n \"description\": \"\"\n}","project":"Governance","id":"edf7bcda-23f6-49bb-b9b2-9a34edcb4a40","savedPayload":{"position":{"x":24813.166666666664,"y":22798.292998059715},"targetPosition":{"x":24963.166666666664,"y":23058.100619195047},"floatingObject":{"isPinned":false,"isFrozen":false,"isCollapsed":false,"angleToParent":1,"distanceToParent":3,"arrangementStyle":0},"uiObject":{}}},"id":"1fd95e41-4b22-48d5-be3a-904c37afcb11","savedPayload":{"position":{"x":24963.166666666664,"y":23058.100619195047},"targetPosition":{"x":24963.166666666664,"y":23058.10061919Line truncated
{
"type": "User Profile",
"name": "Julian-Molina",
"config": "{\n \"codeName\": \"\",\n \"tokens\": 500000\n}",
"project": "Governance",
"contributionClaims": {
"type": "Contribution Claims",
"name": "New Contribution Claims",
"config": "{}",
"project": "Governance",
"assetContributionsFolder": [
{
"type": "Asset Contributions Folder",
"name": "Tutorials",
"config": "{}",
"project": "Governance",
"assetContributionsFolder": [
{
"type": "Asset Contributions Folder",
"name": "Tutorials Created",
"config": "{}",
"project": "Governance",
"assetContributionsFolder": [],
"assetContributionClaims": [
{
"type": "Asset Contribution Claim",
"name": "",
"config": "{\n \"description\": \"\"\n}",
"project": "Governance",
"id": "b62215fd-405b-4b81-a446-d667de2fd23b",
"savedPayload": {
"position": {
"x": 26082.78190893733,
"y": 22758.100619195047
},
"targetPosition": {
"x": 25822.974287801997,
"y": 22908.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {},
"referenceParent": {
"type": "Asset",
"name": "Getting Started Tutorial",
"id": "6c3f251e-cb80-42b7-935b-23bcbe218f97"
}
}
}
],
"id": "30c01eef-80cf-4fb8-9231-af6694be0af9",
"savedPayload": {
"position": {
"x": 25822.974287801997,
"y": 22908.100619195047
},
"targetPosition": {
"x": 25563.166666666664,
"y": 23058.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
},
{
"type": "Asset Contributions Folder",
"name": "Tutorials Mantainance",
"config": "{}",
"project": "Governance",
"assetContributionsFolder": [],
"assetContributionClaims": [
{
"type": "Asset Contribution Claim",
"name": "",
"config": "{\n \"description\": \"\"\n}",
"project": "Governance",
"id": "4a841aaa-0730-4783-91be-87d718ee4e15",
"savedPayload": {
"position": {
"x": 26082.78190893733,
"y": 23358.100619195047
},
"targetPosition": {
"x": 25822.974287801997,
"y": 23208.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {},
"referenceParent": {
"type": "Asset",
"name": "Getting Started Tutorial",
"id": "6c3f251e-cb80-42b7-935b-23bcbe218f97"
}
}
}
],
"id": "03cd14ee-432e-4c7c-b2b0-79dc24d07820",
"savedPayload": {
"position": {
"x": 25822.974287801997,
"y": 23208.100619195047
},
"targetPosition": {
"x": 25563.166666666664,
"y": 23058.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
}
],
"assetContributionClaims": [],
"id": "9318707a-afa0-4c84-8028-473eb448f96b",
"savedPayload": {
"position": {
"x": 25563.166666666664,
"y": 23058.100619195047
},
"targetPosition": {
"x": 25263.166666666664,
"y": 23058.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
}
],
"featureContributionsFolder": [],
"positionContributionsFolder": [],
"id": "43a4118b-fc68-46a9-a7d8-fa4baafa5ad6",
"savedPayload": {
"position": {
"x": 25263.166666666664,
"y": 23058.100619195047
},
"targetPosition": {
"x": 24963.166666666664,
"y": 23058.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
},
"votesDistribution": {
"type": "Votes Distribution",
"name": "New Votes Distribution",
"config": "{\n\"codeName\": \"\"\n}",
"project": "Governance",
"votesSwitch": [
{
"type": "Votes Switch",
"name": "Test",
"config": "{\n \"description\": \"\"\n}",
"project": "Governance",
"votesSwitch": [],
"claimVotesSwitch": [
{
"type": "Claim Votes Switch",
"name": "New Claim Votes Switch",
"config": "{}",
"project": "Governance",
"claimVotesSwitch": [],
"positionClaimVotes": [
{
"type": "Position Claim Vote",
"name": "Luis-Fernando-Molina Project Leader Superalgos",
"config": "{}",
"project": "Governance",
"id": "ab4d6901-a84c-44d3-a97a-7bc14de9ff31",
"savedPayload": {
"position": {
"x": 24963.166666666664,
"y": 24097.33110373638
},
"targetPosition": {
"x": 24813.166666666664,
"y": 23837.523482601046
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {},
"referenceParent": {
"type": "Position Contribution Claim",
"name": "Project Leader Superalgos",
"id": "a2bb4366-f480-4685-80b0-e40af9cddd8c"
}
}
}
],
"assetClaimVotes": [],
"featureClaimVotes": [],
"id": "6029fd9b-94b4-4b62-960a-14fb88107cdb",
"savedPayload": {
"position": {
"x": 24813.166666666664,
"y": 23837.523482601046
},
"targetPosition": {
"x": 24663.166666666664,
"y": 23577.715861465713
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
}
],
"weightVotesSwitch": [
{
"type": "Weight Votes Switch",
"name": "New Weight Votes Switch",
"config": "{}",
"project": "Governance",
"weightVotesSwitch": [],
"poolWeightVotes": [],
"assetWeightVotes": [],
"featureWeightVotes": [],
"positionWeightVotes": [
{
"type": "Position Weight Vote",
"name": "Superalgos Project Leader",
"config": "{}",
"project": "Governance",
"id": "11a8ac12-eba4-472d-b44b-8783720f8c6a",
"savedPayload": {
"position": {
"x": 24063.166666666664,
"y": 23577.715861465713
},
"targetPosition": {
"x": 24363.166666666664,
"y": 23577.715861465713
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {},
"referenceParent": {
"type": "Position",
"name": "Project Leader",
"id": "5f694173-4568-46b2-a52c-4244320919f7"
}
}
}
],
"id": "d98792e3-620f-4827-b17f-74096a2fe5c8",
"savedPayload": {
"position": {
"x": 24363.166666666664,
"y": 23577.715861465713
},
"targetPosition": {
"x": 24663.166666666664,
"y": 23577.715861465713
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
}
],
"userProfileVotesSwitch": [],
"id": "f4127f8b-eb94-4e5e-aea9-71ea43ba5b5b",
"savedPayload": {
"position": {
"x": 24663.166666666664,
"y": 23577.715861465713
},
"targetPosition": {
"x": 24813.166666666664,
"y": 23317.90824033038
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
}
],
"id": "84b2e7e0-577a-4edc-98fd-003905decb99",
"savedPayload": {
"position": {
"x": 24813.166666666664,
"y": 23317.90824033038
},
"targetPosition": {
"x": 24963.166666666664,
"y": 23058.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
},
"userReferrer": {
"type": "User Referrer",
"name": "Luis-Fernando-Molina",
"config": "{\n \"description\": \"\"\n}",
"project": "Governance",
"id": "edf7bcda-23f6-49bb-b9b2-9a34edcb4a40",
"savedPayload": {
"position": {
"x": 24813.166666666664,
"y": 22798.292998059715
},
"targetPosition": {
"x": 24963.166666666664,
"y": 23058.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {},
"referenceParent": {
"type": "User Profile",
"name": "Luis-Fernando-Molina",
"id": "148911b3-b2f3-44fb-8cb4-017991789132"
}
}
},
"id": "1fd95e41-4b22-48d5-be3a-904c37afcb11",
"savedPayload": {
"position": {
"x": 24963.166666666664,
"y": 23058.100619195047
},
"targetPosition": {
"x": 24963.166666666664,
"y": 23058.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": true,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
}
File diff suppressed because it is too large. Load diff
@@ -53,8 +53,10 @@ function newGovernanceFunctionLibraryClaims() {
node.type !== 'Position Class'
) {
if (node.payload.votes !== undefined) {
node.payload.claimsCount = 0
node.payload.claimsVotes = 0
node.payload.claims = {
count: 0,
votes: 0
}
}
}
@@ -95,6 +97,19 @@ function newGovernanceFunctionLibraryClaims() {
node.type !== 'Position Contributions Folder' &&
node.type !== 'Contribution Claims'
) {
if (node.payload.claims === undefined) {
node.payload.claims = {
awarded: {
tokens: 0,
percentage: 0
},
share: {
count: 0,
percentage: 0
}
}
}
if (
node.payload.votes !== undefined &&
node.payload.votes > 0 &&
@@ -104,11 +119,11 @@ function newGovernanceFunctionLibraryClaims() {
node.payload.referenceParent.payload.votes > 0 &&
node.payload.referenceParent.payload.weight !== undefined &&
node.payload.referenceParent.payload.weight > 0 &&
node.payload.referenceParent.payload.claimsCount !== undefined &&
node.payload.referenceParent.payload.claimsVotes !== undefined
node.payload.referenceParent.payload.claims.count !== undefined &&
node.payload.referenceParent.payload.claims.votes !== undefined
) {
node.payload.referenceParent.payload.claimsCount++
node.payload.referenceParent.payload.claimsVotes = node.payload.referenceParent.payload.claimsVotes + node.payload.votes
node.payload.referenceParent.payload.claims.count++
node.payload.referenceParent.payload.claims.votes = node.payload.referenceParent.payload.claims.votes + node.payload.votes
}
}
@@ -150,6 +165,7 @@ function newGovernanceFunctionLibraryClaims() {
node.type !== 'Contribution Claims'
) {
if (
node.payload.claims !== undefined &&
node.payload.votes !== undefined &&
node.payload.votes > 0 &&
node.payload.referenceParent !== undefined &&
@@ -158,25 +174,30 @@ function newGovernanceFunctionLibraryClaims() {
node.payload.referenceParent.payload.votes > 0 &&
node.payload.referenceParent.payload.weight !== undefined &&
node.payload.referenceParent.payload.weight > 0 &&
node.payload.referenceParent.payload.claimsCount !== undefined &&
node.payload.referenceParent.payload.claimsVotes !== undefined
node.payload.referenceParent.payload.claims.count !== undefined &&
node.payload.referenceParent.payload.claims.votes !== undefined
) {
/*
We will use the concept of Vote Ratio for the situation in which the total votes in claims exeeds the
amount of votes for wigthing. When this happen the Votes Ratio will be used to redude the amount of
tokens awarded proportionally to how much was exeeded.
We will use the concept of Vote Reward Claims Ratio for the situation in which the
total votes in claims exeeds the amount of votes of the reward. When this happens
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.claimsVotes
let votesRatio = node.payload.referenceParent.payload.votes / node.payload.referenceParent.payload.claims.votes
if (votesRatio > 1) { votesRatio = 1 }
/*
Share Count means the amount to claims pointing to the same potential tokens reward.
Share Count means the amount to claims pointing to the same potential tokens reward.
*/
let shareCount = node.payload.referenceParent.payload.claimsCount
let sharePercentage = node.payload.votes * 100 / node.payload.referenceParent.payload.claimsVotes
let awarded = node.payload.votes / node.payload.referenceParent.payload.votes * node.payload.referenceParent.payload.tokens * votesRatio
let awardedPercentage = node.payload.votes / node.payload.referenceParent.payload.votes * 100 * votesRatio
node.payload.claims.share.count = node.payload.referenceParent.payload.claims.count
node.payload.claims.share.percentage = node.payload.votes * 100 / node.payload.referenceParent.payload.claims.votes
node.payload.claims.awarded.tokens =
Math.min(
node.payload.votes / node.payload.referenceParent.payload.votes * node.payload.referenceParent.payload.tokens * votesRatio,
node.payload.votes
)
node.payload.claims.awarded.percentage = node.payload.claims.awarded.tokens / node.payload.referenceParent.payload.tokens * 100
drawClaims(node, shareCount, sharePercentage, awarded, awardedPercentage)
drawClaims(node)
}
}
@@ -207,13 +228,13 @@ function newGovernanceFunctionLibraryClaims() {
}
}
function drawClaims(node, shareCount, sharePercentage, awarded, awardedPercentage) {
function drawClaims(node) {
let satatus =
new Intl.NumberFormat().format(awarded) +
new Intl.NumberFormat().format(node.payload.claims.awarded.tokens) +
' ' + 'SA Tokens Awarded' + ' - ' +
'From Reward: ' + awardedPercentage.toFixed(2) + '%' + ' - ' +
'Shared Between: ' + shareCount + ' claims' + ' - ' +
'Share of Claims: ' + sharePercentage.toFixed(2) + '%'
'From Reward: ' + node.payload.claims.awarded.percentage.toFixed(2) + '%' + ' - ' +
'Shared Between: ' + node.payload.claims.share.count + ' claims' + ' - ' +
'Share of Claims: ' + node.payload.claims.share.percentage.toFixed(2) + '%'
node.payload.uiObject.setStatus(satatus)
}
}
@@ -31,6 +31,10 @@ function newGovernanceFunctionLibraryDistributionProcess() {
UI.projects.governance.functionLibraries.tokens.calculate(
pools
)
UI.projects.governance.functionLibraries.userrReferrals.calculate(
userProfiles
)
UI.projects.governance.functionLibraries.claims.calculate(
features,
@@ -52,7 +52,7 @@ function newGovernanceFunctionLibraryTokens() {
return
}
/*
When we reach certain node types, we will halt the distribution, because thse are targets for
When we reach certain node types, we will halt the distribution, because these are targets for
token flow.
*/
if (
@@ -0,0 +1,119 @@
function newGovernanceFunctionLibraryUserReferrals() {
let thisObject = {
calculate: calculate
}
return thisObject
function calculate(
userProfiles
) {
/*
We will first reset all the referral power, and then distribute it.
*/
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
resetUserReferrals(userProfile)
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
distributeForProfile(userProfile)
}
function resetUserReferrals(node) {
if (node === undefined) { return }
if (node.payload === undefined) { return }
node.payload.referring = {
count: 0,
power: 0
}
/*
If the node is a User Profile, we will check if it has a User Referrer child defined.
*/
if (
node.userReferrer !== undefined &&
node.type === 'User Profile'
) {
resetUserReferrals(node.userReferrer)
return
}
/*
If there is a reference parent defined, this means that the referral power is
transfered to it.
*/
if (
node.payload.referenceParent !== undefined &&
node.type === 'User Referrer'
) {
resetUserReferrals(node.payload.referenceParent)
return
}
}
function distributeForProfile(userProfile) {
let referringPower = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(userProfile.payload, 'tokens')
let referringCount = 0
distributeUserReferrals(userProfile, referringPower, referringCount)
}
function distributeUserReferrals(node, referringPower, referringCount) {
if (node === undefined) { return }
if (node.payload === undefined) { return }
node.payload.referring = {
count: node.payload.referring.count + referringCount,
power: node.payload.referring.power + referringPower
}
drawUserReferrals(node, node.payload.referring.count, node.payload.referring.power)
/*
If the node is a User Profile, we will check if it has a User Referrer child defined.
*/
if (
node.userReferrer !== undefined &&
node.type === 'User Profile'
) {
distributeUserReferrals(node.userReferrer, referringPower, 1, 0)
return
}
/*
If there is a reference parent defined, this means that the referral power is
transfered to it.
*/
if (
node.payload.referenceParent !== undefined &&
node.type === 'User Referrer'
) {
distributeUserReferrals(node.payload.referenceParent, referringPower / 10, 1)
return
}
}
function drawUserReferrals(node, count, power) {
const powerText = new Intl.NumberFormat().format(power) + ' ' + 'Referring Power'
if (node.payload !== undefined) {
node.payload.uiObject.valueAngleOffset = 0
node.payload.uiObject.valueAtAngle = false
if (node.type === 'User Referrer') {
node.payload.uiObject.setStatus(powerText)
return
}
if (
(node.type === 'User Profile' &&
node.userReferrer !== undefined &&
node.userReferrer.payload !== undefined &&
node.userReferrer.payload.referenceParent !== undefined)
||
power >= 10000000
) {
node.payload.uiObject.setStatus(powerText + ' - ' + count + ' Referrals')
return
} else {
node.payload.uiObject.setStatus('Define your referrer to collect tokens from your referrals.')
}
}
}
}
}
@@ -25,7 +25,7 @@ function newGovernanceFunctionLibraryVotes() {
resetVotes(featuresNode)
}
/* Reset Votes at Features */
/* Reset Votes at Assets */
for (let i = 0; i < assets.length; i++) {
let assetsNode = assets[i]
resetVotes(assetsNode)
@@ -53,7 +53,7 @@ function newGovernanceFunctionLibraryVotes() {
if (node.payload === undefined) { return }
node.payload.votes = 0
/*
When we reach certain node types, we will halt the distribution, because thse are targets for
When we reach certain node types, we will halt the distribution, because these are targets for
voting power.
*/
if (
@@ -125,7 +125,7 @@ function newGovernanceFunctionLibraryVotes() {
node.payload.votes = node.payload.votes + votes
drawVotes(node, node.payload.votes, switchPercentage)
/*
When we reach certain node types, we will halt the distribution, because thse are targets for
When we reach certain node types, we will halt the distribution, because these are targets for
voting power.
*/
if (
+5
View File
@@ -992,6 +992,11 @@
"name": "Plugins Functions",
"propertyName": "pluginsFunctions",
"functionName": "newGovernanceFunctionLibraryPluginsFunctions"
},
{
"name": "User Referrals",
"propertyName": "userrReferrals",
"functionName": "newGovernanceFunctionLibraryUserReferrals"
}
],
"utilities": [],