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

Contribution: Tokens Mined Implemented
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2021-07-19 07:33:55 -04:00
commit 710df75fcf
14 files changed
+356 -230

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
}
]
}
@@ -22,7 +22,7 @@ function newGovernanceFunctionLibraryDistributionProcess() {
)
/*
Here we will run the Delegation Program, so that all the tokens
that are going to be delegated, are transfered to the Delegate User Profile.
that are going to be delegated, are transfered to the Delegate's User Profile.
*/
UI.projects.governance.functionLibraries.delegationProgram.calculate(
pools,
@@ -35,6 +35,9 @@ function newGovernanceFunctionLibraryDistributionProcess() {
UI.projects.governance.functionLibraries.tokenPower.calculateDelegatedPower(
userProfiles
)
/*
Run the Voting Program
*/
UI.projects.governance.functionLibraries.votingProgram.calculate(
pools,
features,
@@ -42,43 +45,64 @@ function newGovernanceFunctionLibraryDistributionProcess() {
positions,
userProfiles
)
/*
Now that we have all votes applied, we will calculate all weights
*/
UI.projects.governance.functionLibraries.weights.calculate(
pools,
features,
assets,
positions
)
/*
Let's see how the tokens to be distributed flows into pools, assets, features and positions.
*/
UI.projects.governance.functionLibraries.tokens.calculate(
pools
)
/*
Run the Referral Program
*/
UI.projects.governance.functionLibraries.referralProgram.calculate(
pools,
userProfiles
)
/*
Run the Support Program
*/
UI.projects.governance.functionLibraries.supportProgram.calculate(
pools,
userProfiles
)
/*
Run the Mentorship Program
*/
UI.projects.governance.functionLibraries.mentorshipProgram.calculate(
pools,
userProfiles
)
/*
Run the Staking Program
*/
UI.projects.governance.functionLibraries.stakingProgram.calculate(
pools,
userProfiles
)
/*
Run the Claims Program
*/
UI.projects.governance.functionLibraries.claimsProgram.calculate(
features,
assets,
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) {
@@ -1,47 +0,0 @@
function newGovernanceFeaturesSpace() {
const MODULE_NAME = 'Features Space'
let thisObject = {
container: undefined,
physics: physics,
draw: draw,
getContainer: getContainer,
finalize: finalize,
initialize: initialize
}
thisObject.container = newContainer()
thisObject.container.initialize(MODULE_NAME)
thisObject.container.isDraggeable = false
return thisObject
function finalize() {
thisObject.container.finalize()
thisObject.container = undefined
}
function initialize() {
}
function physics() {
if (UI.projects.foundations.spaces.designSpace.workspace === undefined) { return }
}
function getContainer(point) {
return undefined // since this space does not draw anything we return here
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
thisObject.container.space = MODULE_NAME
return thisObject.container
} else {
return undefined
}
}
function draw() {
}
}
@@ -1,49 +0,0 @@
function newGovernancePoolsSpace() {
const MODULE_NAME = 'Pool Space'
let thisObject = {
container: undefined,
physics: physics,
draw: draw,
getContainer: getContainer,
finalize: finalize,
initialize: initialize
}
thisObject.container = newContainer()
thisObject.container.initialize(MODULE_NAME)
thisObject.container.isDraggeable = false
return thisObject
function initialize() {
}
function finalize() {
thisObject.container.finalize()
thisObject.container = undefined
}
function getContainer(point) {
return undefined // since this space does not draw anything we return here
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
thisObject.container.space = MODULE_NAME
return thisObject.container
} else {
return undefined
}
}
function physics() {
if (UI.projects.foundations.spaces.designSpace.workspace === undefined) { return }
UI.projects.governance.functionLibraries.distributionProcess.calculate()
}
function draw() {
}
}
@@ -1,47 +0,0 @@
function newGovernancePositionsSpace() {
const MODULE_NAME = 'Positions Space'
let thisObject = {
container: undefined,
physics: physics,
draw: draw,
getContainer: getContainer,
finalize: finalize,
initialize: initialize
}
thisObject.container = newContainer()
thisObject.container.initialize(MODULE_NAME)
thisObject.container.isDraggeable = false
return thisObject
function finalize() {
thisObject.container.finalize()
thisObject.container = undefined
}
function initialize() {
}
function physics() {
if (UI.projects.foundations.spaces.designSpace.workspace === undefined) { return }
}
function getContainer(point) {
return undefined // since this space does not draw anything we return here
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
thisObject.container.space = MODULE_NAME
return thisObject.container
} else {
return undefined
}
}
function draw() {
}
}
@@ -42,6 +42,13 @@ function newGovernanceUserProfileSpace() {
function physics() {
if (UI.projects.foundations.spaces.designSpace.workspace === undefined) { return }
/*
Here we will run the distribution process, that in turn will run all the programs.
*/
UI.projects.governance.functionLibraries.distributionProcess.calculate()
/*
Load the user profiles with Token Power.
*/
let userProfiles = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('User Profile')
if (waitingForResponses !== 0) { return }
/*
@@ -57,6 +64,7 @@ function newGovernanceUserProfileSpace() {
}
}
function getBlockchainAccount(userProfile) {
let signature = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(userProfile.payload, 'signature')
if (signature === undefined || signature === "") { return }
+6 -40
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",
@@ -1116,45 +1121,6 @@
"onMouseOverIndex": 1,
"onMouseClickIndex": 1,
"onMouseDownIndex": 1
},
{
"name": "Features Space",
"folderName": "Features-Space",
"propertyName": "featuresSpace",
"functionName": "newGovernanceFeaturesSpace",
"initializationIndex": 2,
"animationPhysicsIndex": 2,
"animationDrawIndex": 2,
"onMouseWheelIndex": 2,
"onMouseOverIndex": 2,
"onMouseClickIndex": 2,
"onMouseDownIndex": 2
},
{
"name": "Positions Space",
"folderName": "Positions-Space",
"propertyName": "positionsSpace",
"functionName": "newGovernancePositionsSpace",
"initializationIndex": 3,
"animationPhysicsIndex": 3,
"animationDrawIndex": 3,
"onMouseWheelIndex": 3,
"onMouseOverIndex": 3,
"onMouseClickIndex": 3,
"onMouseDownIndex": 3
},
{
"name": "Pools Space",
"folderName": "Pools-Space",
"propertyName": "poolsSpace",
"functionName": "newGovernancePoolsSpace",
"initializationIndex": 4,
"animationPhysicsIndex": 4,
"animationDrawIndex": 4,
"onMouseWheelIndex": 4,
"onMouseOverIndex": 4,
"onMouseClickIndex": 4,
"onMouseDownIndex": 4
}
]
},