Merge pull request #1180 from Luis-Fernando-Molina/develop
Contribution: Governance: Mentorship Program Implementation
This commit is contained in:
5 files changed
+264
-98
No files matched your search
@@ -15,7 +15,7 @@
|
||||
"project": "Governance",
|
||||
"userReferrer": {
|
||||
"type": "User Referrer",
|
||||
"name": "",
|
||||
"name": "Jeremy",
|
||||
"config": "{}",
|
||||
"project": "Governance",
|
||||
"id": "0d0b04ff-034b-4b02-8351-67d621d514c0",
|
||||
@@ -82,7 +82,7 @@
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"isCollapsed": true,
|
||||
"angleToParent": 2,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
@@ -97,12 +97,69 @@
|
||||
"name": "New Mentorship Program",
|
||||
"config": "{}",
|
||||
"project": "Governance",
|
||||
"userMentors": [],
|
||||
"userMentors": [
|
||||
{
|
||||
"type": "User Mentor",
|
||||
"name": "Jeremy",
|
||||
"config": "{}",
|
||||
"project": "Governance",
|
||||
"id": "0e176a01-3ed2-4b02-b070-601236ea2393",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25662.630264392985,
|
||||
"y": 23874.32824727054
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25243.737077503094,
|
||||
"y": 23709.924786305663
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"angleToParent": 2,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
},
|
||||
"uiObject": {},
|
||||
"referenceParent": {
|
||||
"type": "User Profile",
|
||||
"name": "Jeremy",
|
||||
"id": "759e9012-c995-47ed-92f1-7d204bf2b58e"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"tokensAwarded": {
|
||||
"type": "Tokens Awarded",
|
||||
"name": "New Tokens Awarded",
|
||||
"project": "Governance",
|
||||
"id": "27f046ba-de7c-45a3-9086-d6f4e0ac0fd7",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25310.806097282373,
|
||||
"y": 24154.89865810697
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25243.737077503094,
|
||||
"y": 23709.924786305663
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"angleToParent": 2,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
},
|
||||
"uiObject": {}
|
||||
}
|
||||
},
|
||||
"id": "362a1ecb-dce9-4ebb-9b00-a20d3631f2f3",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25150.213607224283,
|
||||
"y": 23592.650063935456
|
||||
"x": 25243.737077503094,
|
||||
"y": 23709.924786305663
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 24963.166666666664,
|
||||
@@ -113,7 +170,7 @@
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"angleToParent": 2,
|
||||
"distanceToParent": 3,
|
||||
"distanceToParent": 4,
|
||||
"arrangementStyle": 0
|
||||
},
|
||||
"uiObject": {
|
||||
@@ -274,7 +331,7 @@
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": true,
|
||||
"isCollapsed": false,
|
||||
"angleToParent": 2,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"isCollapsed": true,
|
||||
"angleToParent": 1,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
@@ -97,7 +97,95 @@
|
||||
"name": "New Mentorship Program",
|
||||
"config": "{}",
|
||||
"project": "Governance",
|
||||
"userMentors": [],
|
||||
"userMentors": [
|
||||
{
|
||||
"type": "User Mentor",
|
||||
"name": "Julian-Molina",
|
||||
"config": "{}",
|
||||
"project": "Governance",
|
||||
"id": "97483d0f-35ec-4471-a981-0d22565e0d63",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 30862.495633423034,
|
||||
"y": 23307.14665723229
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 30608.478373654547,
|
||||
"y": 23466.75628018689
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"angleToParent": 2,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
},
|
||||
"uiObject": {},
|
||||
"referenceParent": {
|
||||
"type": "User Profile",
|
||||
"name": "Julian-Molina",
|
||||
"id": "1fd95e41-4b22-48d5-be3a-904c37afcb11"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "User Mentor",
|
||||
"name": "Jeremy",
|
||||
"config": "{}",
|
||||
"project": "Governance",
|
||||
"id": "8adecfda-c803-400c-acde-c34bda09e39b",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 30900.956747309094,
|
||||
"y": 23533.512560373787
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 30608.478373654547,
|
||||
"y": 23466.75628018689
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"angleToParent": 2,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
},
|
||||
"uiObject": {},
|
||||
"referenceParent": {
|
||||
"type": "User Profile",
|
||||
"name": "Jeremy",
|
||||
"id": "759e9012-c995-47ed-92f1-7d204bf2b58e"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"tokensAwarded": {
|
||||
"type": "Tokens Awarded",
|
||||
"name": "New Tokens Awarded",
|
||||
"project": "Governance",
|
||||
"id": "09648f99-1bf8-4d53-9d20-f15cc8c71508",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 30768.08799660915,
|
||||
"y": 23720.77353995538
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 30608.478373654547,
|
||||
"y": 23466.75628018689
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"angleToParent": 2,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
},
|
||||
"uiObject": {}
|
||||
}
|
||||
},
|
||||
"id": "8af4af68-62bf-4ad2-bf84-f1124cba0abf",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
@@ -401,7 +489,7 @@
|
||||
"poolWeightVotes": [
|
||||
{
|
||||
"type": "Pool Weight Vote",
|
||||
"name": "Usage Pool",
|
||||
"name": "Mentorship Program Pool",
|
||||
"config": "{}",
|
||||
"project": "Governance",
|
||||
"id": "a32cb176-83c0-4800-b630-01f1df6d2301",
|
||||
@@ -425,7 +513,7 @@
|
||||
"uiObject": {},
|
||||
"referenceParent": {
|
||||
"type": "Pool",
|
||||
"name": "Usage",
|
||||
"name": "Mentorship Program",
|
||||
"id": "60712b3c-ee76-40ba-8de2-e03aa61f6dde"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,11 @@ function newGovernanceFunctionLibraryDistributionProcess() {
|
||||
pools,
|
||||
userProfiles
|
||||
)
|
||||
|
||||
UI.projects.governance.functionLibraries.mentorshipProgram.calculate(
|
||||
pools,
|
||||
userProfiles
|
||||
)
|
||||
|
||||
UI.projects.governance.functionLibraries.claims.calculate(
|
||||
features,
|
||||
|
||||
@@ -26,7 +26,7 @@ function newGovernanceFunctionLibraryMentorshipProgram() {
|
||||
/* Scan Pools Until finding the Mentoship-Program Pool */
|
||||
for (let i = 0; i < pools.length; i++) {
|
||||
let poolsNode = pools[i]
|
||||
referralProgramPoolTokenReward = UI.projects.governance.utilities.pools.findPool(poolsNode, "Mentorship-Program")
|
||||
mentorshipProgramPoolTokenReward = UI.projects.governance.utilities.pools.findPool(poolsNode, "Mentorship-Program")
|
||||
}
|
||||
if (mentorshipProgramPoolTokenReward === undefined || mentorshipProgramPoolTokenReward === 0) { return }
|
||||
/*
|
||||
@@ -39,7 +39,7 @@ function newGovernanceFunctionLibraryMentorshipProgram() {
|
||||
if (userProfile.tokenSwitch.mentorshipProgram === undefined) { continue }
|
||||
if (userProfile.tokenSwitch.mentorshipProgram.payload === undefined) { continue }
|
||||
|
||||
resetUserMentorships(userProfile.tokenSwitch.mentorshipProgram)
|
||||
reserMentorshipProgram(userProfile.tokenSwitch.mentorshipProgram)
|
||||
}
|
||||
for (let i = 0; i < userProfiles.length; i++) {
|
||||
let userProfile = userProfiles[i]
|
||||
@@ -60,10 +60,10 @@ function newGovernanceFunctionLibraryMentorshipProgram() {
|
||||
calculateMentorshipProgram(userProfile.tokenSwitch.mentorshipProgram)
|
||||
}
|
||||
|
||||
function resetUserMentorships(node) {
|
||||
function reserMentorshipProgram(node) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
node.payload.mentorships = {
|
||||
node.payload.mentorshipProgram = {
|
||||
count: 0,
|
||||
outgoingPower: 0,
|
||||
ownPower: 0,
|
||||
@@ -73,36 +73,34 @@ function newGovernanceFunctionLibraryMentorshipProgram() {
|
||||
percentage: 0
|
||||
}
|
||||
}
|
||||
/*
|
||||
If the node is a User Profile, we will check if it has a User Referrer child defined.
|
||||
*/
|
||||
if (
|
||||
node.type === 'User Profile' &&
|
||||
node.tokenSwitch !== undefined &&
|
||||
node.tokenSwitch.mentorshipProgram !== undefined
|
||||
node.tokenSwitch !== undefined
|
||||
) {
|
||||
resetUserMentorships(node.tokenSwitch.mentorshipProgram)
|
||||
reserMentorshipProgram(node.tokenSwitch)
|
||||
return
|
||||
}
|
||||
if (
|
||||
node.type === 'Token Switch' &&
|
||||
node.mentorshipProgram !== undefined
|
||||
) {
|
||||
reserMentorshipProgram(node.mentorshipProgram)
|
||||
return
|
||||
}
|
||||
/*
|
||||
If the node is a Mentorship Program, we will check if it has a User Referrer child defined.
|
||||
*/
|
||||
if (
|
||||
node.type === 'Mentorship Program' &&
|
||||
node.userReferrer !== undefined
|
||||
node.userMentors !== undefined
|
||||
) {
|
||||
resetUserMentorships(node.userReferrer)
|
||||
for (let i = 0; i < node.userMentors.length; i++) {
|
||||
reserMentorshipProgram(node.userMentors[i])
|
||||
}
|
||||
return
|
||||
}
|
||||
/*
|
||||
If there is a reference parent defined, this means that the mentorship outgoingPower is
|
||||
transfered to it.
|
||||
*/
|
||||
if (
|
||||
node.type === 'User Referrer' &&
|
||||
node.type === 'User Mentor' &&
|
||||
node.payload.referenceParent !== undefined
|
||||
) {
|
||||
resetUserMentorships(node.payload.referenceParent)
|
||||
reserMentorshipProgram(node.payload.referenceParent)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -111,9 +109,9 @@ function newGovernanceFunctionLibraryMentorshipProgram() {
|
||||
if (mentorshipProgram === undefined || mentorshipProgram.payload === undefined) { return }
|
||||
/*
|
||||
Here we will convert Token Power into Mentorship Power.
|
||||
As per system rules referringPower = tokensPower
|
||||
As per system rules mentoshipPower = tokensPower
|
||||
*/
|
||||
let referringPower = mentorshipProgram.payload.tokenPower
|
||||
let mentoshipPower = mentorshipProgram.payload.tokenPower
|
||||
/*
|
||||
We will also reseet the count of mentorships here.
|
||||
*/
|
||||
@@ -121,19 +119,19 @@ function newGovernanceFunctionLibraryMentorshipProgram() {
|
||||
/*
|
||||
The Own Power is the power generated by the same User Profile tokens, not inherited from others.
|
||||
*/
|
||||
mentorshipProgram.payload.mentorships.ownPower = referringPower
|
||||
mentorshipProgram.payload.mentorshipProgram.ownPower = mentoshipPower
|
||||
|
||||
distributeMentorshipPower(mentorshipProgram, referringPower, count)
|
||||
distributeMentorshipPower(mentorshipProgram, mentoshipPower, count)
|
||||
}
|
||||
|
||||
function distributeMentorshipPower(
|
||||
node,
|
||||
referringPower,
|
||||
mentoshipPower,
|
||||
count
|
||||
) {
|
||||
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
if (node.payload.mentorshipProgram === undefined) { return }
|
||||
|
||||
switch (node.type) {
|
||||
case 'Mentorship Program': {
|
||||
@@ -142,18 +140,18 @@ function newGovernanceFunctionLibraryMentorshipProgram() {
|
||||
at the count parameters. If we are processing the User Profile of this Mentorship Program
|
||||
then we will add zero, otherwise, 1.
|
||||
*/
|
||||
node.payload.mentorships.count = node.payload.mentorships.count + count
|
||||
node.payload.mentorshipProgram.count = node.payload.mentorshipProgram.count + count
|
||||
/*
|
||||
The outgoingPower of this node will be accumulating all the referringPower flowing
|
||||
The outgoingPower of this node will be accumulating all the mentoshipPower flowing
|
||||
through it, no matter from where it comes.
|
||||
*/
|
||||
node.payload.mentorships.outgoingPower = node.payload.mentorships.outgoingPower + referringPower
|
||||
node.payload.mentorshipProgram.outgoingPower = node.payload.mentorshipProgram.outgoingPower + mentoshipPower
|
||||
/*
|
||||
We need to adjust the balance that holds the accumulationt of all incomingPower of all Mentorship Program
|
||||
nodes. To do this we will substratct the current incomingPower, bacause it is going to be recalculated
|
||||
inmediatelly after this, and then we will add it again after the recalcualtion.
|
||||
*/
|
||||
accumulatedIncomingMentorshipPower = accumulatedIncomingMentorshipPower - node.payload.mentorships.incomingPower
|
||||
accumulatedIncomingMentorshipPower = accumulatedIncomingMentorshipPower - node.payload.mentorshipProgram.incomingPower
|
||||
/*
|
||||
At any point in time, the incomingPower will be equal to the total of the outgoingPower minus
|
||||
the ownPower. This is like this because the outgoingPower is the accumulation of all the
|
||||
@@ -161,34 +159,38 @@ function newGovernanceFunctionLibraryMentorshipProgram() {
|
||||
substract the ownPower, we will have the accumulation of all the incomingPower, which
|
||||
means all the power coming from other User Profiles referencing this one.
|
||||
*/
|
||||
node.payload.mentorships.incomingPower = node.payload.mentorships.outgoingPower - node.payload.mentorships.ownPower
|
||||
node.payload.mentorshipProgram.incomingPower = node.payload.mentorshipProgram.outgoingPower - node.payload.mentorshipProgram.ownPower
|
||||
/*
|
||||
Now that we have the incomingPower calculated again, we can add it again to the balance of all the incomingPower
|
||||
of all Mentorship Program nodes.
|
||||
*/
|
||||
accumulatedIncomingMentorshipPower = accumulatedIncomingMentorshipPower + node.payload.mentorships.incomingPower
|
||||
accumulatedIncomingMentorshipPower = accumulatedIncomingMentorshipPower + node.payload.mentorshipProgram.incomingPower
|
||||
|
||||
if (node.userReferrer !== undefined) {
|
||||
distributeMentorshipPower(node.userReferrer, referringPower, 0)
|
||||
if (node.userMentors !== undefined) {
|
||||
for (let i = 0; i < node.userMentors.length; i++) {
|
||||
distributeMentorshipPower(node.userMentors[i], mentoshipPower / node.userMentors.length, 0)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'User Referrer': {
|
||||
drawUserReferrer(node)
|
||||
case 'User Mentor': {
|
||||
node.payload.mentorshipProgram.outgoingPower = node.payload.parentNode.payload.mentorshipProgram.outgoingPower / node.payload.parentNode.userMentors.length
|
||||
|
||||
drawUserMentor(node)
|
||||
if (node.payload.referenceParent !== undefined) {
|
||||
distributeMentorshipPower(node.payload.referenceParent, referringPower / 10, 0)
|
||||
distributeMentorshipPower(node.payload.referenceParent, mentoshipPower / 10, 0)
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'User Profile': {
|
||||
if (node.tokenSwitch !== undefined) {
|
||||
distributeMentorshipPower(node.tokenSwitch, referringPower, 0)
|
||||
distributeMentorshipPower(node.tokenSwitch, mentoshipPower, 0)
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'Token Switch': {
|
||||
if (node.mentorshipProgram !== undefined) {
|
||||
distributeMentorshipPower(node.mentorshipProgram, referringPower, 1)
|
||||
distributeMentorshipPower(node.mentorshipProgram, mentoshipPower, 1)
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -198,7 +200,7 @@ function newGovernanceFunctionLibraryMentorshipProgram() {
|
||||
function calculateMentorshipProgram(mentorshipProgram) {
|
||||
/*
|
||||
Here we will calculate which share of the Mentorship Program Pool this user will get in tokens.
|
||||
To do that, we use the incomingPower, to se which proportion of the accumulatedIncomingMentorshipPower
|
||||
To do that, we use the incomingPower, to see which proportion of the accumulatedIncomingMentorshipPower
|
||||
represents.
|
||||
*/
|
||||
if (mentorshipProgram.payload === undefined) { return }
|
||||
@@ -216,58 +218,73 @@ function newGovernanceFunctionLibraryMentorshipProgram() {
|
||||
mentorshipProgram.payload.uiObject.setErrorMessage("Tokens Awarded Node is needed in order for this Program to get Tokens from the Mentorship Program Pool.")
|
||||
return
|
||||
}
|
||||
mentorshipProgram.payload.mentorships.awarded.tokens = mentorshipProgram.payload.mentorships.incomingPower * totalPowerRewardRatio
|
||||
mentorshipProgram.payload.mentorshipProgram.awarded.tokens = mentorshipProgram.payload.mentorshipProgram.incomingPower * totalPowerRewardRatio
|
||||
/*
|
||||
As per the system rules, the Mentorship Program will not give tokens to users that do not ha their own Referrer set up,
|
||||
unless it has a big amount of tokens (this last condition is for the edge case where a user it at the top of the
|
||||
mentorship pyramid.)
|
||||
*/
|
||||
if (
|
||||
mentorshipProgram.payload.mentorships.ownPower < 1000000 &&
|
||||
(mentorshipProgram.userReferrer === undefined || mentorshipProgram.userReferrer.payload.referenceParent === undefined)
|
||||
mentorshipProgram.payload.mentorshipProgram.awarded.tokens > 0 &&
|
||||
mentorshipProgram.payload.mentorshipProgram.ownPower < 1000000 &&
|
||||
(mentorshipProgram.userMentors === undefined || hasUsersDefined(mentorshipProgram.userMentors) === false)
|
||||
) {
|
||||
|
||||
mentorshipProgram.payload.uiObject.setErrorMessage("In order to be awarded " + mentorshipProgram.payload.mentorships.awarded.tokens + " SA Tokens from your mentorships, you need first to define yourself who your referrer is.")
|
||||
mentorshipProgram.payload.mentorships.awarded.tokens = 0
|
||||
mentorshipProgram.payload.uiObject.setErrorMessage("In order to be awarded " + mentorshipProgram.payload.mentorshipProgram.awarded.tokens + " SA Tokens from your mentorships, you need first to define yourself who your metors are.")
|
||||
mentorshipProgram.payload.mentorshipProgram.awarded.tokens = 0
|
||||
}
|
||||
|
||||
drawMentorshipProgram(mentorshipProgram)
|
||||
}
|
||||
|
||||
function drawUserReferrer(node) {
|
||||
function hasUsersDefined(usersArray) {
|
||||
if (usersArray === undefined) { return false }
|
||||
for (let i = 0; i < usersArray.length; i++) {
|
||||
let user = usersArray[i]
|
||||
if (user.payload.referenceParent !== undefined) { return true }
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function drawUserMentor(node) {
|
||||
if (node.payload !== undefined) {
|
||||
const ownPowerText = new Intl.NumberFormat().format(node.payload.parentNode.payload.mentorships.ownPower)
|
||||
const incomingPowerText = new Intl.NumberFormat().format(node.payload.parentNode.payload.mentorships.incomingPower)
|
||||
const outgoingPowerText = new Intl.NumberFormat().format(node.payload.parentNode.payload.mentorships.outgoingPower)
|
||||
|
||||
const outgoingPowerText = new Intl.NumberFormat().format(node.payload.mentorshipProgram.outgoingPower)
|
||||
|
||||
node.payload.uiObject.valueAngleOffset = 180
|
||||
node.payload.uiObject.valueAtAngle = true
|
||||
|
||||
node.payload.uiObject.setValue(outgoingPowerText + ' ' + 'Referring Power')
|
||||
node.payload.uiObject.setValue(outgoingPowerText + ' ' + 'Mentorship Power')
|
||||
|
||||
node.payload.uiObject.statusAngleOffset = 0
|
||||
node.payload.uiObject.statusAtAngle = false
|
||||
|
||||
node.payload.uiObject.setStatus(ownPowerText + ' Own RP + ' + incomingPowerText + ' Incoming RP = ' + outgoingPowerText + ' ' + ' Outgoing RP')
|
||||
node.payload.uiObject.setStatus(outgoingPowerText + ' ' + ' Outgoing Power')
|
||||
}
|
||||
}
|
||||
|
||||
function drawMentorshipProgram(node) {
|
||||
if (node.payload !== undefined) {
|
||||
|
||||
const ownPowerText = new Intl.NumberFormat().format(node.payload.mentorshipProgram.ownPower)
|
||||
const incomingPowerText = new Intl.NumberFormat().format(node.payload.mentorshipProgram.incomingPower)
|
||||
|
||||
node.payload.uiObject.statusAngleOffset = 0
|
||||
node.payload.uiObject.statusAtAngle = false
|
||||
|
||||
node.payload.uiObject.setStatus("Referring Power = Token Power")
|
||||
node.payload.uiObject.setStatus(ownPowerText + ' Own Power - ' + incomingPowerText + ' Incoming Power')
|
||||
}
|
||||
if (node.tokensAwarded !== undefined && node.tokensAwarded.payload !== undefined) {
|
||||
|
||||
const tokensAwardedText = new Intl.NumberFormat().format(node.payload.mentorships.awarded.tokens)
|
||||
const tokensAwardedText = new Intl.NumberFormat().format(node.payload.mentorshipProgram.awarded.tokens)
|
||||
|
||||
node.tokensAwarded.payload.uiObject.statusAngleOffset = 0
|
||||
node.tokensAwarded.payload.uiObject.statusAtAngle = false
|
||||
node.tokensAwarded.payload.uiObject.valueAngleOffset = 0
|
||||
node.tokensAwarded.payload.uiObject.valueAtAngle = false
|
||||
|
||||
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens')
|
||||
node.tokensAwarded.payload.uiObject.setStatus('From ' + node.payload.mentorshipProgram.count + ' Mentees.')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ function newGovernanceFunctionLibraryReferralProgram() {
|
||||
if (userProfile.tokenSwitch.referralProgram === undefined) { continue }
|
||||
if (userProfile.tokenSwitch.referralProgram.payload === undefined) { continue }
|
||||
|
||||
resetUserReferrals(userProfile.tokenSwitch.referralProgram)
|
||||
reserReferralProgram(userProfile.tokenSwitch.referralProgram)
|
||||
}
|
||||
for (let i = 0; i < userProfiles.length; i++) {
|
||||
let userProfile = userProfiles[i]
|
||||
@@ -60,10 +60,10 @@ function newGovernanceFunctionLibraryReferralProgram() {
|
||||
calculateReferralProgram(userProfile.tokenSwitch.referralProgram)
|
||||
}
|
||||
|
||||
function resetUserReferrals(node) {
|
||||
function reserReferralProgram(node) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
node.payload.referrals = {
|
||||
node.payload.referralProgram = {
|
||||
count: 0,
|
||||
outgoingPower: 0,
|
||||
ownPower: 0,
|
||||
@@ -73,36 +73,32 @@ function newGovernanceFunctionLibraryReferralProgram() {
|
||||
percentage: 0
|
||||
}
|
||||
}
|
||||
/*
|
||||
If the node is a User Profile, we will check if it has a User Referrer child defined.
|
||||
*/
|
||||
if (
|
||||
node.type === 'User Profile' &&
|
||||
node.tokenSwitch !== undefined &&
|
||||
node.tokenSwitch.referralProgram !== undefined
|
||||
node.tokenSwitch !== undefined
|
||||
) {
|
||||
resetUserReferrals(node.tokenSwitch.referralProgram)
|
||||
reserReferralProgram(node.tokenSwitch)
|
||||
return
|
||||
}
|
||||
if (
|
||||
node.type === 'Token Switch' &&
|
||||
node.referralProgram !== undefined
|
||||
) {
|
||||
reserReferralProgram(node.referralProgram)
|
||||
return
|
||||
}
|
||||
/*
|
||||
If the node is a Referral Program, we will check if it has a User Referrer child defined.
|
||||
*/
|
||||
if (
|
||||
node.type === 'Referral Program' &&
|
||||
node.userReferrer !== undefined
|
||||
) {
|
||||
resetUserReferrals(node.userReferrer)
|
||||
reserReferralProgram(node.userReferrer)
|
||||
return
|
||||
}
|
||||
/*
|
||||
If there is a reference parent defined, this means that the referral outgoingPower is
|
||||
transfered to it.
|
||||
*/
|
||||
if (
|
||||
node.type === 'User Referrer' &&
|
||||
node.payload.referenceParent !== undefined
|
||||
) {
|
||||
resetUserReferrals(node.payload.referenceParent)
|
||||
reserReferralProgram(node.payload.referenceParent)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -121,7 +117,7 @@ function newGovernanceFunctionLibraryReferralProgram() {
|
||||
/*
|
||||
The Own Power is the power generated by the same User Profile tokens, not inherited from others.
|
||||
*/
|
||||
referralProgram.payload.referrals.ownPower = referringPower
|
||||
referralProgram.payload.referralProgram.ownPower = referringPower
|
||||
|
||||
distributeReferralPower(referralProgram, referringPower, count)
|
||||
}
|
||||
@@ -142,18 +138,18 @@ function newGovernanceFunctionLibraryReferralProgram() {
|
||||
at the count parameters. If we are processing the User Profile of this Referral Program
|
||||
then we will add zero, otherwise, 1.
|
||||
*/
|
||||
node.payload.referrals.count = node.payload.referrals.count + count
|
||||
node.payload.referralProgram.count = node.payload.referralProgram.count + count
|
||||
/*
|
||||
The outgoingPower of this node will be accumulating all the referringPower flowing
|
||||
through it, no matter from where it comes.
|
||||
*/
|
||||
node.payload.referrals.outgoingPower = node.payload.referrals.outgoingPower + referringPower
|
||||
node.payload.referralProgram.outgoingPower = node.payload.referralProgram.outgoingPower + referringPower
|
||||
/*
|
||||
We need to adjust the balance that holds the accumulationt of all incomingPower of all Referral Program
|
||||
nodes. To do this we will substratct the current incomingPower, bacause it is going to be recalculated
|
||||
inmediatelly after this, and then we will add it again after the recalcualtion.
|
||||
*/
|
||||
accumulatedIncomingReferralPower = accumulatedIncomingReferralPower - node.payload.referrals.incomingPower
|
||||
accumulatedIncomingReferralPower = accumulatedIncomingReferralPower - node.payload.referralProgram.incomingPower
|
||||
/*
|
||||
At any point in time, the incomingPower will be equal to the total of the outgoingPower minus
|
||||
the ownPower. This is like this because the outgoingPower is the accumulation of all the
|
||||
@@ -161,12 +157,12 @@ function newGovernanceFunctionLibraryReferralProgram() {
|
||||
substract the ownPower, we will have the accumulation of all the incomingPower, which
|
||||
means all the power coming from other User Profiles referencing this one.
|
||||
*/
|
||||
node.payload.referrals.incomingPower = node.payload.referrals.outgoingPower - node.payload.referrals.ownPower
|
||||
node.payload.referralProgram.incomingPower = node.payload.referralProgram.outgoingPower - node.payload.referralProgram.ownPower
|
||||
/*
|
||||
Now that we have the incomingPower calculated again, we can add it again to the balance of all the incomingPower
|
||||
of all Referral Program nodes.
|
||||
*/
|
||||
accumulatedIncomingReferralPower = accumulatedIncomingReferralPower + node.payload.referrals.incomingPower
|
||||
accumulatedIncomingReferralPower = accumulatedIncomingReferralPower + node.payload.referralProgram.incomingPower
|
||||
|
||||
if (node.userReferrer !== undefined) {
|
||||
distributeReferralPower(node.userReferrer, referringPower, 0)
|
||||
@@ -198,7 +194,7 @@ function newGovernanceFunctionLibraryReferralProgram() {
|
||||
function calculateReferralProgram(referralProgram) {
|
||||
/*
|
||||
Here we will calculate which share of the Referral Program Pool this user will get in tokens.
|
||||
To do that, we use the incomingPower, to se which proportion of the accumulatedIncomingReferralPower
|
||||
To do that, we use the incomingPower, to see which proportion of the accumulatedIncomingReferralPower
|
||||
represents.
|
||||
*/
|
||||
if (referralProgram.payload === undefined) { return }
|
||||
@@ -216,19 +212,19 @@ function newGovernanceFunctionLibraryReferralProgram() {
|
||||
referralProgram.payload.uiObject.setErrorMessage("Tokens Awarded Node is needed in order for this Program to get Tokens from the Referral Program Pool.")
|
||||
return
|
||||
}
|
||||
referralProgram.payload.referrals.awarded.tokens = referralProgram.payload.referrals.incomingPower * totalPowerRewardRatio
|
||||
referralProgram.payload.referralProgram.awarded.tokens = referralProgram.payload.referralProgram.incomingPower * totalPowerRewardRatio
|
||||
/*
|
||||
As per the system rules, the Referral Program will not give tokens to users that do not ha their own Referrer set up,
|
||||
unless it has a big amount of tokens (this last condition is for the edge case where a user it at the top of the
|
||||
referral pyramid.)
|
||||
*/
|
||||
if (
|
||||
referralProgram.payload.referrals.ownPower < 1000000 &&
|
||||
referralProgram.payload.referralProgram.ownPower < 1000000 &&
|
||||
(referralProgram.userReferrer === undefined || referralProgram.userReferrer.payload.referenceParent === undefined)
|
||||
) {
|
||||
|
||||
referralProgram.payload.uiObject.setErrorMessage("In order to be awarded " + referralProgram.payload.referrals.awarded.tokens + " SA Tokens from your referrals, you need first to define yourself who your referrer is.")
|
||||
referralProgram.payload.referrals.awarded.tokens = 0
|
||||
referralProgram.payload.uiObject.setErrorMessage("In order to be awarded " + referralProgram.payload.referralProgram.awarded.tokens + " SA Tokens from your referrals, you need first to define yourself who your referrer is.")
|
||||
referralProgram.payload.referralProgram.awarded.tokens = 0
|
||||
}
|
||||
|
||||
drawReferralProgram(referralProgram)
|
||||
@@ -236,9 +232,9 @@ function newGovernanceFunctionLibraryReferralProgram() {
|
||||
|
||||
function drawUserReferrer(node) {
|
||||
if (node.payload !== undefined) {
|
||||
const ownPowerText = new Intl.NumberFormat().format(node.payload.parentNode.payload.referrals.ownPower)
|
||||
const incomingPowerText = new Intl.NumberFormat().format(node.payload.parentNode.payload.referrals.incomingPower)
|
||||
const outgoingPowerText = new Intl.NumberFormat().format(node.payload.parentNode.payload.referrals.outgoingPower)
|
||||
const ownPowerText = new Intl.NumberFormat().format(node.payload.parentNode.payload.referralProgram.ownPower)
|
||||
const incomingPowerText = new Intl.NumberFormat().format(node.payload.parentNode.payload.referralProgram.incomingPower)
|
||||
const outgoingPowerText = new Intl.NumberFormat().format(node.payload.parentNode.payload.referralProgram.outgoingPower)
|
||||
|
||||
node.payload.uiObject.valueAngleOffset = 180
|
||||
node.payload.uiObject.valueAtAngle = true
|
||||
@@ -262,12 +258,15 @@ function newGovernanceFunctionLibraryReferralProgram() {
|
||||
}
|
||||
if (node.tokensAwarded !== undefined && node.tokensAwarded.payload !== undefined) {
|
||||
|
||||
const tokensAwardedText = new Intl.NumberFormat().format(node.payload.referrals.awarded.tokens)
|
||||
const tokensAwardedText = new Intl.NumberFormat().format(node.payload.referralProgram.awarded.tokens)
|
||||
|
||||
node.tokensAwarded.payload.uiObject.statusAngleOffset = 0
|
||||
node.tokensAwarded.payload.uiObject.statusAtAngle = false
|
||||
node.tokensAwarded.payload.uiObject.valueAngleOffset = 0
|
||||
node.tokensAwarded.payload.uiObject.valueAtAngle = false
|
||||
|
||||
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens')
|
||||
node.tokensAwarded.payload.uiObject.setStatus('From '+ node.payload.referralProgram.count + ' Referrals.')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user