Delegation Program Debugged and Working well
This commit is contained in:
1 parent
685b223728
commit
3750629750
5 files changed
+457
-264
No files matched your search
+44
@@ -114,6 +114,50 @@
|
||||
"style": "Text",
|
||||
"text": "The final step is turning the object-formatted records back into a minimized array format, and saving the corresponding files in the dataset."
|
||||
},
|
||||
{
|
||||
"style": "Title",
|
||||
"text": "Appendix: Building 2 Interdependent Indicators"
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "Let's say you built indicator1 with product A that depends on Indicator Candles Volumens, product Candles, and you are building indicator2, product B that depends on indicator1 product A."
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "When you wrote the code for Indicator 1 Product A, you were using the syntax:"
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "variable property1 = record.current.open"
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "Why? Because Indicator 1 depends on Candles Volumens, produc Candles, and each candle has a property called open, and since product Candles is the only data dependency, it is then also the main dependency and then it will be served to you inside the record object for your convenience."
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "You could also have done"
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "variable property1 = products.candles[index] but that is more difficult because you don't really know which index you are at at any given moment in time. It is best and easier to use the record object. The array is for very advanced users."
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "Then you want to write the code for indicator 2, product B, you already declared Indicator 1, Product A as the only data dependency. "
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "Since Indicator1 product A is the only data dependency of indicator 2, then it is also the main dependency, which means that for building indicator 2, the Data Building Process will iterate over every element of Indicator 1 in this case (not candles because that is not a dependency at all)."
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "In the same way that you did before, you will write code like this:"
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": "variable propertyX = record.current.property1 (that means the property 1 of Product A of Indicator 1) "
|
||||
},
|
||||
{
|
||||
"style": "Text",
|
||||
"text": ""
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"referralProgram": {
|
||||
"type": "Referral Program",
|
||||
"name": "New Referral Program",
|
||||
"config": "{\n \"percentage\": 50\n}",
|
||||
"config": "{\n \"percentage\": 40\n}",
|
||||
"project": "Governance",
|
||||
"userReferrers": [
|
||||
{
|
||||
@@ -23,12 +23,12 @@
|
||||
"id": "0aa9db01-7605-4a51-abd9-e233de6721d6",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25342.831777538646,
|
||||
"y": 22908.486652064803
|
||||
"x": 25290.103730732157,
|
||||
"y": 22868.804725085698
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25197.716111407073,
|
||||
"y": 23171.05367863743
|
||||
"x": 25175.298701022628,
|
||||
"y": 23145.968584839084
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -54,12 +54,12 @@
|
||||
"id": "208f866a-459d-4dd8-93ea-1a2b8bfa3dac",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25432.265556147482,
|
||||
"y": 22984.00673807981
|
||||
"x": 25387.43073537859,
|
||||
"y": 22933.83655048312
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25197.716111407073,
|
||||
"y": 23171.05367863743
|
||||
"x": 25175.298701022628,
|
||||
"y": 23145.968584839084
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -79,12 +79,12 @@
|
||||
"id": "9f40067c-6185-4ea1-9ae0-bcdc38f7b1c7",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25485.991307990604,
|
||||
"y": 23088.003025209975
|
||||
"x": 25452.462560776014,
|
||||
"y": 23031.16355512956
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25197.716111407073,
|
||||
"y": 23171.05367863743
|
||||
"x": 25175.298701022628,
|
||||
"y": 23145.968584839084
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -100,8 +100,8 @@
|
||||
"id": "a9ddce61-97b0-47e8-ad6c-e9438aca3913",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25197.716111407073,
|
||||
"y": 23171.05367863743
|
||||
"x": 25175.298701022628,
|
||||
"y": 23145.968584839084
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 24963.166666666664,
|
||||
@@ -134,12 +134,12 @@
|
||||
"id": "ebf5fe9a-58c9-4b8a-afed-396d47b9556f",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25551.406345876683,
|
||||
"y": 23374.605032390522
|
||||
"x": 25540.33052642005,
|
||||
"y": 23243.295589485522
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25255.64504032121,
|
||||
"y": 23424.856899381943
|
||||
"x": 25263.166666666664,
|
||||
"y": 23358.100619195047
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -165,12 +165,12 @@
|
||||
"id": "b9052f1d-235a-4b61-8ed7-e0d77a53d6a5",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25548.123413975758,
|
||||
"y": 23491.613179568838
|
||||
"x": 25563.166666666664,
|
||||
"y": 23358.100619195047
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25255.64504032121,
|
||||
"y": 23424.856899381943
|
||||
"x": 25263.166666666664,
|
||||
"y": 23358.100619195047
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -190,12 +190,12 @@
|
||||
"id": "f8262e5f-3cb2-4a93-a539-1b79ca7fdaec",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25500.313301008988,
|
||||
"y": 23598.458288235885
|
||||
"x": 25540.33052642005,
|
||||
"y": 23472.905648904576
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25255.64504032121,
|
||||
"y": 23424.856899381943
|
||||
"x": 25263.166666666664,
|
||||
"y": 23358.100619195047
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -211,8 +211,8 @@
|
||||
"id": "f1020b53-23d4-4fea-b5d3-5409e13197a9",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25255.64504032121,
|
||||
"y": 23424.856899381943
|
||||
"x": 25263.166666666664,
|
||||
"y": 23358.100619195047
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 24963.166666666664,
|
||||
@@ -245,12 +245,12 @@
|
||||
"id": "0e176a01-3ed2-4b02-b070-601236ea2393",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25317.02443786688,
|
||||
"y": 23828.295252951375
|
||||
"x": 25452.462560776014,
|
||||
"y": 23685.03768326054
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25093.33178840193,
|
||||
"y": 23628.391279565774
|
||||
"x": 25175.298701022628,
|
||||
"y": 23570.23265355101
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -276,12 +276,12 @@
|
||||
"id": "27f046ba-de7c-45a3-9086-d6f4e0ac0fd7",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25223.496910137197,
|
||||
"y": 23898.6819399365
|
||||
"x": 25387.43073537859,
|
||||
"y": 23782.364687906975
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25093.33178840193,
|
||||
"y": 23628.391279565774
|
||||
"x": 25175.298701022628,
|
||||
"y": 23570.23265355101
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -301,12 +301,12 @@
|
||||
"id": "d0d720ad-6539-4d6b-9f56-ab1187757bf2",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25110.15292257309,
|
||||
"y": 23927.91932407112
|
||||
"x": 25290.103730732157,
|
||||
"y": 23847.396513304397
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 25093.33178840193,
|
||||
"y": 23628.391279565774
|
||||
"x": 25175.298701022628,
|
||||
"y": 23570.23265355101
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -322,8 +322,8 @@
|
||||
"id": "362a1ecb-dce9-4ebb-9b00-a20d3631f2f3",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 25093.33178840193,
|
||||
"y": 23628.391279565774
|
||||
"x": 25175.298701022628,
|
||||
"y": 23570.23265355101
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 24963.166666666664,
|
||||
@@ -353,8 +353,8 @@
|
||||
"id": "bec9399a-9f85-4cb5-bff4-9938a3bc7ac4",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 24833.001544931398,
|
||||
"y": 23628.391279565774
|
||||
"x": 24963.166666666664,
|
||||
"y": 23658.100619195047
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 24963.166666666664,
|
||||
@@ -982,12 +982,12 @@
|
||||
"id": "31919ec5-b741-4e1e-bc3e-3a537bd29e8b",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 24405.453674960736,
|
||||
"y": 23565.03748786386
|
||||
"x": 24601.0346323107,
|
||||
"y": 23830.040274686344
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 24670.688293012117,
|
||||
"y": 23424.856899381943
|
||||
"x": 24751.0346323107,
|
||||
"y": 23570.23265355101
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -1010,12 +1010,12 @@
|
||||
"id": "ee6784e7-318b-49d9-9d02-aec216a377af",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 24370.898081575597,
|
||||
"y": 23413.639541099044
|
||||
"x": 24491.227011175368,
|
||||
"y": 23720.23265355101
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 24670.688293012117,
|
||||
"y": 23424.856899381943
|
||||
"x": 24751.0346323107,
|
||||
"y": 23570.23265355101
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -1031,8 +1031,8 @@
|
||||
"id": "0b2863a0-d280-4a9a-9e2c-fe5bdbc54854",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 24670.688293012117,
|
||||
"y": 23424.856899381943
|
||||
"x": 24751.0346323107,
|
||||
"y": 23570.23265355101
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 24963.166666666664,
|
||||
@@ -1063,12 +1063,12 @@
|
||||
"id": "060240ae-727a-4b18-b154-770af8e9e8fe",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 24494.067777185846,
|
||||
"y": 22984.00673807981
|
||||
"x": 24363.166666666664,
|
||||
"y": 23358.100619195047
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 24728.617221926255,
|
||||
"y": 23171.05367863743
|
||||
"x": 24663.166666666664,
|
||||
"y": 23358.100619195047
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
@@ -1084,8 +1084,62 @@
|
||||
"id": "d66a7bf2-963a-4d28-b896-c41e83f610ae",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 24728.617221926255,
|
||||
"y": 23171.05367863743
|
||||
"x": 24663.166666666664,
|
||||
"y": 23358.100619195047
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 24963.166666666664,
|
||||
"y": 23358.100619195047
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"angleToParent": 1,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
},
|
||||
"uiObject": {
|
||||
"isRunning": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"delegationProgram": {
|
||||
"type": "Delegation Program",
|
||||
"name": "New Delegation Program",
|
||||
"config": "{}",
|
||||
"project": "Governance",
|
||||
"delegatePowerSwitch": [],
|
||||
"tokensBonus": {
|
||||
"type": "Tokens Bonus",
|
||||
"name": "New Tokens Bonus",
|
||||
"project": "Governance",
|
||||
"id": "5a9ed555-5734-4231-9822-657a2b89cacd",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 24538.902597954737,
|
||||
"y": 22933.83655048312
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 24751.0346323107,
|
||||
"y": 23145.968584839084
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"angleToParent": 1,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
},
|
||||
"uiObject": {}
|
||||
}
|
||||
},
|
||||
"id": "ebfbf3db-d700-4a5e-b040-5f950acadce7",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 24751.0346323107,
|
||||
"y": 23145.968584839084
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 24963.166666666664,
|
||||
|
||||
@@ -51,6 +51,14 @@ function newGovernanceFunctionLibraryDelegationProgram() {
|
||||
programPower: 0,
|
||||
ownPower: 0
|
||||
}
|
||||
|
||||
if (node.type === 'User Profile') {
|
||||
return
|
||||
}
|
||||
if (node.payload.referenceParent !== undefined) {
|
||||
resetProgram(node.payload.referenceParent)
|
||||
return
|
||||
}
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument === undefined) { return }
|
||||
|
||||
@@ -58,14 +66,10 @@ function newGovernanceFunctionLibraryDelegationProgram() {
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
if (node.type === 'User Profile' && property.name !== "votingProgram") { continue }
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (node.type === 'User Profile' && property.name === "votingProgram") {
|
||||
let childNode = node[property.name]
|
||||
resetProgram(childNode)
|
||||
}
|
||||
let childNode = node[property.name]
|
||||
resetProgram(childNode)
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
@@ -111,7 +115,9 @@ function newGovernanceFunctionLibraryDelegationProgram() {
|
||||
*/
|
||||
if (
|
||||
node.type === 'User Profile'
|
||||
) { return }
|
||||
) {
|
||||
return
|
||||
}
|
||||
/*
|
||||
If there is a reference parent defined, this means that the delegate power is
|
||||
transfered to it and not distributed among children.
|
||||
@@ -120,7 +126,7 @@ function newGovernanceFunctionLibraryDelegationProgram() {
|
||||
node.payload.referenceParent !== undefined &&
|
||||
node.type === 'User Delegate'
|
||||
) {
|
||||
distributeProgramPower(node.payload.referenceParent, programPower)
|
||||
distributeProgramPower(node.payload.referenceParent, programPower / 10)
|
||||
return
|
||||
}
|
||||
/*
|
||||
@@ -254,23 +260,23 @@ function newGovernanceFunctionLibraryDelegationProgram() {
|
||||
|
||||
function drawUserNode(node, programPower, percentage) {
|
||||
if (node.payload !== undefined) {
|
||||
|
||||
const outgoingPowerText = parseFloat(programPower.toFixed(2)).toLocaleString('en')
|
||||
|
||||
|
||||
const outgoingPowerText = parseFloat(programPower.toFixed(2)).toLocaleString('en')
|
||||
|
||||
node.payload.uiObject.valueAngleOffset = 180
|
||||
node.payload.uiObject.valueAtAngle = true
|
||||
|
||||
|
||||
node.payload.uiObject.setValue(outgoingPowerText + ' Delegate Power')
|
||||
|
||||
|
||||
node.payload.uiObject.percentageAngleOffset = 180
|
||||
node.payload.uiObject.percentageAtAngle = true
|
||||
|
||||
|
||||
node.payload.uiObject.setPercentage(percentage)
|
||||
|
||||
|
||||
if (node.payload.referenceParent !== undefined) {
|
||||
node.payload.uiObject.statusAngleOffset = 0
|
||||
node.payload.uiObject.statusAtAngle = true
|
||||
|
||||
|
||||
node.payload.uiObject.setStatus(outgoingPowerText + ' ' + ' Outgoing Power')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,16 +12,29 @@ function newGovernanceFunctionLibraryDistributionProcess() {
|
||||
let assets = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('Assets')
|
||||
let positions = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('Positions')
|
||||
let userProfiles = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('User Profile')
|
||||
|
||||
UI.projects.governance.functionLibraries.tokenPower.calculate(
|
||||
/*
|
||||
Here we are going to read the amount of tokens at the blockchain
|
||||
and make a first round of distribution so that they can reach
|
||||
all the defined Programs.
|
||||
*/
|
||||
UI.projects.governance.functionLibraries.tokenPower.calculateTokenPower(
|
||||
userProfiles
|
||||
)
|
||||
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
UI.projects.governance.functionLibraries.delegationProgram.calculate(
|
||||
pools,
|
||||
userProfiles
|
||||
)
|
||||
|
||||
/*
|
||||
Here we are going to do the distribution of the delegated tokens so that they
|
||||
can also reach all the defined Programs.
|
||||
*/
|
||||
UI.projects.governance.functionLibraries.tokenPower.calculateDelegatedPower(
|
||||
userProfiles
|
||||
)
|
||||
UI.projects.governance.functionLibraries.votingProgram.calculate(
|
||||
pools,
|
||||
features,
|
||||
@@ -60,7 +73,7 @@ function newGovernanceFunctionLibraryDistributionProcess() {
|
||||
pools,
|
||||
userProfiles
|
||||
)
|
||||
|
||||
|
||||
UI.projects.governance.functionLibraries.claimsProgram.calculate(
|
||||
features,
|
||||
assets,
|
||||
|
||||
@@ -1,222 +1,298 @@
|
||||
function newGovernanceFunctionLibraryTokenPower() {
|
||||
let thisObject = {
|
||||
calculate: calculate
|
||||
calculateTokenPower: calculateTokenPower,
|
||||
calculateDelegatedPower: calculateDelegatedPower
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function calculate(
|
||||
function calculateTokenPower(
|
||||
userProfiles
|
||||
) {
|
||||
/*
|
||||
We will first reset all the token power, and then distribute it to each Program.
|
||||
We will first reset all the token and delegated power, and then distribute the token power to each Program.
|
||||
*/
|
||||
for (let i = 0; i < userProfiles.length; i++) {
|
||||
let userProfile = userProfiles[i]
|
||||
resetTokenPower(userProfile)
|
||||
resetPower(userProfile)
|
||||
}
|
||||
for (let i = 0; i < userProfiles.length; i++) {
|
||||
let userProfile = userProfiles[i]
|
||||
distributeProfile(userProfile)
|
||||
distributeProfileTokenPower(userProfile)
|
||||
}
|
||||
}
|
||||
|
||||
function resetTokenPower(node) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
node.payload.tokenPower = 0
|
||||
/*
|
||||
When we reach certain node types, we will halt the distribution, because these are targets for
|
||||
token power.
|
||||
*/
|
||||
if (
|
||||
node.type === 'Referral Program' ||
|
||||
node.type === 'Mentorship Program' ||
|
||||
node.type === 'Support Program' ||
|
||||
node.type === 'Voting Program' ||
|
||||
node.type === 'Claims Program' ||
|
||||
node.type === 'Staking Program'
|
||||
) { return }
|
||||
/*
|
||||
We will reset token power of children.
|
||||
*/
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument === undefined) { return }
|
||||
function calculateDelegatedPower(
|
||||
userProfiles
|
||||
) {
|
||||
/*
|
||||
We will distribute the original Blockachain Power + the Delegated Power to each Program.
|
||||
*/
|
||||
for (let i = 0; i < userProfiles.length; i++) {
|
||||
let userProfile = userProfiles[i]
|
||||
distributeProfileDelegatedPower(userProfile)
|
||||
}
|
||||
}
|
||||
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
function resetPower(node) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
node.payload.tokenPower = 0
|
||||
/*
|
||||
When we reach certain node types, we will halt the distribution, because these are targets for
|
||||
token power.
|
||||
*/
|
||||
if (
|
||||
node.type === 'Referral Program' ||
|
||||
node.type === 'Mentorship Program' ||
|
||||
node.type === 'Support Program' ||
|
||||
node.type === 'Voting Program' ||
|
||||
node.type === 'Claims Program' ||
|
||||
node.type === 'Staking Program' ||
|
||||
node.type === 'Delegation Program'
|
||||
) { return }
|
||||
/*
|
||||
We will reset token power of children.
|
||||
*/
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument === undefined) { return }
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
let childNode = node[property.name]
|
||||
resetTokenPower(childNode)
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let propertyArray = node[property.name]
|
||||
if (propertyArray !== undefined) {
|
||||
for (let m = 0; m < propertyArray.length; m++) {
|
||||
let childNode = propertyArray[m]
|
||||
resetTokenPower(childNode)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
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]
|
||||
resetPower(childNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function distributeProfile(userProfile) {
|
||||
if (userProfile.payload === undefined) { return }
|
||||
let tokenPower
|
||||
if (userProfile.payload.blockchainTokens === undefined) {
|
||||
return
|
||||
} else {
|
||||
tokenPower = userProfile.payload.blockchainTokens
|
||||
}
|
||||
/*
|
||||
Before we start we will do some validations:
|
||||
*/
|
||||
if (userProfile.tokenPowerSwitch === undefined) {
|
||||
userProfile.payload.uiObject.setErrorMessage("You need to have a Token Power Switch child node.")
|
||||
return
|
||||
}
|
||||
distributeTokenPower(userProfile, tokenPower)
|
||||
}
|
||||
|
||||
function distributeTokenPower(node, tokenPower, switchPercentage) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
node.payload.tokenPower = node.payload.tokenPower + tokenPower
|
||||
drawTokenPower(node, node.payload.tokenPower, switchPercentage)
|
||||
/*
|
||||
When we reach certain node types, we will halt the distribution,
|
||||
because these are targets for token power.
|
||||
*/
|
||||
if (
|
||||
node.type === 'Referral Program' ||
|
||||
node.type === 'Mentorship Program' ||
|
||||
node.type === 'Support Program' ||
|
||||
node.type === 'Voting Program' ||
|
||||
node.type === 'Claims Program' ||
|
||||
node.type === 'Staking Program' ||
|
||||
node.type === 'Delegation Program'
|
||||
) { return }
|
||||
/*
|
||||
We will redistribute token power among children.
|
||||
*/
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument === undefined) { return }
|
||||
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
/*
|
||||
Before distributing the token power, we will calculate how the power
|
||||
is going to be switched between all nodes. The first pass is about
|
||||
scanning all sibling nodes to see which ones have a percentage defined
|
||||
at their config, and check that all percentages don't add more than 100.
|
||||
*/
|
||||
let totalPercentage = 0
|
||||
let totalNodesWithoutPercentage = 0
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
let childNode = node[property.name]
|
||||
if (childNode === undefined) { continue }
|
||||
let percentage = getPercentage(childNode)
|
||||
|
||||
if (percentage !== undefined && isNaN(percentage) !== true) {
|
||||
totalPercentage = totalPercentage + percentage
|
||||
} else {
|
||||
totalNodesWithoutPercentage++
|
||||
break
|
||||
case 'array': {
|
||||
let propertyArray = node[property.name]
|
||||
if (propertyArray !== undefined) {
|
||||
for (let m = 0; m < propertyArray.length; m++) {
|
||||
let childNode = propertyArray[m]
|
||||
resetPower(childNode)
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let propertyArray = node[property.name]
|
||||
if (propertyArray !== undefined) {
|
||||
for (let m = 0; m < propertyArray.length; m++) {
|
||||
let childNode = propertyArray[m]
|
||||
if (childNode === undefined) { continue }
|
||||
let percentage = getPercentage(childNode)
|
||||
if (percentage !== undefined && isNaN(percentage) !== true) {
|
||||
totalPercentage = totalPercentage + percentage
|
||||
} else {
|
||||
totalNodesWithoutPercentage++
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if (totalPercentage > 100) {
|
||||
node.payload.uiObject.setErrorMessage('Token Power Switching Error. Total Percentage of children nodes is grater that 100.')
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function distributeProfileTokenPower(userProfile) {
|
||||
if (userProfile.payload === undefined) { return }
|
||||
if (userProfile.payload.blockchainTokens === undefined) { return }
|
||||
/*
|
||||
The tokenPower is comming from blockchainTokens.
|
||||
*/
|
||||
let tokenPower = userProfile.payload.blockchainTokens
|
||||
/*
|
||||
Before we start we will do some validations:
|
||||
*/
|
||||
if (userProfile.tokenPowerSwitch === undefined) {
|
||||
userProfile.payload.uiObject.setErrorMessage("You need to have a Token Power Switch child node.")
|
||||
return
|
||||
}
|
||||
distributeTokenPower(
|
||||
userProfile,
|
||||
tokenPower,
|
||||
undefined,
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
function distributeProfileDelegatedPower(userProfile) {
|
||||
if (userProfile.payload === undefined) { return }
|
||||
if (userProfile.payload.blockchainTokens === undefined) { return }
|
||||
if (userProfile.payload.delegationProgram === undefined) { return }
|
||||
/*
|
||||
The Deletated Power is already accumilated at userProfile.payload.tokenPower
|
||||
*/
|
||||
let tokenPower = userProfile.payload.delegationProgram.programPower
|
||||
/*
|
||||
Before we start we will do some validations:
|
||||
*/
|
||||
if (userProfile.tokenPowerSwitch === undefined) {
|
||||
userProfile.payload.uiObject.setErrorMessage("You need to have a Token Power Switch child node.")
|
||||
return
|
||||
}
|
||||
distributeTokenPower(
|
||||
userProfile,
|
||||
tokenPower,
|
||||
undefined,
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
function distributeTokenPower(
|
||||
node,
|
||||
tokenPower,
|
||||
switchPercentage,
|
||||
excludeDelegationProgram
|
||||
) {
|
||||
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
node.payload.tokenPower = node.payload.tokenPower + tokenPower
|
||||
drawTokenPower(node, node.payload.tokenPower, switchPercentage)
|
||||
/*
|
||||
When we reach certain node types, we will halt the distribution,
|
||||
because these are targets for token power.
|
||||
*/
|
||||
if (
|
||||
node.type === 'Referral Program' ||
|
||||
node.type === 'Mentorship Program' ||
|
||||
node.type === 'Support Program' ||
|
||||
node.type === 'Voting Program' ||
|
||||
node.type === 'Claims Program' ||
|
||||
node.type === 'Staking Program' ||
|
||||
node.type === 'Delegation Program'
|
||||
) { return }
|
||||
/*
|
||||
We will redistribute token power among children.
|
||||
*/
|
||||
let schemaDocument = getSchemaDocument(node)
|
||||
if (schemaDocument === undefined) { return }
|
||||
|
||||
if (schemaDocument.childrenNodesProperties !== undefined) {
|
||||
/*
|
||||
Before distributing the token power, we will calculate how the power
|
||||
is going to be switched between all nodes. The first pass is about
|
||||
scanning all sibling nodes to see which ones have a percentage defined
|
||||
at their config, and check that all percentages don't add more than 100.
|
||||
*/
|
||||
let totalPercentage = 0
|
||||
let totalNodesWithoutPercentage = 0
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
let childNode = node[property.name]
|
||||
if (childNode === undefined) { continue }
|
||||
if (childNode.type === "Delegation Program" && excludeDelegationProgram === true) { continue }
|
||||
|
||||
let percentage = getPercentage(childNode)
|
||||
|
||||
if (percentage !== undefined && isNaN(percentage) !== true) {
|
||||
totalPercentage = totalPercentage + percentage
|
||||
} else {
|
||||
totalNodesWithoutPercentage++
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let propertyArray = node[property.name]
|
||||
if (propertyArray !== undefined) {
|
||||
for (let m = 0; m < propertyArray.length; m++) {
|
||||
let childNode = propertyArray[m]
|
||||
if (childNode === undefined) { continue }
|
||||
if (childNode.type === "Delegation Program" && excludeDelegationProgram === true) { continue }
|
||||
|
||||
let percentage = getPercentage(childNode)
|
||||
if (percentage !== undefined && isNaN(percentage) !== true) {
|
||||
totalPercentage = totalPercentage + percentage
|
||||
} else {
|
||||
totalNodesWithoutPercentage++
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
let defaultPercentage = 0
|
||||
if (totalNodesWithoutPercentage > 0) {
|
||||
defaultPercentage = (100 - totalPercentage) / totalNodesWithoutPercentage
|
||||
}
|
||||
/*
|
||||
Here we do the actual distribution.
|
||||
*/
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
let childNode = node[property.name]
|
||||
if (childNode === undefined) { continue }
|
||||
let percentage = getPercentage(childNode)
|
||||
if (percentage === undefined || isNaN(percentage) === true) {
|
||||
percentage = defaultPercentage
|
||||
}
|
||||
distributeTokenPower(childNode, tokenPower * percentage / 100, percentage)
|
||||
}
|
||||
if (totalPercentage > 100) {
|
||||
node.payload.uiObject.setErrorMessage('Token Power Switching Error. Total Percentage of children nodes is grater that 100.')
|
||||
return
|
||||
}
|
||||
let defaultPercentage = 0
|
||||
if (totalNodesWithoutPercentage > 0) {
|
||||
defaultPercentage = (100 - totalPercentage) / totalNodesWithoutPercentage
|
||||
}
|
||||
/*
|
||||
Here we do the actual distribution.
|
||||
*/
|
||||
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
|
||||
let property = schemaDocument.childrenNodesProperties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
let childNode = node[property.name]
|
||||
if (childNode === undefined) { continue }
|
||||
if (childNode.type === "Delegation Program" && excludeDelegationProgram === true) { continue }
|
||||
|
||||
let percentage = getPercentage(childNode)
|
||||
if (percentage === undefined || isNaN(percentage) === true) {
|
||||
percentage = defaultPercentage
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let propertyArray = node[property.name]
|
||||
if (propertyArray !== undefined) {
|
||||
for (let m = 0; m < propertyArray.length; m++) {
|
||||
let childNode = propertyArray[m]
|
||||
if (childNode === undefined) { continue }
|
||||
let percentage = getPercentage(childNode)
|
||||
if (percentage === undefined || isNaN(percentage) === true) {
|
||||
percentage = defaultPercentage
|
||||
}
|
||||
distributeTokenPower(childNode, tokenPower * percentage / 100, percentage)
|
||||
distributeTokenPower(
|
||||
childNode,
|
||||
tokenPower * percentage / 100,
|
||||
percentage,
|
||||
excludeDelegationProgram
|
||||
)
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let propertyArray = node[property.name]
|
||||
if (propertyArray !== undefined) {
|
||||
for (let m = 0; m < propertyArray.length; m++) {
|
||||
let childNode = propertyArray[m]
|
||||
if (childNode === undefined) { continue }
|
||||
if (childNode.type === "Delegation Program" && excludeDelegationProgram === true) { continue }
|
||||
|
||||
let percentage = getPercentage(childNode)
|
||||
if (percentage === undefined || isNaN(percentage) === true) {
|
||||
percentage = defaultPercentage
|
||||
}
|
||||
distributeTokenPower(
|
||||
childNode,
|
||||
tokenPower * percentage / 100,
|
||||
percentage,
|
||||
excludeDelegationProgram
|
||||
)
|
||||
}
|
||||
break
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getPercentage(node) {
|
||||
return UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'percentage')
|
||||
}
|
||||
function getPercentage(node) {
|
||||
return UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'percentage')
|
||||
}
|
||||
|
||||
function drawTokenPower(node, tokenPower, percentage) {
|
||||
if (node.payload !== undefined) {
|
||||
if (node.type === 'User Profile') {
|
||||
|
||||
let incomingPower = node.payload.tokenPower - node.payload.blockchainTokens
|
||||
const ownPowerText = parseFloat(node.payload.blockchainTokens.toFixed(2)).toLocaleString('en') + ' ' + 'Own Power'
|
||||
const incomingPowerText = parseFloat(incomingPower.toFixed(2)).toLocaleString('en') + ' ' + 'Incoming Power'
|
||||
|
||||
node.payload.uiObject.valueAngleOffset = 0
|
||||
node.payload.uiObject.valueAtAngle = false
|
||||
node.payload.uiObject.setStatus(ownPowerText + ' - ' + incomingPowerText)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const tokenPowerText = parseFloat(tokenPower.toFixed(2)).toLocaleString('en') + ' ' + 'Token Power'
|
||||
|
||||
function drawTokenPower(node, tokenPower, percentage) {
|
||||
tokenPower = parseFloat(tokenPower.toFixed(2)).toLocaleString('en') + ' ' + 'Token Power'
|
||||
if (node.payload !== undefined) {
|
||||
if (node.type === 'User Profile') {
|
||||
return
|
||||
}
|
||||
node.payload.uiObject.valueAngleOffset = 180
|
||||
node.payload.uiObject.valueAtAngle = true
|
||||
node.payload.uiObject.valueAngleOffset = 180
|
||||
node.payload.uiObject.valueAtAngle = true
|
||||
|
||||
node.payload.uiObject.setValue(tokenPower)
|
||||
node.payload.uiObject.setValue(tokenPowerText)
|
||||
|
||||
if (percentage !== undefined) {
|
||||
node.payload.uiObject.percentageAngleOffset = 180
|
||||
node.payload.uiObject.percentageAtAngle = true
|
||||
node.payload.uiObject.setPercentage(percentage.toFixed(2))
|
||||
}
|
||||
if (percentage !== undefined) {
|
||||
node.payload.uiObject.percentageAngleOffset = 180
|
||||
node.payload.uiObject.percentageAtAngle = true
|
||||
node.payload.uiObject.setPercentage(percentage.toFixed(2))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user