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

Contribution: Tokens Awarded Calculation Implemented both for Claims AND Referrals
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2021-06-13 19:00:35 -04:00
commit 187fcbdd45
6 files changed
+198 -87

No files matched your search

@@ -424,40 +424,9 @@
{
"type": "Pool",
"name": "User Referrals",
"config": "{\n \"description\": \"\"\n}",
"config": "{\n \"codeName\": \"User-Referrals\"\n}",
"project": "Governance",
"poolClasses": [
{
"type": "Pool Class",
"name": "Note: Increases when referrer uses the system",
"config": "{\n \"description\": \"\", \"relativeWeight\": 0 \n}",
"project": "Governance",
"poolClasses": [],
"pools": [],
"id": "f06bba01-2b98-4fd3-949a-7038b7f6e96a",
"savedPayload": {
"position": {
"x": 24323.080856734938,
"y": 31257.85618141008
},
"targetPosition": {
"x": 24511.87697404989,
"y": 31024.71239297299
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
}
],
"poolClasses": [],
"pools": [],
"id": "639a6504-a0d0-4d7e-ad99-80ba5115ac72",
"savedPayload": {
@@ -218,8 +218,8 @@
"id": "ab4d6901-a84c-44d3-a97a-7bc14de9ff31",
"savedPayload": {
"position": {
"x": 24963.166666666664,
"y": 24097.33110373638
"x": 25113.166666666664,
"y": 23837.523482601046
},
"targetPosition": {
"x": 24813.166666666664,
@@ -240,6 +240,37 @@
"id": "a2bb4366-f480-4685-80b0-e40af9cddd8c"
}
}
},
{
"type": "Position Claim Vote",
"name": "Luis-Fernando-Molina Project Leader Superalgos",
"config": "{}",
"project": "Governance",
"id": "2248b955-af4b-42e6-9649-9b6a689d0ade",
"savedPayload": {
"position": {
"x": 24663.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": "be2aedec-06fd-41fa-8599-08105931f75f"
}
}
}
],
"assetClaimVotes": [],
@@ -1242,7 +1242,7 @@
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"isCollapsed": true,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
@@ -1273,12 +1273,12 @@
"id": "4bef0dea-763d-4cfe-b56d-37b6d3ff4640",
"savedPayload": {
"position": {
"x": 28446.384757729335,
"y": 23659.80762113533
"x": 28429.384757729335,
"y": 23648.80762113533
},
"targetPosition": {
"x": 28446.384757729335,
"y": 23359.80762113533
"x": 28429.384757729335,
"y": 23348.80762113533
},
"floatingObject": {
"isPinned": false,
@@ -1304,12 +1304,12 @@
"id": "a5d807f5-7aa0-4251-915b-13c24367fea9",
"savedPayload": {
"position": {
"x": 28186.577136594,
"y": 23509.80762113533
"x": 28169.577136594,
"y": 23498.80762113533
},
"targetPosition": {
"x": 28446.384757729335,
"y": 23359.80762113533
"x": 28429.384757729335,
"y": 23348.80762113533
},
"floatingObject": {
"isPinned": false,
@@ -1334,12 +1334,12 @@
"id": "7e160d0d-8b89-483c-88a3-6faab8af137f",
"savedPayload": {
"position": {
"x": 28446.384757729335,
"y": 23359.80762113533
"x": 28429.384757729335,
"y": 23348.80762113533
},
"targetPosition": {
"x": 28596.384757729335,
"y": 23099.999999999996
"x": 28579.384757729335,
"y": 23088.999999999996
},
"floatingObject": {
"isPinned": false,
@@ -1369,12 +1369,12 @@
"id": "98ac1d12-c38e-4b51-8d60-e489305cfc53",
"savedPayload": {
"position": {
"x": 27996.384757729335,
"y": 23099.999999999996
"x": 27979.384757729335,
"y": 23088.999999999996
},
"targetPosition": {
"x": 28296.384757729335,
"y": 23099.999999999996
"x": 28279.384757729335,
"y": 23088.999999999996
},
"floatingObject": {
"isPinned": false,
@@ -1399,12 +1399,12 @@
"id": "81fd5407-d0b1-4ea0-86a0-a88b51d9dfcf",
"savedPayload": {
"position": {
"x": 28296.384757729335,
"y": 23099.999999999996
"x": 28279.384757729335,
"y": 23088.999999999996
},
"targetPosition": {
"x": 28596.384757729335,
"y": 23099.999999999996
"x": 28579.384757729335,
"y": 23088.999999999996
},
"floatingObject": {
"isPinned": false,
@@ -1437,7 +1437,7 @@
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"isCollapsed": true,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
@@ -1456,7 +1456,7 @@
{
"type": "Weight Votes Switch",
"name": "Users Pool Class",
"config": "{}",
"config": "{\n \"percentage\": 50\n}",
"project": "Governance",
"weightVotesSwitch": [],
"poolWeightVotes": [
@@ -2146,7 +2146,7 @@
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"isCollapsed": true,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
@@ -2211,7 +2211,7 @@
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"isCollapsed": true,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
@@ -2239,7 +2239,7 @@
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": true,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
@@ -33,13 +33,20 @@ function newGovernanceFunctionLibraryClaims() {
/* Claim Count Follows */
for (let i = 0; i < userProfiles.length; i++) {
let userProfilesNode = userProfiles[i]
if (userProfilesNode.payload === undefined) { continue }
userProfilesNode.payload.claims = {
awarded: {
tokens: 0
},
count: 0
}
countForNode(userProfilesNode.contributionClaims)
}
/* Claim Calculation Follows */
for (let i = 0; i < userProfiles.length; i++) {
let userProfilesNode = userProfiles[i]
calculateForNode(userProfilesNode.contributionClaims)
calculateForNode(userProfilesNode.contributionClaims, userProfilesNode)
}
}
@@ -99,6 +106,7 @@ function newGovernanceFunctionLibraryClaims() {
) {
if (node.payload.claims === undefined) {
node.payload.claims = {
count: 0,
awarded: {
tokens: 0,
percentage: 0
@@ -154,7 +162,7 @@ function newGovernanceFunctionLibraryClaims() {
}
}
function calculateForNode(node) {
function calculateForNode(node, userProfilesNode) {
if (node === undefined) { return }
if (node.payload === undefined) { return }
@@ -197,7 +205,10 @@ function newGovernanceFunctionLibraryClaims() {
)
node.payload.claims.awarded.percentage = node.payload.claims.awarded.tokens / node.payload.referenceParent.payload.tokens * 100
drawClaims(node)
userProfilesNode.payload.claims.awarded.tokens = userProfilesNode.payload.claims.awarded.tokens + node.payload.claims.awarded.tokens
userProfilesNode.payload.claims.count++
drawClaims(node, userProfilesNode)
}
}
@@ -210,7 +221,7 @@ function newGovernanceFunctionLibraryClaims() {
switch (property.type) {
case 'node': {
let childNode = node[property.name]
calculateForNode(childNode)
calculateForNode(childNode, userProfilesNode)
}
break
case 'array': {
@@ -218,7 +229,7 @@ function newGovernanceFunctionLibraryClaims() {
if (propertyArray !== undefined) {
for (let m = 0; m < propertyArray.length; m++) {
let childNode = propertyArray[m]
calculateForNode(childNode)
calculateForNode(childNode, userProfilesNode)
}
}
break
@@ -228,13 +239,20 @@ function newGovernanceFunctionLibraryClaims() {
}
}
function drawClaims(node) {
function drawClaims(node, userProfilesNode) {
let satatus =
new Intl.NumberFormat().format(node.payload.claims.awarded.tokens) +
' ' + 'SA Tokens Awarded' + ' - ' +
'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)
satatus = new Intl.NumberFormat().format(userProfilesNode.payload.claims.awarded.tokens) +
' ' + 'SA Tokens Awarded' +
' from ' + userProfilesNode.payload.claims.count + ' Claims'
userProfilesNode.payload.uiObject.setValue(satatus)
}
}
@@ -33,6 +33,7 @@ function newGovernanceFunctionLibraryDistributionProcess() {
)
UI.projects.governance.functionLibraries.userrReferrals.calculate(
pools,
userProfiles
)
@@ -6,10 +6,20 @@ function newGovernanceFunctionLibraryUserReferrals() {
return thisObject
function calculate(
pools,
userProfiles
) {
let tokensReward
let totalReferralsPower = 0
/* Scan Pools Until finding the User-Referrlas Pool */
for (let i = 0; i < pools.length; i++) {
let poolsNode = pools[i]
findPool(poolsNode)
}
if (tokensReward === undefined || tokensReward === 0) { return }
/*
We will first reset all the referral power, and then distribute it.
We will first reset all the referral combinedPower, and then distribute it.
*/
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
@@ -19,13 +29,68 @@ function newGovernanceFunctionLibraryUserReferrals() {
let userProfile = userProfiles[i]
distributeForProfile(userProfile)
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
calculateAwardedForProfile(userProfile)
}
function findPool(node) {
if (node === undefined) { return }
if (node.payload === undefined) { return }
/*
When we reach certain node types, we will halt the distribution, because these are targets for
voting combinedPower.
*/
if (
node.type === 'Pool'
) {
let codeName = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'codeName')
if (codeName === "User-Referrals") {
tokensReward = node.payload.tokens
return
}
}
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]
findPool(childNode)
}
break
case 'array': {
let propertyArray = node[property.name]
if (propertyArray !== undefined) {
for (let m = 0; m < propertyArray.length; m++) {
let childNode = propertyArray[m]
findPool(childNode)
}
}
break
}
}
}
}
}
function resetUserReferrals(node) {
if (node === undefined) { return }
if (node.payload === undefined) { return }
node.payload.referring = {
count: 0,
power: 0
combinedPower: 0,
ownPower: 0,
referralsPower: 0,
awarded: {
tokens: 0,
percentage: 0
}
}
/*
If the node is a User Profile, we will check if it has a User Referrer child defined.
@@ -38,7 +103,7 @@ function newGovernanceFunctionLibraryUserReferrals() {
return
}
/*
If there is a reference parent defined, this means that the referral power is
If there is a reference parent defined, this means that the referral combinedPower is
transfered to it.
*/
if (
@@ -51,8 +116,10 @@ function newGovernanceFunctionLibraryUserReferrals() {
}
function distributeForProfile(userProfile) {
if (userProfile === undefined || userProfile.payload === undefined) { return }
let referringPower = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(userProfile.payload, 'tokens')
let referringCount = 0
userProfile.payload.referring.ownPower = referringPower
distributeUserReferrals(userProfile, referringPower, referringCount)
}
@@ -60,15 +127,14 @@ function newGovernanceFunctionLibraryUserReferrals() {
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)
node.payload.referring.count = node.payload.referring.count + referringCount
node.payload.referring.combinedPower = node.payload.referring.combinedPower + referringPower
/*
If the node is a User Profile, we will check if it has a User Referrer child defined.
*/
totalReferralsPower = totalReferralsPower - node.payload.referring.referralsPower
node.payload.referring.referralsPower = node.payload.referring.combinedPower - node.payload.referring.ownPower
totalReferralsPower = totalReferralsPower + node.payload.referring.referralsPower
if (
node.userReferrer !== undefined &&
node.type === 'User Profile'
@@ -77,41 +143,67 @@ function newGovernanceFunctionLibraryUserReferrals() {
return
}
/*
If there is a reference parent defined, this means that the referral power is
If there is a reference parent defined, this means that the referral combinedPower is
transfered to it.
*/
if (
node.payload.referenceParent !== undefined &&
node.type === 'User Referrer'
) {
drawUserReferrals(node)
distributeUserReferrals(node.payload.referenceParent, referringPower / 10, 1)
return
}
}
function drawUserReferrals(node, count, power) {
const powerText = new Intl.NumberFormat().format(power) + ' ' + 'Referring Power'
function calculateAwardedForProfile(userProfile) {
let totalPowerRewardRation = tokensReward / totalReferralsPower
if (totalPowerRewardRation < 1) { totalPowerRewardRation = 1 }
userProfile.payload.referring.awarded.tokens = userProfile.payload.referring.referralsPower * totalPowerRewardRation
drawUserProfiles(userProfile)
}
function drawUserReferrals(node) {
if (node.payload !== undefined) {
const powerText = new Intl.NumberFormat().format(node.payload.referring.combinedPower)
node.payload.uiObject.valueAngleOffset = 0
node.payload.uiObject.valueAtAngle = false
node.payload.uiObject.setStatus(powerText + ' ' + 'Combined Referring Power')
return
}
}
function drawUserProfiles(node) {
if (node.payload !== undefined) {
const powerText = new Intl.NumberFormat().format(node.payload.referring.combinedPower)
const awardedTokens = new Intl.NumberFormat().format(node.payload.referring.awarded.tokens)
const referralPower = new Intl.NumberFormat().format(node.payload.referring.referralsPower)
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.referring.combinedPower >= 10000000
) {
node.payload.uiObject.setStatus(powerText + ' - ' + count + ' Referrals')
let status =
powerText + ' ' + 'Combined Referring Power' + ' - ' +
node.payload.referring.count + ' Referrals' + ' - ' +
referralPower + ' Referrals Power' + ' - ' +
awardedTokens + ' ' + 'SA Tokens Awarded'
node.payload.uiObject.setStatus(status)
return
} else {
node.payload.uiObject.setStatus('Define your referrer to collect tokens from your referrals.')
node.payload.referring.awarded.tokens = 0
node.payload.uiObject.setStatus(awardedTokens + ' SA Tokens not Awarded, because you have not defined your referrer yet.')
}
}
}