Tokens Mined Implemented

This commit is contained in:
Luis Fernando Molina committed 2021-07-19 13:32:42 +02:00
1 parent b929c3ec29
commit 7348cad232
10 files changed
+323 -40

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

@@ -1223,6 +1223,33 @@
}
}
},
"tokensMined": {
"type": "Tokens Mined",
"name": "New Tokens Mined",
"project": "Governance",
"id": "02c80886-9f64-451a-a8a6-e23fadb26d97",
"savedPayload": {
"position": {
"x": 24663.166666666664,
"y": 23058.100619195047
},
"targetPosition": {
"x": 24963.166666666664,
"y": 23058.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
},
"id": "1fd95e41-4b22-48d5-be3a-904c37afcb11",
"savedPayload": {
"position": {
@@ -4142,6 +4142,33 @@
}
}
},
"tokensMined": {
"type": "Tokens Mined",
"name": "New Tokens Mined",
"project": "Governance",
"id": "ab419614-d76c-4820-ace3-970c8282daa6",
"savedPayload": {
"position": {
"x": 30016,
"y": 23099.999999999996
},
"targetPosition": {
"x": 30316,
"y": 23099.999999999996
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
},
"id": "148911b3-b2f3-44fb-8cb4-017991789132",
"savedPayload": {
"position": {
@@ -534,12 +534,12 @@
"id": "c2ad753c-49b6-4675-9fdd-02b6967aaab2",
"savedPayload": {
"position": {
"x": 14643.944089716459,
"y": 23180.59258456338
"x": 14844.076124072424,
"y": 23593.280114692785
},
"targetPosition": {
"x": 14566.298376185703,
"y": 23470.3703324501
"x": 14554.298376185703,
"y": 23515.634401162028
},
"floatingObject": {
"isPinned": false,
@@ -572,12 +572,12 @@
"id": "578d894c-20a7-4a79-b90e-ba383740d29d",
"savedPayload": {
"position": {
"x": 15068.208158428388,
"y": 23180.59258456338
"x": 14844.076124072422,
"y": 24017.544183404712
},
"targetPosition": {
"x": 14856.076124072424,
"y": 23392.724618919343
"x": 14631.944089716459,
"y": 23805.41214904875
},
"floatingObject": {
"isPinned": false,
@@ -600,12 +600,12 @@
"id": "0cfaa435-6615-4df8-9d31-1fe5f21e0e61",
"savedPayload": {
"position": {
"x": 15145.853871959145,
"y": 23470.3703324501
"x": 14554.298376185703,
"y": 24095.18989693547
},
"targetPosition": {
"x": 14856.076124072424,
"y": 23392.724618919343
"x": 14631.944089716459,
"y": 23805.41214904875
},
"floatingObject": {
"isPinned": false,
@@ -623,12 +623,12 @@
"id": "4ac11744-6d87-413d-813e-f0963b156d8c",
"savedPayload": {
"position": {
"x": 14856.076124072424,
"y": 23392.724618919343
"x": 14631.944089716459,
"y": 23805.41214904875
},
"targetPosition": {
"x": 14566.298376185703,
"y": 23470.3703324501
"x": 14554.298376185703,
"y": 23515.634401162028
},
"floatingObject": {
"isPinned": false,
@@ -646,12 +646,12 @@
"id": "fcceb17d-2c2a-4e24-ab5d-e2a8a2798f90",
"savedPayload": {
"position": {
"x": 14566.298376185703,
"y": 23470.3703324501
"x": 14554.298376185703,
"y": 23515.634401162028
},
"targetPosition": {
"x": 14354.16634182974,
"y": 23682.502366806064
"x": 14342.16634182974,
"y": 23303.502366806064
},
"floatingObject": {
"isPinned": false,
@@ -802,12 +802,12 @@
"id": "055d1919-2b4b-40f2-8793-9cc5eb765a88",
"savedPayload": {
"position": {
"x": 14954.16634182974,
"y": 23682.502366806064
"x": 14342.16634182974,
"y": 23903.502366806064
},
"targetPosition": {
"x": 14654.16634182974,
"y": 23682.502366806064
"x": 14342.16634182974,
"y": 23603.502366806064
},
"floatingObject": {
"isPinned": false,
@@ -825,12 +825,12 @@
"id": "450eb600-3080-4d37-b8a2-12f71120573c",
"savedPayload": {
"position": {
"x": 14654.16634182974,
"y": 23682.502366806064
"x": 14342.16634182974,
"y": 23603.502366806064
},
"targetPosition": {
"x": 14354.16634182974,
"y": 23682.502366806064
"x": 14342.16634182974,
"y": 23303.502366806064
},
"floatingObject": {
"isPinned": false,
@@ -886,12 +886,12 @@
"id": "02e75b99-0944-44dd-a434-9e307bdc7935",
"savedPayload": {
"position": {
"x": 14778.430410541667,
"y": 24106.76643551799
"x": 13917.902273117812,
"y": 23727.76643551799
},
"targetPosition": {
"x": 14566.298376185703,
"y": 23894.634401162028
"x": 14130.034307473776,
"y": 23515.634401162028
},
"floatingObject": {
"isPinned": false,
@@ -909,12 +909,12 @@
"id": "8f44d9ab-8ce6-4336-8b0e-0323d7440e75",
"savedPayload": {
"position": {
"x": 14566.298376185703,
"y": 23894.634401162028
"x": 14130.034307473776,
"y": 23515.634401162028
},
"targetPosition": {
"x": 14354.16634182974,
"y": 23682.502366806064
"x": 14342.16634182974,
"y": 23303.502366806064
},
"floatingObject": {
"isPinned": false,
@@ -933,15 +933,42 @@
"id": "d5ad1e6a-c6ea-465e-ae14-99fb54534baa",
"savedPayload": {
"position": {
"x": 14354.16634182974,
"y": 23682.502366806064
"x": 14342.16634182974,
"y": 23303.502366806064
},
"targetPosition": {
"x": 14342.16634182974,
"y": 23003.502366806064
},
"floatingObject": {
"isPinned": true,
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
},
"tokensMined": {
"type": "Tokens Mined",
"name": "New Tokens Mined",
"project": "Governance",
"id": "9f832420-03f7-4e4b-8973-c3520bd6f263",
"savedPayload": {
"position": {
"x": 14042.16634182974,
"y": 23003.502366806064
},
"targetPosition": {
"x": 14342.16634182974,
"y": 23003.502366806064
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
@@ -0,0 +1,21 @@
{
"type": "Tokens Mined",
"menuItems": [
{
"action": "Delete UI Object",
"actionProject": "Foundations",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity",
"actionFunction": "payload.executeAction"
}
],
"addLeftIcons": true,
"level": 2,
"attachingRules": {
"compatibleTypes": "->User Profile->"
},
"propertyNameAtParent": "tokensMined"
}
@@ -17,6 +17,15 @@
"label": "Add Token Power Switch",
"relatedUiObject": "Token Power Switch"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "tokensMined",
"actionFunction": "payload.executeAction",
"label": "Add Tokens Mined",
"relatedUiObject": "Tokens Mined"
},
{
"action": "Delete UI Object",
"actionProject": "Foundations",
@@ -44,6 +53,12 @@
"type": "node",
"childType": "Token Power Switch",
"autoAdd": true
},
{
"name": "tokensMined",
"type": "node",
"childType": "Tokens Mined",
"autoAdd": true
}
]
}
@@ -97,5 +97,12 @@ function newGovernanceFunctionLibraryDistributionProcess() {
positions,
userProfiles
)
/*
After all the programs were ran, we can calculate the tokens mining
calculation each profile.
*/
UI.projects.governance.functionLibraries.tokenMining.calculate(
userProfiles
)
}
}
@@ -0,0 +1,150 @@
function newGovernanceFunctionLibraryTokenMining() {
let thisObject = {
calculate: calculate
}
return thisObject
function calculate(
userProfiles
) {
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
if (userProfile.tokenPowerSwitch === undefined) { continue }
resetTokensMined(userProfile)
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
if (userProfile.tokenPowerSwitch === undefined) { continue }
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Referral Program")
if (program === undefined) { continue }
if (program.payload === undefined) { continue }
calculateProgram(userProfile, program, "referralProgram")
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
if (userProfile.tokenPowerSwitch === undefined) { continue }
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Support Program")
if (program === undefined) { continue }
if (program.payload === undefined) { continue }
calculateProgram(userProfile, program, "supportProgram")
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
if (userProfile.tokenPowerSwitch === undefined) { continue }
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Mentorship Program")
if (program === undefined) { continue }
if (program.payload === undefined) { continue }
calculateProgram(userProfile, program, "mentorshipProgram")
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
if (userProfile.tokenPowerSwitch === undefined) { continue }
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Claims Program")
if (program === undefined) { continue }
if (program.payload === undefined) { continue }
calculateProgram(userProfile, program, "claimsProgram")
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
if (userProfile.tokenPowerSwitch === undefined) { continue }
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Voting Program")
if (program === undefined) { continue }
if (program.payload === undefined) { continue }
calculateProgram(userProfile, program, "votingProgram")
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
if (userProfile.tokenPowerSwitch === undefined) { continue }
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Staking Program")
if (program === undefined) { continue }
if (program.payload === undefined) { continue }
calculateProgram(userProfile, program, "stakingProgram")
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
if (userProfile.tokenPowerSwitch === undefined) { continue }
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Delegation Program")
if (program === undefined) { continue }
if (program.payload === undefined) { continue }
calculateProgram(userProfile, program, "delegationProgram")
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
if (userProfile.tokenPowerSwitch === undefined) { continue }
drawTokensMined(userProfile)
}
function resetTokensMined(userProfile) {
if (userProfile === undefined) { return }
if (userProfile.payload === undefined) { return }
if (userProfile.tokensMined === undefined) { return }
if (userProfile.tokensMined.payload.tokensMined === undefined) {
userProfile.tokensMined.payload.tokensMined = {
awarded: 0,
bonus: 0,
total: 0
}
} else {
userProfile.tokensMined.payload.tokensMined.awarded = 0
userProfile.tokensMined.payload.tokensMined.bonus = 0
userProfile.tokensMined.payload.tokensMined.total = 0
}
}
function calculateProgram(userProfile, programNode, programPropertyName) {
/*
Here we will look into the program node and add their token awarded and token bonus
to the subtotals at the Tokens Mined node.
*/
if (userProfile === undefined) { return }
if (userProfile.payload === undefined) { return }
if (userProfile.tokensMined === undefined) { return }
if (programNode.payload === undefined) { return }
if (programNode.payload[programPropertyName] === undefined) { return }
if (programNode.tokensAwarded !== undefined && programNode.payload[programPropertyName].awarded !== undefined) {
let awarded = programNode.payload[programPropertyName].awarded.tokens | 0
userProfile.tokensMined.payload.tokensMined.awarded = userProfile.tokensMined.payload.tokensMined.awarded + awarded
}
if (programNode.tokensBonus !== undefined && programNode.payload[programPropertyName].bonus !== undefined) {
let bonus = programNode.payload[programPropertyName].bonus.tokens | 0
userProfile.tokensMined.payload.tokensMined.bonus = userProfile.tokensMined.payload.tokensMined.bonus + bonus
}
userProfile.tokensMined.payload.tokensMined.total = userProfile.tokensMined.payload.tokensMined.awarded + userProfile.tokensMined.payload.tokensMined.bonus
}
function drawTokensMined(userProfile) {
if (userProfile === undefined) { return }
if (userProfile.payload === undefined) { return }
if (userProfile.tokensMined === undefined) { return }
const awarded = parseFloat(userProfile.tokensMined.payload.tokensMined.awarded.toFixed(2)).toLocaleString('en')
const bonus = parseFloat(userProfile.tokensMined.payload.tokensMined.bonus.toFixed(2)).toLocaleString('en')
const total = parseFloat(userProfile.tokensMined.payload.tokensMined.total.toFixed(2)).toLocaleString('en')
userProfile.tokensMined.payload.uiObject.valueAngleOffset = 0
userProfile.tokensMined.payload.uiObject.valueAtAngle = true
userProfile.tokensMined.payload.uiObject.setStatus(awarded + ' Awarded + ' + bonus + ' Bonus')
userProfile.tokensMined.payload.uiObject.setValue(total + ' SA Tokens')
}
}
}
@@ -174,6 +174,7 @@ function newGovernanceFunctionLibraryTokenPower() {
let childNode = node[property.name]
if (childNode === undefined) { continue }
if (childNode.type === "Delegation Program" && excludeDelegationProgram === true) { continue }
if (childNode.type === "Tokens Mined") { continue }
let percentage = getPercentage(childNode)
@@ -191,6 +192,7 @@ function newGovernanceFunctionLibraryTokenPower() {
let childNode = propertyArray[m]
if (childNode === undefined) { continue }
if (childNode.type === "Delegation Program" && excludeDelegationProgram === true) { continue }
if (childNode.type === "Tokens Mined") { continue }
let percentage = getPercentage(childNode)
if (percentage !== undefined && isNaN(percentage) !== true) {
@@ -223,6 +225,7 @@ function newGovernanceFunctionLibraryTokenPower() {
let childNode = node[property.name]
if (childNode === undefined) { continue }
if (childNode.type === "Delegation Program" && excludeDelegationProgram === true) { continue }
if (childNode.type === "Tokens Mined") { continue }
let percentage = getPercentage(childNode)
if (percentage === undefined || isNaN(percentage) === true) {
@@ -243,6 +246,7 @@ function newGovernanceFunctionLibraryTokenPower() {
let childNode = propertyArray[m]
if (childNode === undefined) { continue }
if (childNode.type === "Delegation Program" && excludeDelegationProgram === true) { continue }
if (childNode.type === "Tokens Mined") { continue }
let percentage = getPercentage(childNode)
if (percentage === undefined || isNaN(percentage) === true) {
+6 -1
View File
@@ -983,10 +983,15 @@
"functionName": "newGovernanceFunctionLibraryAssets"
},
{
"name": "TokenPower",
"name": "Token Power",
"propertyName": "tokenPower",
"functionName": "newGovernanceFunctionLibraryTokenPower"
},
{
"name": "Token Mining",
"propertyName": "tokenMining",
"functionName": "newGovernanceFunctionLibraryTokenMining"
},
{
"name": "Voting Program",
"propertyName": "votingProgram",