Mentorship Program Implementation first iteration finished

This commit is contained in:
Luis Fernando Molina committed 2021-06-20 19:36:06 +02:00
1 parent 83dd0e6174
commit 66e1af371c
5 files changed
+228 -68

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 }
/*
@@ -73,33 +73,31 @@ 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
) {
reserMentorshipProgram(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
) {
reserMentorshipProgram(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
) {
reserMentorshipProgram(node.payload.referenceParent)
@@ -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.mentorshipProgram.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': {
@@ -144,10 +142,10 @@ function newGovernanceFunctionLibraryMentorshipProgram() {
*/
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.mentorshipProgram.outgoingPower = node.payload.mentorshipProgram.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
@@ -168,27 +166,31 @@ function newGovernanceFunctionLibraryMentorshipProgram() {
*/
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 }
@@ -223,42 +225,54 @@ function newGovernanceFunctionLibraryMentorshipProgram() {
mentorship pyramid.)
*/
if (
mentorshipProgram.payload.mentorshipProgram.awarded.tokens > 0 &&
mentorshipProgram.payload.mentorshipProgram.ownPower < 1000000 &&
(mentorshipProgram.userReferrer === undefined || mentorshipProgram.userReferrer.payload.referenceParent === undefined)
(mentorshipProgram.userMentors === undefined || hasUsersDefined(mentorshipProgram.userMentors) === false)
) {
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 referrer is.")
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.mentorshipProgram.ownPower)
const incomingPowerText = new Intl.NumberFormat().format(node.payload.parentNode.payload.mentorshipProgram.incomingPower)
const outgoingPowerText = new Intl.NumberFormat().format(node.payload.parentNode.payload.mentorshipProgram.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) {
@@ -270,7 +284,7 @@ function newGovernanceFunctionLibraryMentorshipProgram() {
node.tokensAwarded.payload.uiObject.valueAtAngle = false
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens')
node.tokensAwarded.payload.uiObject.setStatus('From '+ node.payload.referralProgram.count + ' Mentorships.')
node.tokensAwarded.payload.uiObject.setStatus('From ' + node.payload.mentorshipProgram.count + ' Mentees.')
}
}
}
@@ -73,20 +73,20 @@ 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
) {
reserReferralProgram(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
@@ -94,10 +94,6 @@ function newGovernanceFunctionLibraryReferralProgram() {
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
@@ -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 }