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

Contribution: Governance: Reading token balance from the blockchain.
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2021-06-17 10:04:38 -04:00
commit 4b688776d2
54 files changed
+3053 -4466

No files matched your search

+19
View File
@@ -132,6 +132,25 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
respondWithContent(JSON.stringify(serverResponse), httpResponse)
return
}
case 'signData': {
let serverResponse = await WEB3_SERVER.signData(
params.privateKey,
params.data
)
respondWithContent(JSON.stringify(serverResponse), httpResponse)
return
}
case 'recoverAddress': {
let serverResponse = await WEB3_SERVER.recoverAddress(
params.signature
)
respondWithContent(JSON.stringify(serverResponse), httpResponse)
return
}
default: {
respondWithContent(JSON.stringify({ error: 'Method ' + params.method + ' is invalid.' }), httpResponse)
}
+48 -11
View File
@@ -6,6 +6,8 @@ exports.newWeb3Server = function newWeb3Server() {
getNetworkClientStatus: getNetworkClientStatus,
createWalletAccount: createWalletAccount,
getWalletBalances: getWalletBalances,
signData: signData,
recoverAddress: recoverAddress,
initialize: initialize,
finalize: finalize,
run: run
@@ -56,7 +58,7 @@ exports.newWeb3Server = function newWeb3Server() {
return status
}
} catch (err) {
return { error: 'Could not connect to ' + key + '. ' + err.message + '.' }
return { error: 'Could not connect to ' + key + '. ' + err.stack + '.' }
}
}
@@ -73,7 +75,7 @@ exports.newWeb3Server = function newWeb3Server() {
}
} catch (err) {
return { error: 'Could not create the account. ' + err.message }
return { error: 'Could not create the account. ' + err.stack }
}
}
@@ -116,22 +118,22 @@ exports.newWeb3Server = function newWeb3Server() {
for (let j = 0; j < walletAccount.tokenBalances.length; j++) {
let tokenBalance = walletAccount.tokenBalances[j]
if (tokenBalance.referenceParent === undefined) { continue }
if (tokenBalance.referenceParent.parentNode === undefined) { continue }
if (tokenBalance.referenceParent.smartContracts === undefined) { continue }
if (tokenBalance.referenceParent === undefined) { continue }
if (tokenBalance.referenceParent.parentNode === undefined) { continue }
if (tokenBalance.referenceParent.smartContracts === undefined) { continue }
if (tokenBalance.referenceParent.config.codeName === undefined) {
tokenBalance.error = 'Reference Parent without config.codeName defined.'
continue
}
}
if (tokenBalance.referenceParent.smartContracts.config.address === undefined) {
tokenBalance.error = 'Reference Parent Smart Contract without config.address defined.'
continue
}
}
let tokenContractAddress = tokenBalance.referenceParent.smartContracts.config.address
// The minimum ABI to get ERC20 Token balance
// The minimum ABI to get ERC20 Token balance
let minABI = [
// balanceOf
{
@@ -152,8 +154,8 @@ exports.newWeb3Server = function newWeb3Server() {
];
let contract = new web3.eth.Contract(minABI, tokenContractAddress);
try {
try {
tokenBalance.value = await contract.methods.balanceOf(walletAccount.config.address).call()
} catch (err) {
if (err.message.indexOf('Provided address') >= 0) {
@@ -170,7 +172,7 @@ exports.newWeb3Server = function newWeb3Server() {
return responseData
}
} catch (err) {
return { error: 'Could not connect to ' + key + '. ' + err.message + '.' }
return { error: 'Could not connect to ' + key + '. ' + err.stack + '.' }
}
}
@@ -202,4 +204,39 @@ exports.newWeb3Server = function newWeb3Server() {
}
}
}
async function signData(privateKey, data) {
try {
let web3 = new Web3()
let signature = web3.eth.accounts.sign(data, privateKey)
return {
signature: signature,
result: 'Ok'
}
} catch (err) {
return { error: 'Could not sign the data. ' + err.stack }
}
}
async function recoverAddress(signature) {
try {
console.log("STRING:", signature)
let signatureObject = JSON.parse(signature)
console.log("OBJECT:", signatureObject)
let web3 = new Web3()
let address = web3.eth.accounts.recover(signatureObject)
return {
address: address,
result: 'Ok'
}
} catch (err) {
return { error: 'Could not recover address. ' + err.stack }
}
}
}
@@ -11,7 +11,7 @@ function newEthereumFunctionLibraryAccounts() {
let params = {
method: 'createWalletAccount',
entropy: walletAccountNode.id
entropy: walletAccountNode.id + (new Date()).valueOf()
}
let url = 'WEB3' // we don't need to ask this to any specific superalgos node.
@@ -52,7 +52,7 @@
},
{
"style": "Javascript",
"text": "UI.projects.foundations.utilities.nodeConfig.savePropertyAtNodeConfig(node.payload,'showPanels', true)"
"text": "UI.projects.foundations.utilities.nodeConfig.saveConfigProperty(node.payload,'showPanels', true)"
},
{
"style": "Text",
@@ -30,6 +30,10 @@ function newUiObject() {
hasInfo: undefined,
valueAtAngle: true,
valueAngleOffset: 0,
percentageAtAngle: true,
percentageAngleOffset: 0,
statusAtAngle: true,
statusAngleOffset: 0,
run: run,
stop: stop,
heartBeat: heartBeat,
@@ -1887,13 +1891,13 @@ function newUiObject() {
label = label.substring(0, MAX_LABEL_LENGTH) + '...'
}
if (thisObject.valueAtAngle === true && thisObject.payload.angle !== undefined) {
if (thisObject.percentageAtAngle === true && thisObject.payload.angle !== undefined) {
labelPoint = {
x: position.x - getTextWidth(label) / 2,
y: position.y
}
labelPoint.x = labelPoint.x + radius * 7 / 3 * Math.cos(toRadians(thisObject.payload.angle + thisObject.valueAngleOffset))
labelPoint.y = labelPoint.y + radius * 7 / 3 * Math.sin(toRadians(thisObject.payload.angle + thisObject.valueAngleOffset)) + lineSeparator * 1
labelPoint.x = labelPoint.x + radius * 7 / 3 * Math.cos(toRadians(thisObject.payload.angle + thisObject.percentageAngleOffset))
labelPoint.y = labelPoint.y + radius * 7 / 3 * Math.sin(toRadians(thisObject.payload.angle + thisObject.percentageAngleOffset)) + lineSeparator * 1
} else {
if (thisObject.isOnFocus === true) {
labelPoint = {
@@ -1948,15 +1952,25 @@ function newUiObject() {
label = label.substring(0, MAX_LABEL_LENGTH) + '...'
}
if (thisObject.isOnFocus === true) {
if (thisObject.statusAtAngle === true && thisObject.payload.angle !== undefined) {
labelPoint = {
x: position.x - getTextWidth(label) / 2,
y: position.y + radius * 2 / 3 + lineSeparator * 4 + 30
y: position.y
}
labelPoint.x = labelPoint.x + radius * 7 / 3 * Math.cos(toRadians(thisObject.payload.angle + thisObject.statusAngleOffset))
labelPoint.y = labelPoint.y + radius * 7 / 3 * Math.sin(toRadians(thisObject.payload.angle + thisObject.statusAngleOffset)) + lineSeparator * 2
} else {
labelPoint = {
x: position.x - getTextWidth(label) / 2,
y: position.y + thisObject.payload.floatingObject.currentImageSize / 2 + lineSeparator * 4
if (thisObject.isOnFocus === true) {
labelPoint = {
x: position.x - getTextWidth(label) / 2,
y: position.y + radius * 2 / 3 + lineSeparator * 4 + 30
}
} else {
labelPoint = {
x: position.x - getTextWidth(label) / 2,
y: position.y + thisObject.payload.floatingObject.currentImageSize / 2 + lineSeparator * 4
}
}
}
@@ -511,7 +511,7 @@ function newLayer() {
}
}
} else {
UI.projects.foundations.utilities.nodeConfig.savePropertyAtNodeConfig(thisObject.payload, 'showPanels', panelsVisibleButton.showPanels)
UI.projects.foundations.utilities.nodeConfig.saveConfigProperty(thisObject.payload, 'showPanels', panelsVisibleButton.showPanels)
}
}
}
@@ -560,7 +560,7 @@ function newLayer() {
}
}
UI.projects.foundations.utilities.nodeConfig.savePropertyAtNodeConfig(thisObject.payload, 'status', thisObject.status)
UI.projects.foundations.utilities.nodeConfig.saveConfigProperty(thisObject.payload, 'status', thisObject.status)
let eventData = thisObject
thisObject.container.eventHandler.raiseEvent('Status Changed', eventData)
}
@@ -114,7 +114,7 @@ function newLayersPanel() {
}
function saveObjectStateVisibleLayers() {
UI.projects.foundations.utilities.nodeConfig.savePropertyAtNodeConfig(thisObject.payload, 'visibleLayers', desiredVisibleLayers)
UI.projects.foundations.utilities.nodeConfig.saveConfigProperty(thisObject.payload, 'visibleLayers', desiredVisibleLayers)
}
function saveObjectStatePanelLocation() {
@@ -122,7 +122,7 @@ function newLayersPanel() {
upOrDown: thisObject.upDownButton.status,
leftOrRight: thisObject.leftRightButton.status
}
UI.projects.foundations.utilities.nodeConfig.savePropertyAtNodeConfig(thisObject.payload, 'panelLocation', panelLocation)
UI.projects.foundations.utilities.nodeConfig.saveConfigProperty(thisObject.payload, 'panelLocation', panelLocation)
}
function readObjectState() {
@@ -1,12 +1,12 @@
function newFoundationsUtilitiesNodeConfig() {
let thisObject = {
savePropertyAtNodeConfig: savePropertyAtNodeConfig,
saveConfigProperty: saveConfigProperty,
loadConfigProperty: loadConfigProperty
}
return thisObject
function savePropertyAtNodeConfig(payload, propertyName, value) {
function saveConfigProperty(payload, propertyName, value) {
try {
let config = JSON.parse(payload.node.config)
config[propertyName] = value
Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

@@ -424,7 +424,7 @@
{
"type": "Pool",
"name": "User Referrals",
"config": "{\n \"codeName\": \"User-Referrals\"\n}",
"config": "{\n \"codeName\": \"Referral-Program\"\n}",
"project": "Governance",
"poolClasses": [],
"pools": [],
@@ -3,399 +3,246 @@
"name": "Julian-Molina",
"config": "{\n \"codeName\": \"\",\n \"tokens\": 500000\n}",
"project": "Governance",
"contributionClaims": {
"type": "Contribution Claims",
"name": "New Contribution Claims",
"tokenSwitch": {
"type": "Token Switch",
"name": "New Token Switch",
"config": "{}",
"project": "Governance",
"assetContributionsFolder": [
{
"type": "Asset Contributions Folder",
"name": "Tutorials",
"referralProgram": {
"type": "Referral Program",
"name": "New Referral Program",
"config": "{}",
"project": "Governance",
"userReferrer": {
"type": "User Referrer",
"name": "Jeremy",
"config": "{}",
"project": "Governance",
"assetContributionsFolder": [
{
"type": "Asset Contributions Folder",
"name": "Tutorials Created",
"config": "{}",
"project": "Governance",
"assetContributionsFolder": [],
"assetContributionClaims": [
{
"type": "Asset Contribution Claim",
"name": "",
"config": "{\n \"description\": \"\"\n}",
"project": "Governance",
"id": "b62215fd-405b-4b81-a446-d667de2fd23b",
"savedPayload": {
"position": {
"x": 26082.78190893733,
"y": 22758.100619195047
},
"targetPosition": {
"x": 25822.974287801997,
"y": 22908.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {},
"referenceParent": {
"type": "Asset",
"name": "Getting Started Tutorial",
"id": "6c3f251e-cb80-42b7-935b-23bcbe218f97"
}
}
}
],
"id": "30c01eef-80cf-4fb8-9231-af6694be0af9",
"savedPayload": {
"position": {
"x": 25822.974287801997,
"y": 22908.100619195047
},
"targetPosition": {
"x": 25563.166666666664,
"y": 23058.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
},
{
"type": "Asset Contributions Folder",
"name": "Tutorials Mantainance",
"config": "{}",
"project": "Governance",
"assetContributionsFolder": [],
"assetContributionClaims": [
{
"type": "Asset Contribution Claim",
"name": "",
"config": "{\n \"description\": \"\"\n}",
"project": "Governance",
"id": "4a841aaa-0730-4783-91be-87d718ee4e15",
"savedPayload": {
"position": {
"x": 26082.78190893733,
"y": 23358.100619195047
},
"targetPosition": {
"x": 25822.974287801997,
"y": 23208.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {},
"referenceParent": {
"type": "Asset",
"name": "Getting Started Tutorial",
"id": "6c3f251e-cb80-42b7-935b-23bcbe218f97"
}
}
}
],
"id": "03cd14ee-432e-4c7c-b2b0-79dc24d07820",
"savedPayload": {
"position": {
"x": 25822.974287801997,
"y": 23208.100619195047
},
"targetPosition": {
"x": 25563.166666666664,
"y": 23058.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
}
],
"assetContributionClaims": [],
"id": "9318707a-afa0-4c84-8028-473eb448f96b",
"id": "0d0b04ff-034b-4b02-8351-67d621d514c0",
"savedPayload": {
"position": {
"x": 25563.166666666664,
"y": 23058.100619195047
"x": 25532.618466191747,
"y": 23465.846712854385
},
"targetPosition": {
"x": 25263.166666666664,
"y": 23058.100619195047
"x": 25233.45732703739,
"y": 23488.265740930314
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
"uiObject": {},
"referenceParent": {
"type": "User Profile",
"name": "Jeremy",
"id": "759e9012-c995-47ed-92f1-7d204bf2b58e"
}
}
}
],
"featureContributionsFolder": [],
"positionContributionsFolder": [],
"id": "43a4118b-fc68-46a9-a7d8-fa4baafa5ad6",
"savedPayload": {
"position": {
"x": 25263.166666666664,
"y": 23058.100619195047
},
"targetPosition": {
"x": 24963.166666666664,
"y": 23058.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
},
"votesDistribution": {
"type": "Votes Distribution",
"name": "New Votes Distribution",
"config": "{\n\"codeName\": \"\"\n}",
"project": "Governance",
"votesSwitch": [
{
"type": "Votes Switch",
"name": "Test",
"config": "{\n \"description\": \"\"\n}",
"tokensAwarded": {
"type": "Tokens Awarded",
"name": "New Tokens Awarded",
"project": "Governance",
"votesSwitch": [],
"claimVotesSwitch": [
{
"type": "Claim Votes Switch",
"name": "New Claim Votes Switch",
"config": "{}",
"project": "Governance",
"claimVotesSwitch": [],
"positionClaimVotes": [
{
"type": "Position Claim Vote",
"name": "Luis-Fernando-Molina Project Leader Superalgos",
"config": "{}",
"project": "Governance",
"id": "ab4d6901-a84c-44d3-a97a-7bc14de9ff31",
"savedPayload": {
"position": {
"x": 25113.166666666664,
"y": 23837.523482601046
},
"targetPosition": {
"x": 24813.166666666664,
"y": 23837.523482601046
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {},
"referenceParent": {
"type": "Position Contribution Claim",
"name": "Project Leader Superalgos",
"id": "a2bb4366-f480-4685-80b0-e40af9cddd8c"
}
}
},
{
"type": "Position Claim Vote",
"name": "Luis-Fernando-Molina Project Leader Superalgos",
"config": "{}",
"project": "Governance",
"id": "2248b955-af4b-42e6-9649-9b6a689d0ade",
"savedPayload": {
"position": {
"x": 24663.166666666664,
"y": 24097.33110373638
},
"targetPosition": {
"x": 24813.166666666664,
"y": 23837.523482601046
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {},
"referenceParent": {
"type": "Position Contribution Claim",
"name": "Project Leader Superalgos",
"id": "be2aedec-06fd-41fa-8599-08105931f75f"
}
}
}
],
"assetClaimVotes": [],
"featureClaimVotes": [],
"id": "6029fd9b-94b4-4b62-960a-14fb88107cdb",
"savedPayload": {
"position": {
"x": 24813.166666666664,
"y": 23837.523482601046
},
"targetPosition": {
"x": 24663.166666666664,
"y": 23577.715861465713
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
}
],
"weightVotesSwitch": [
{
"type": "Weight Votes Switch",
"name": "New Weight Votes Switch",
"config": "{}",
"project": "Governance",
"weightVotesSwitch": [],
"poolWeightVotes": [],
"assetWeightVotes": [],
"featureWeightVotes": [],
"positionWeightVotes": [
{
"type": "Position Weight Vote",
"name": "Superalgos Project Leader",
"config": "{}",
"project": "Governance",
"id": "11a8ac12-eba4-472d-b44b-8783720f8c6a",
"savedPayload": {
"position": {
"x": 24063.166666666664,
"y": 23577.715861465713
},
"targetPosition": {
"x": 24363.166666666664,
"y": 23577.715861465713
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {},
"referenceParent": {
"type": "Position",
"name": "Project Leader",
"id": "5f694173-4568-46b2-a52c-4244320919f7"
}
}
}
],
"id": "d98792e3-620f-4827-b17f-74096a2fe5c8",
"savedPayload": {
"position": {
"x": 24363.166666666664,
"y": 23577.715861465713
},
"targetPosition": {
"x": 24663.166666666664,
"y": 23577.715861465713
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
}
],
"userProfileVotesSwitch": [],
"id": "f4127f8b-eb94-4e5e-aea9-71ea43ba5b5b",
"id": "208f866a-459d-4dd8-93ea-1a2b8bfa3dac",
"savedPayload": {
"position": {
"x": 24663.166666666664,
"y": 23577.715861465713
"x": 25402.453344456477,
"y": 23736.137373225112
},
"targetPosition": {
"x": 24813.166666666664,
"y": 23317.90824033038
"x": 25233.45732703739,
"y": 23488.265740930314
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
"uiObject": {}
}
},
"id": "a9ddce61-97b0-47e8-ad6c-e9438aca3913",
"savedPayload": {
"position": {
"x": 25233.45732703739,
"y": 23488.265740930314
},
"targetPosition": {
"x": 24963.166666666664,
"y": 23358.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
],
"id": "84b2e7e0-577a-4edc-98fd-003905decb99",
},
"mentorshipProgram": {
"type": "Mentorship Program",
"name": "New Mentorship Program",
"config": "{}",
"project": "Governance",
"userMentors": [],
"id": "362a1ecb-dce9-4ebb-9b00-a20d3631f2f3",
"savedPayload": {
"position": {
"x": 25150.213607224283,
"y": 23592.650063935456
},
"targetPosition": {
"x": 24963.166666666664,
"y": 23358.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
},
"supportProgram": {
"type": "Support Program",
"name": "New Support Program",
"config": "{}",
"project": "Governance",
"userSupports": [],
"id": "f1020b53-23d4-4fea-b5d3-5409e13197a9",
"savedPayload": {
"position": {
"x": 25029.92294685356,
"y": 23650.578992849594
},
"targetPosition": {
"x": 24963.166666666664,
"y": 23358.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
},
"votingProgram": {
"type": "Voting Program",
"name": "New Voting Program",
"config": "{}",
"project": "Governance",
"votesSwitch": [],
"id": "0b2863a0-d280-4a9a-9e2c-fe5bdbc54854",
"savedPayload": {
"position": {
"x": 24896.41038647977,
"y": 23650.578992849594
},
"targetPosition": {
"x": 24963.166666666664,
"y": 23358.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
},
"claimsProgram": {
"type": "Claims Program",
"name": "New Claims Program",
"config": "{}",
"project": "Governance",
"assetContributionsFolder": [],
"featureContributionsFolder": [],
"positionContributionsFolder": [],
"id": "bec9399a-9f85-4cb5-bff4-9938a3bc7ac4",
"savedPayload": {
"position": {
"x": 24776.119726109046,
"y": 23592.650063935456
},
"targetPosition": {
"x": 24963.166666666664,
"y": 23358.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
},
"stakingProgram": {
"type": "Staking Program",
"name": "New Staking Program",
"config": "{}",
"project": "Governance",
"id": "d66a7bf2-963a-4d28-b896-c41e83f610ae",
"savedPayload": {
"position": {
"x": 24692.876006295937,
"y": 23488.265740930314
},
"targetPosition": {
"x": 24963.166666666664,
"y": 23358.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
},
"id": "86a8ca4c-76d4-4eb0-9acb-5650095c6667",
"savedPayload": {
"position": {
"x": 24813.166666666664,
"y": 23317.90824033038
"x": 24963.166666666664,
"y": 23358.100619195047
},
"targetPosition": {
"x": 24963.166666666664,
@@ -405,7 +252,7 @@
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
@@ -414,37 +261,6 @@
}
}
},
"userReferrer": {
"type": "User Referrer",
"name": "Luis-Fernando-Molina",
"config": "{\n \"description\": \"\"\n}",
"project": "Governance",
"id": "edf7bcda-23f6-49bb-b9b2-9a34edcb4a40",
"savedPayload": {
"position": {
"x": 24813.166666666664,
"y": 22798.292998059715
},
"targetPosition": {
"x": 24963.166666666664,
"y": 23058.100619195047
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 1,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {},
"referenceParent": {
"type": "User Profile",
"name": "Luis-Fernando-Molina",
"id": "148911b3-b2f3-44fb-8cb4-017991789132"
}
}
},
"id": "1fd95e41-4b22-48d5-be3a-904c37afcb11",
"savedPayload": {
"position": {
@@ -458,8 +274,8 @@
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": true,
"angleToParent": 1,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
File diff suppressed because it is too large. Load diff
@@ -198,9 +198,9 @@
"name": "Julian-Molina",
"config": "{\n \"codeName\": \"\",\n \"tokens\": 500000\n}",
"project": "Governance",
"contributionClaims": {
"type": "Contribution Claims",
"name": "New Contribution Claims",
"claimsProgram": {
"type": "Claims Program",
"name": "New Claims Program",
"config": "{}",
"project": "Governance",
"assetContributionsFolder": [
@@ -385,9 +385,9 @@
}
}
},
"votesDistribution": {
"type": "Votes Distribution",
"name": "New Votes Distribution",
"votingProgram": {
"type": "Voting Program",
"name": "New Voting Program",
"config": "{\n\"codeName\": \"\"\n}",
"project": "Governance",
"votesSwitch": [
@@ -0,0 +1,21 @@
{
"type": "Tokens Awarded",
"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": "->Referral Program->Mentorship Program->Support Program->Voting Program->Claims Program->Staking Program->"
},
"propertyNameAtParent": "tokensAwarded"
}
@@ -42,7 +42,7 @@
"addLeftIcons": true,
"level": 2,
"attachingRules": {
"compatibleTypes": "->Contribution Claims->Asset Contributions Folder->"
"compatibleTypes": "->Claims Program->Asset Contributions Folder->"
},
"propertyNameAtParent": "assetContributionsFolder",
"childrenNodesProperties": [
@@ -1,5 +1,5 @@
{
"type": "Contribution Claims",
"type": "Claims Program",
"menuItems": [
{
"action": "Configure",
@@ -29,6 +29,15 @@
"label": "Add Position Contributions Folder",
"relatedUiObject": "Position Contributions Folder"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "tokensAwarded",
"actionFunction": "payload.executeAction",
"label": "Add Tokens Awarded",
"relatedUiObject": "Tokens Awarded"
},
{
"action": "Delete UI Object",
"actionProject": "Foundations",
@@ -47,11 +56,11 @@
"config": "{}"
},
"attachingRules": {
"compatibleTypes": "->User Profile->"
"compatibleTypes": "->Token Switch->"
},
"addLeftIcons": true,
"level": 1,
"propertyNameAtParent": "contributionClaims",
"propertyNameAtParent": "claimsProgram",
"childrenNodesProperties": [
{
"name": "assetContributionsFolder",
@@ -70,6 +79,12 @@
"type": "array",
"childType": "Position Contributions Folder",
"autoAdd": false
},
{
"name": "tokensAwarded",
"type": "node",
"childType": "Tokens Awarded",
"autoAdd": true
}
]
}
@@ -42,7 +42,7 @@
"addLeftIcons": true,
"level": 2,
"attachingRules": {
"compatibleTypes": "->Contribution Claims->Feature Contributions Folder->"
"compatibleTypes": "->Claims Program->Feature Contributions Folder->"
},
"propertyNameAtParent": "featureContributionsFolder",
"childrenNodesProperties": [
@@ -36,6 +36,13 @@
"relatedUiObject": "User Profile",
"actionFunction": "payload.executeAction"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"actionFunction": "payload.executeAction",
"label": "Add Profile Constructor",
"relatedUiObject": "Profile Constructor"
},
{
"action": "Delete UI Object",
"actionProject": "Foundations",
@@ -0,0 +1,64 @@
{
"type": "Mentorship Program",
"menuItems": [
{
"action": "Configure",
"actionFunction": "uiObject.configEditor.activate",
"label": "Configure",
"iconPathOn": "configuration",
"iconPathOff": "configuration"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"actionFunction": "payload.executeAction",
"label": "Add User Mentor",
"relatedUiObject": "User Mentor"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "tokensAwarded",
"actionFunction": "payload.executeAction",
"label": "Add Tokens Awarded",
"relatedUiObject": "Tokens Awarded"
},
{
"action": "Delete UI Object",
"actionProject": "Foundations",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity",
"actionFunction": "payload.executeAction"
}
],
"editors": {
"config": true
},
"initialValues": {
"config": "{}"
},
"attachingRules": {
"compatibleTypes": "->Token Switch->"
},
"addLeftIcons": true,
"level": 1,
"propertyNameAtParent": "mentorshipProgram",
"childrenNodesProperties": [
{
"name": "userMentors",
"type": "array",
"childType": "User Mentor",
"autoAdd": false
},
{
"name": "tokensAwarded",
"type": "node",
"childType": "Tokens Awarded",
"autoAdd": true
}
]
}
@@ -42,7 +42,7 @@
"addLeftIcons": true,
"level": 2,
"attachingRules": {
"compatibleTypes": "->Contribution Claims->Position Contributions Folder->"
"compatibleTypes": "->Claims Program->Position Contributions Folder->"
},
"propertyNameAtParent": "positionContributionsFolder",
"childrenNodesProperties": [
@@ -0,0 +1,44 @@
{
"type": "Profile Constructor",
"menuItems": [
{
"action": "Configure",
"actionFunction": "uiObject.configEditor.activate",
"label": "Configure",
"iconPathOn": "configuration",
"iconPathOff": "configuration"
},
{
"action": "Build Profile",
"actionProject": "Governance",
"label": "Build Profile",
"askConfirmation": true,
"confirmationLabel": "Confirm to Proceed",
"workDoneLabel": "Done",
"relatedUiObject": "Profile Constructor",
"actionFunction": "payload.executeAction"
},
{
"action": "Delete UI Object",
"actionProject": "Foundations",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity",
"actionFunction": "payload.executeAction"
}
],
"isHierarchyHead": true,
"editors": {
"config": true
},
"initialValues": {
"config": "{ \"githubUsername\": \"\"}"
},
"addLeftIcons": true,
"level": 2,
"referencingRules": {
"compatibleTypes": "->User Profile->"
}
}
@@ -0,0 +1,66 @@
{
"type": "Referral Program",
"menuItems": [
{
"action": "Configure",
"actionFunction": "uiObject.configEditor.activate",
"label": "Configure",
"iconPathOn": "configuration",
"iconPathOff": "configuration"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "userReferrer",
"actionFunction": "payload.executeAction",
"label": "Add User Referrer",
"relatedUiObject": "User Referrer"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "tokensAwarded",
"actionFunction": "payload.executeAction",
"label": "Add Tokens Awarded",
"relatedUiObject": "Tokens Awarded"
},
{
"action": "Delete UI Object",
"actionProject": "Foundations",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity",
"actionFunction": "payload.executeAction"
}
],
"editors": {
"config": true
},
"initialValues": {
"config": "{}"
},
"attachingRules": {
"compatibleTypes": "->Token Switch->"
},
"addLeftIcons": true,
"level": 1,
"propertyNameAtParent": "referralProgram",
"childrenNodesProperties": [
{
"name": "userReferrer",
"type": "node",
"childType": "User Referrer",
"autoAdd": true
},
{
"name": "tokensAwarded",
"type": "node",
"childType": "Tokens Awarded",
"autoAdd": true
}
]
}
@@ -0,0 +1,51 @@
{
"type": "Staking Program",
"menuItems": [
{
"action": "Configure",
"actionFunction": "uiObject.configEditor.activate",
"label": "Configure",
"iconPathOn": "configuration",
"iconPathOff": "configuration"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "tokensAwarded",
"actionFunction": "payload.executeAction",
"label": "Add Tokens Awarded",
"relatedUiObject": "Tokens Awarded"
},
{
"action": "Delete UI Object",
"actionProject": "Foundations",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity",
"actionFunction": "payload.executeAction"
}
],
"editors": {
"config": true
},
"initialValues": {
"config": "{}"
},
"attachingRules": {
"compatibleTypes": "->Token Switch->"
},
"addLeftIcons": true,
"level": 1,
"propertyNameAtParent": "stakingProgram",
"childrenNodesProperties": [
{
"name": "tokensAwarded",
"type": "node",
"childType": "Tokens Awarded",
"autoAdd": true
}
]
}
@@ -0,0 +1,64 @@
{
"type": "Support Program",
"menuItems": [
{
"action": "Configure",
"actionFunction": "uiObject.configEditor.activate",
"label": "Configure",
"iconPathOn": "configuration",
"iconPathOff": "configuration"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"actionFunction": "payload.executeAction",
"label": "Add User Support",
"relatedUiObject": "User Support"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "tokensAwarded",
"actionFunction": "payload.executeAction",
"label": "Add Tokens Awarded",
"relatedUiObject": "Tokens Awarded"
},
{
"action": "Delete UI Object",
"actionProject": "Foundations",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity",
"actionFunction": "payload.executeAction"
}
],
"editors": {
"config": true
},
"initialValues": {
"config": "{}"
},
"attachingRules": {
"compatibleTypes": "->Token Switch->"
},
"addLeftIcons": true,
"level": 1,
"propertyNameAtParent": "supportProgram",
"childrenNodesProperties": [
{
"name": "userSupports",
"type": "array",
"childType": "User Support",
"autoAdd": false
},
{
"name": "tokensAwarded",
"type": "node",
"childType": "Tokens Awarded",
"autoAdd": true
}
]
}
@@ -0,0 +1,126 @@
{
"type": "Token Switch",
"menuItems": [
{
"action": "Configure",
"actionFunction": "uiObject.configEditor.activate",
"label": "Configure",
"iconPathOn": "configuration",
"iconPathOff": "configuration"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"actionFunction": "payload.executeAction",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "referralProgram",
"label": "Add Referral Program",
"relatedUiObject": "Referral Program"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"actionFunction": "payload.executeAction",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "mentorshipProgram",
"label": "Add Mentorship Program",
"relatedUiObject": "Mentorship Program"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"actionFunction": "payload.executeAction",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "supportProgram",
"label": "Add Support Program",
"relatedUiObject": "Support Program"
},
{
"action": "Add UI Object",
"actionProject": "Voting Program",
"actionFunction": "payload.executeAction",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "votingProgram",
"label": "Add Voting Program",
"relatedUiObject": "Voting Program"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"actionFunction": "payload.executeAction",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "claimsProgram",
"label": "Add Claims Program",
"relatedUiObject": "Claims Program"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"actionFunction": "payload.executeAction",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "stakingProgram",
"label": "Add Staking Program",
"relatedUiObject": "Staking Program"
},
{
"action": "Delete UI Object",
"actionProject": "Foundations",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity",
"actionFunction": "payload.executeAction"
}
],
"editors": {
"config": true
},
"initialValues": {
"config": "{}"
},
"addLeftIcons": true,
"level": 2,
"attachingRules": {
"compatibleTypes": "->User Profile->"
},
"propertyNameAtParent": "tokenSwitch",
"childrenNodesProperties": [
{
"name": "referralProgram",
"type": "node",
"childType": "Referral Program",
"autoAdd": true
},
{
"name": "mentorshipProgram",
"type": "node",
"childType": "Mentorship Program",
"autoAdd": true
},
{
"name": "supportProgram",
"type": "node",
"childType": "Support Program",
"autoAdd": true
},
{
"name": "votingProgram",
"type": "node",
"childType": "Voting Program",
"autoAdd": true
},
{
"name": "claimsProgram",
"type": "node",
"childType": "Claims Program",
"autoAdd": true
},
{
"name": "stakingProgram",
"type": "node",
"childType": "Staking Program",
"autoAdd": true
}
]
}
@@ -0,0 +1,40 @@
{
"type": "User Mentor",
"menuItems": [
{
"action": "Configure",
"actionFunction": "uiObject.configEditor.activate",
"label": "Configure",
"iconPathOn": "configuration",
"iconPathOff": "configuration"
},
{
"action": "Delete UI Object",
"actionProject": "Foundations",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity",
"actionFunction": "payload.executeAction"
}
],
"title": [
"Use Reference Parent"
],
"editors": {
"config": true
},
"initialValues": {
"config": "{}"
},
"addLeftIcons": true,
"level": 2,
"attachingRules": {
"compatibleTypes": "->mentorship Program->"
},
"referencingRules": {
"compatibleTypes": "->User Profile->"
},
"propertyNameAtParent": "userMentors"
}
@@ -12,28 +12,10 @@
"action": "Add UI Object",
"actionProject": "Foundations",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "contributionClaims",
"propertyToCheckFor": "tokenSwitch",
"actionFunction": "payload.executeAction",
"label": "Add Contribution Claims",
"relatedUiObject": "Contribution Claims"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "votesDistribution",
"actionFunction": "payload.executeAction",
"label": "Add Votes Distribution",
"relatedUiObject": "Votes Distribution"
},
{
"action": "Add UI Object",
"actionProject": "Foundations",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "userReferrer",
"actionFunction": "payload.executeAction",
"label": "Add User Referrer",
"relatedUiObject": "User Referrer"
"label": "Add Token Switch",
"relatedUiObject": "Token Switch"
},
{
"action": "Delete UI Object",
@@ -50,7 +32,7 @@
"config": true
},
"initialValues": {
"config": "{\n\"codeName\": \"\"\n}"
"config": "{}"
},
"isTitleAllwaysVisible": false,
"isHierarchyHead": true,
@@ -58,22 +40,10 @@
"level": 0,
"childrenNodesProperties": [
{
"name": "contributionClaims",
"name": "tokenSwitch",
"type": "node",
"childType": "Contribution Claims",
"autoAdd": false
},
{
"name": "votesDistribution",
"type": "node",
"childType": "Votes Distribution",
"autoAdd": false
},
{
"name": "userReferrer",
"type": "node",
"childType": "User Referrer",
"autoAdd": false
"childType": "Token Switch",
"autoAdd": true
}
]
}
@@ -26,12 +26,12 @@
"config": true
},
"initialValues": {
"config": "{\n \"description\": \"\"\n}"
"config": "{}"
},
"addLeftIcons": true,
"level": 2,
"attachingRules": {
"compatibleTypes": "->User Profile->"
"compatibleTypes": "->Referral Program->"
},
"referencingRules": {
"compatibleTypes": "->User Profile->"
@@ -0,0 +1,40 @@
{
"type": "User Support",
"menuItems": [
{
"action": "Configure",
"actionFunction": "uiObject.configEditor.activate",
"label": "Configure",
"iconPathOn": "configuration",
"iconPathOff": "configuration"
},
{
"action": "Delete UI Object",
"actionProject": "Foundations",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity",
"actionFunction": "payload.executeAction"
}
],
"title": [
"Use Reference Parent"
],
"editors": {
"config": true
},
"initialValues": {
"config": "{}"
},
"addLeftIcons": true,
"level": 2,
"attachingRules": {
"compatibleTypes": "->support Program->"
},
"referencingRules": {
"compatibleTypes": "->User Profile->"
},
"propertyNameAtParent": "userSupports"
}
@@ -65,7 +65,7 @@
"addLeftIcons": true,
"level": 2,
"attachingRules": {
"compatibleTypes": "->Votes Distribution->Votes Switch->"
"compatibleTypes": "->Voting Program->Votes Switch->"
},
"propertyNameAtParent": "votesSwitch",
"childrenNodesProperties": [
@@ -1,5 +1,5 @@
{
"type": "Votes Distribution",
"type": "Voting Program",
"menuItems": [
{
"action": "Configure",
@@ -19,10 +19,10 @@
"action": "Add UI Object",
"actionProject": "Foundations",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "userReferrer",
"propertyToCheckFor": "tokensAwarded",
"actionFunction": "payload.executeAction",
"label": "Add User Referrer",
"relatedUiObject": "User Referrer"
"label": "Add Tokens Awarded",
"relatedUiObject": "Tokens Awarded"
},
{
"action": "Delete UI Object",
@@ -42,17 +42,23 @@
"config": "{}"
},
"attachingRules": {
"compatibleTypes": "->User Profile->"
"compatibleTypes": "->Token Switch->"
},
"addLeftIcons": true,
"level": 1,
"propertyNameAtParent": "votesDistribution",
"propertyNameAtParent": "votingProgram",
"childrenNodesProperties": [
{
"name": "votesSwitch",
"type": "array",
"childType": "Votes Switch",
"autoAdd": false
},
{
"name": "tokensAwarded",
"type": "node",
"childType": "Tokens Awarded",
"autoAdd": true
}
]
}
@@ -1,5 +1,5 @@
{
"type": "Contribution Claims",
"type": "Claims Program",
"definition": {
"text": "This node helps define the section of the User Profiel hierarchy that is going to be used to define the claims users make for the contributions they have done. These claims need later to be voted by other users in order to be considered during the token distribution process.",
"updated": 1622989461838
@@ -1,7 +1,7 @@
{
"type": "User Profile",
"definition": {
"text": "At these hierarchies, users define their profile, which essentially means declaring which are their contribution claims, and which is the way they would like to distribute their voting power. From each user profile starts a stream of votes that flows through switches that split these streams according to the user preferences and end up at other hierarchies's nodes, who are the recipient of these votes. ",
"text": "At these hierarchies, users define their profile, which essentially means declaring which are their Claims Program, and which is the way they would like to distribute their voting power. From each user profile starts a stream of votes that flows through switches that split these streams according to the user preferences and end up at other hierarchies's nodes, who are the recipient of these votes. ",
"updated": 1622988108578
},
"paragraphs": [
@@ -1,5 +1,5 @@
{
"type": "Votes Distribution",
"type": "Voting Program",
"definition": {
"text": "This node defined the section where votes are going to flow like vote-streams, going through Votes Swithces and several different types of Vote nodes. Via references they are later sent to recipient nodes living at other hierarchies.",
"updated": 1622989230849
@@ -28,6 +28,11 @@ function newGovernanceActionSwitch() {
UI.projects.governance.functionLibraries.votes.installVotes(action.node, action.rootNodes)
break
}
case 'Build Profile':
{
UI.projects.governance.functionLibraries.profileConstructor.buildProfile(action.node, action.rootNodes)
break
}
case 'Add Missing Plugin User Profiles':
{
UI.projects.governance.functionLibraries.pluginsFunctions.addMissingPluginUserProfiles(action.node, action.rootNodes)
@@ -40,13 +40,13 @@ function newGovernanceFunctionLibraryClaims() {
},
count: 0
}
countForNode(userProfilesNode.contributionClaims)
countForNode(userProfilesNode.claimsProgram)
}
/* Claim Calculation Follows */
for (let i = 0; i < userProfiles.length; i++) {
let userProfilesNode = userProfiles[i]
calculateForNode(userProfilesNode.contributionClaims, userProfilesNode)
calculateForNode(userProfilesNode.claimsProgram, userProfilesNode)
}
}
@@ -102,7 +102,7 @@ function newGovernanceFunctionLibraryClaims() {
node.type !== 'Asset Contributions Folder' &&
node.type !== 'Feature Contributions Folder' &&
node.type !== 'Position Contributions Folder' &&
node.type !== 'Contribution Claims'
node.type !== 'Claims Program'
) {
if (node.payload.claims === undefined) {
node.payload.claims = {
@@ -170,7 +170,7 @@ function newGovernanceFunctionLibraryClaims() {
node.type !== 'Asset Contributions Folder' &&
node.type !== 'Feature Contributions Folder' &&
node.type !== 'Position Contributions Folder' &&
node.type !== 'Contribution Claims'
node.type !== 'Claims Program'
) {
if (
node.payload.claims !== undefined &&
@@ -13,6 +13,10 @@ function newGovernanceFunctionLibraryDistributionProcess() {
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(
userProfiles
)
UI.projects.governance.functionLibraries.votes.calculate(
pools,
features,
@@ -0,0 +1,97 @@
function newGovernanceFunctionLibraryProfileConstructor() {
let thisObject = {
buildProfile: buildProfile
}
return thisObject
function buildProfile(
node,
rootNodes
) {
/*
Some validations first...
*/
if (node.payload.referenceParent === undefined) {
node.payload.uiObject.setErrorMessage("You need to reference the node that contains the data to be signed.")
return
}
let data = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'githubUsername')
if (data === undefined || data === "") {
node.payload.referenceParent.payload.uiObject.setErrorMessage("githubUsername config property missing.")
return
}
createNewAccount()
signUserProfileData()
function createNewAccount() {
let params = {
method: 'createWalletAccount',
entropy: node.id + (new Date()).valueOf()
}
let url = 'WEB3' // we don't need to ask this to any specific superalgos node.
httpRequest(JSON.stringify(params), url, onResponse)
function onResponse(err, data) {
/* Lets check the result of the call through the http interface */
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
node.payload.uiObject.setErrorMessage('Call via HTTP Interface failed.')
walletAccountNode.payload.uiObject.menu.internalClick('Delete UI Object')
return
}
let response = JSON.parse(data)
/* Lets check the result of the method call */
if (response.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
node.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + response.error)
return
}
UI.projects.foundations.utilities.nodeConfig.saveConfigProperty(node.payload, 'address', response.address)
UI.projects.foundations.utilities.nodeConfig.saveConfigProperty(node.payload, 'privateKey', response.privateKey)
}
}
function signUserProfileData() {
let privateKey = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'privateKey')
if (privateKey === undefined || privateKey === "") { return }
let request = {
url: 'WEB3',
params: {
method: "signData",
privateKey: privateKey,
data: data
}
}
httpRequest(JSON.stringify(request.params), request.url, onResponse)
function onResponse(err, data) {
/* Lets check the result of the call through the http interface */
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
node.payload.uiObject.setErrorMessage('Call via HTTP Interface failed.')
return
}
let response = JSON.parse(data)
/* Lets check the result of the method call */
if (response.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
node.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + response.error)
console.log('Call to WEB3 Server failed. ' + response.error)
return
}
UI.projects.foundations.utilities.nodeConfig.saveConfigProperty(node.payload.referenceParent.payload, 'signature', response.signature)
node.payload.uiObject.setInfoMessage("Profile Account has been successfully created.")
}
}
}
}
@@ -0,0 +1,250 @@
function newGovernanceFunctionLibraryTokenPower() {
let thisObject = {
calculate: calculate
}
return thisObject
function calculate(
userProfiles
) {
/*
We will first reset all the token power, and then distribute it to each Program.
*/
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
resetTokenPower(userProfile)
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
distributeForProfile(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 }
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]
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
}
}
}
}
}
function distributeForProfile(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.tokenSwitch === undefined) {
userProfile.payload.uiObject.setErrorMessage("You need to have a Token Switch child node.")
return
}
if (userProfile.tokenSwitch.referralProgram === undefined) {
userProfile.tokenSwitch.payload.uiObject.setErrorMessage("You need to have a Referral Program child node.")
return
}
if (userProfile.tokenSwitch.mentorshipProgram === undefined) {
userProfile.tokenSwitch.payload.uiObject.setErrorMessage("You need to have a Mentorship Program child node.")
return
}
if (userProfile.tokenSwitch.supportProgram === undefined) {
userProfile.tokenSwitch.payload.uiObject.setErrorMessage("You need to have a Spupport Program 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'
) { 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]
if (childNode === undefined) { continue }
let percentage = getPercentage(childNode)
if (percentage !== undefined && isNaN(percentage) !== true) {
totalPercentage = totalPercentage + percentage
} else {
totalNodesWithoutPercentage++
}
}
}
break
}
}
}
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 }
let percentage = getPercentage(childNode)
if (percentage === undefined || isNaN(percentage) === true) {
percentage = defaultPercentage
}
distributeTokenPower(childNode, tokenPower * percentage / 100, percentage)
}
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)
}
}
break
}
}
}
}
}
function getPercentage(node) {
/*
There are some system wide rules regarfing mandatory percentages,
we will apply them now.
*/
switch (node.type) {
case 'Referral Program': {
return 20
}
case 'Mentorship Program': {
return 10
}
case 'Support Program': {
return 10
}
default: return UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'percentage')
}
}
function drawTokenPower(node, tokenPower, percentage) {
tokenPower = new Intl.NumberFormat().format(tokenPower) + ' ' + '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.setValue(tokenPower)
if (percentage !== undefined) {
node.payload.uiObject.percentageAngleOffset = 180
node.payload.uiObject.percentageAtAngle = true
node.payload.uiObject.setPercentage(percentage.toFixed(2))
}
}
}
}
}
@@ -71,7 +71,7 @@ function newGovernanceFunctionLibraryTokens() {
switch (property.type) {
case 'node': {
if (node.type === 'Pools' && property.name === "votesDistribution") {
if (node.type === 'Pools' && property.name === "votingProgram") {
let childNode = node[property.name]
resetTokenFlow(childNode)
}
@@ -142,7 +142,7 @@ function newGovernanceFunctionLibraryTokens() {
switch (property.type) {
case 'node': {
if (node.type === 'Pools' && property.name === "votesDistribution") {
if (node.type === 'Pools' && property.name === "votingProgram") {
let childNode = node[property.name]
distributeTokens(childNode, tokens)
}
@@ -9,29 +9,55 @@ function newGovernanceFunctionLibraryUserReferrals() {
pools,
userProfiles
) {
let tokensReward
let totalReferralsPower = 0
/*
Here we will store the total amount of tokens that is going to be distributed among all participants
of the Referral Program. This will come from a Pool that is configured wiht a codeName config property
with the value "Referral-Program"
*/
let referralProgramPoolTokenReward
/*
In order to be able to calculate the share of the Referrals Program Pool for each User Profile,
we need to accumulate all the Icomming Referral Power that each User Profile at their Referral Program
node has, because with that Incoming Power is that each Referral Program node gets a share of
the pool.
*/
let accumulatedIncomingReferralPower = 0
/* Scan Pools Until finding the User-Referrlas Pool */
for (let i = 0; i < pools.length; i++) {
let poolsNode = pools[i]
findPool(poolsNode)
}
if (tokensReward === undefined || tokensReward === 0) { return }
if (referralProgramPoolTokenReward === undefined || referralProgramPoolTokenReward === 0) { return }
/*
We will first reset all the referral combinedPower, and then distribute it.
We will first reset all the referral outgoingPower, and then distribute it.
*/
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
resetUserReferrals(userProfile)
if (userProfile.tokenSwitch === undefined) { continue }
if (userProfile.tokenSwitch.referralProgram === undefined) { continue }
if (userProfile.tokenSwitch.referralProgram.payload === undefined) { continue }
resetUserReferrals(userProfile.tokenSwitch.referralProgram)
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
distributeForProfile(userProfile)
if (userProfile.tokenSwitch === undefined) { continue }
if (userProfile.tokenSwitch.referralProgram === undefined) { continue }
if (userProfile.tokenSwitch.referralProgram.payload === undefined) { continue }
distributeForReferralProgram(userProfile.tokenSwitch.referralProgram)
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
calculateAwardedForProfile(userProfile)
if (userProfile.tokenSwitch === undefined) { continue }
if (userProfile.tokenSwitch.referralProgram === undefined) { continue }
if (userProfile.tokenSwitch.referralProgram.payload === undefined) { continue }
calculateForReferralProgram(userProfile.tokenSwitch.referralProgram)
}
function findPool(node) {
@@ -40,14 +66,14 @@ function newGovernanceFunctionLibraryUserReferrals() {
/*
When we reach certain node types, we will halt the distribution, because these are targets for
voting combinedPower.
voting outgoingPower.
*/
if (
node.type === 'Pool'
) {
let codeName = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(node.payload, 'codeName')
if (codeName === "User-Referrals") {
tokensReward = node.payload.tokens
if (codeName === "Referral-Program") {
referralProgramPoolTokenReward = node.payload.tokens
return
}
}
@@ -82,11 +108,11 @@ function newGovernanceFunctionLibraryUserReferrals() {
function resetUserReferrals(node) {
if (node === undefined) { return }
if (node.payload === undefined) { return }
node.payload.referring = {
node.payload.referrals = {
count: 0,
combinedPower: 0,
outgoingPower: 0,
ownPower: 0,
referralsPower: 0,
incomingPower: 0,
awarded: {
tokens: 0,
percentage: 0
@@ -96,115 +122,197 @@ function newGovernanceFunctionLibraryUserReferrals() {
If the node is a User Profile, we will check if it has a User Referrer child defined.
*/
if (
node.userReferrer !== undefined &&
node.type === 'User Profile'
node.type === 'User Profile' &&
node.tokenSwitch !== undefined &&
node.tokenSwitch.referralProgram !== undefined
) {
resetUserReferrals(node.tokenSwitch.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)
return
}
/*
If there is a reference parent defined, this means that the referral combinedPower is
If there is a reference parent defined, this means that the referral outgoingPower is
transfered to it.
*/
if (
node.payload.referenceParent !== undefined &&
node.type === 'User Referrer'
node.type === 'User Referrer' &&
node.payload.referenceParent !== undefined
) {
resetUserReferrals(node.payload.referenceParent)
return
}
}
function distributeForProfile(userProfile) {
if (userProfile === undefined || userProfile.payload === undefined) { return }
let referringPower = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(userProfile.payload, 'tokens')
let referringCount = 0
userProfile.payload.referring.ownPower = referringPower
distributeUserReferrals(userProfile, referringPower, referringCount)
function distributeForReferralProgram(referralProgram) {
if (referralProgram === undefined || referralProgram.payload === undefined) { return }
/*
Here we will convert Token Power into Referral Power.
As per system rules referringPower = tokensPower
*/
let referringPower = referralProgram.payload.tokenPower
/*
We will also reseet the count of referrals here.
*/
let count = 0
/*
The Own Power is the power generated by the same User Profile tokens, not inherited from others.
*/
referralProgram.payload.referrals.ownPower = referringPower
distributeReferralPower(referralProgram, referringPower, count)
}
function distributeUserReferrals(node, referringPower, referringCount) {
function distributeReferralPower(
node,
referringPower,
count
) {
if (node === undefined) { return }
if (node.payload === undefined) { return }
node.payload.referring.count = node.payload.referring.count + referringCount
node.payload.referring.combinedPower = node.payload.referring.combinedPower + referringPower
/*
If the node is a User Profile, we will check if it has a User Referrer child defined.
*/
totalReferralsPower = totalReferralsPower - node.payload.referring.referralsPower
node.payload.referring.referralsPower = node.payload.referring.combinedPower - node.payload.referring.ownPower
totalReferralsPower = totalReferralsPower + node.payload.referring.referralsPower
if (
node.userReferrer !== undefined &&
node.type === 'User Profile'
) {
distributeUserReferrals(node.userReferrer, referringPower, 1, 0)
return
}
/*
If there is a reference parent defined, this means that the referral combinedPower is
transfered to it.
*/
if (
node.payload.referenceParent !== undefined &&
node.type === 'User Referrer'
) {
drawUserReferrals(node)
distributeUserReferrals(node.payload.referenceParent, referringPower / 10, 1)
return
}
}
switch (node.type) {
case 'Referral Program': {
/*
This is the point where we increase to our local count of referrals whatever it comes
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
/*
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
/*
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
/*
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
power flow that is leaving this node, which includes the ownPower. That means that if we
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
/*
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
function calculateAwardedForProfile(userProfile) {
let totalPowerRewardRation = tokensReward / totalReferralsPower
if (totalPowerRewardRation < 1) { totalPowerRewardRation = 1 }
userProfile.payload.referring.awarded.tokens = userProfile.payload.referring.referralsPower * totalPowerRewardRation
drawUserProfiles(userProfile)
}
function drawUserReferrals(node) {
if (node.payload !== undefined) {
const powerText = new Intl.NumberFormat().format(node.payload.referring.combinedPower)
node.payload.uiObject.valueAngleOffset = 0
node.payload.uiObject.valueAtAngle = false
node.payload.uiObject.setStatus(powerText + ' ' + 'Combined Referring Power')
return
}
}
function drawUserProfiles(node) {
if (node.payload !== undefined) {
const powerText = new Intl.NumberFormat().format(node.payload.referring.combinedPower)
const awardedTokens = new Intl.NumberFormat().format(node.payload.referring.awarded.tokens)
const referralPower = new Intl.NumberFormat().format(node.payload.referring.referralsPower)
node.payload.uiObject.valueAngleOffset = 0
node.payload.uiObject.valueAtAngle = false
if (
(
node.userReferrer !== undefined &&
node.userReferrer.payload !== undefined &&
node.userReferrer.payload.referenceParent !== undefined)
||
node.payload.referring.combinedPower >= 10000000
) {
let status =
powerText + ' ' + 'Combined Referring Power' + ' - ' +
node.payload.referring.count + ' Referrals' + ' - ' +
referralPower + ' Referrals Power' + ' - ' +
awardedTokens + ' ' + 'SA Tokens Awarded'
node.payload.uiObject.setStatus(status)
return
} else {
node.payload.referring.awarded.tokens = 0
node.payload.uiObject.setStatus(awardedTokens + ' SA Tokens not Awarded, because you have not defined your referrer yet.')
if (node.userReferrer !== undefined) {
distributeReferralPower(node.userReferrer, referringPower, 0)
}
break
}
case 'User Referrer': {
drawUserReferrer(node)
if (node.payload.referenceParent !== undefined) {
distributeReferralPower(node.payload.referenceParent, referringPower / 10, 0)
}
break
}
case 'User Profile': {
if (node.tokenSwitch !== undefined) {
distributeReferralPower(node.tokenSwitch, referringPower, 0)
}
break
}
case 'Token Switch': {
if (node.referralProgram !== undefined) {
distributeReferralPower(node.referralProgram, referringPower, 1)
}
break
}
}
}
function calculateForReferralProgram(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
represents.
*/
if (referralProgram.payload === undefined) { return }
/*
If the accumulatedIncomingReferralPower is not grater the amount of tokens at the Referral Program Pool, then
this user will get the exact amount of tokens from the pool as incomingPower he has.
If the accumulatedIncomingReferralPower is grater the amount of tokens at the Referral Program Pool, then
the amount ot tokens to be received is a proportional to the share of incomingPower in accumulatedIncomingReferralPower.
*/
let totalPowerRewardRatio = accumulatedIncomingReferralPower / referralProgramPoolTokenReward
if (totalPowerRewardRatio < 1) { totalPowerRewardRatio = 1 }
if (referralProgram.tokensAwarded === undefined || referralProgram.tokensAwarded.payload === undefined) {
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
/*
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.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
}
drawReferralProgram(referralProgram)
}
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)
node.payload.uiObject.valueAngleOffset = 180
node.payload.uiObject.valueAtAngle = true
node.payload.uiObject.setValue(outgoingPowerText + ' ' + 'Referring Power')
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = false
node.payload.uiObject.setStatus(ownPowerText + ' Own RP + ' + incomingPowerText + ' Incoming RP = ' + outgoingPowerText + ' ' + ' Outgoing RP')
}
}
function drawReferralProgram(node) {
if (node.payload !== undefined) {
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = false
node.payload.uiObject.setStatus("Referring Power = Token Power")
}
if (node.tokensAwarded !== undefined && node.tokensAwarded.payload !== undefined) {
const tokensAwardedText = new Intl.NumberFormat().format(node.payload.referrals.awarded.tokens)
node.tokensAwarded.payload.uiObject.statusAngleOffset = 0
node.tokensAwarded.payload.uiObject.statusAtAngle = false
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens')
}
}
}
@@ -41,11 +41,23 @@ function newGovernanceFunctionLibraryVotes() {
*/
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
resetVotes(userProfile)
if (userProfile.tokenSwitch === undefined) { continue }
if (userProfile.tokenSwitch.votingProgram === undefined) { continue }
if (userProfile.tokenSwitch.votingProgram.payload === undefined) { continue }
resetVotes(userProfile.tokenSwitch.votingProgram)
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
distributeForProfile(userProfile)
if (userProfile.tokenSwitch === undefined) { continue }
if (userProfile.tokenSwitch.votingProgram === undefined) { continue }
if (userProfile.tokenSwitch.votingProgram.payload === undefined) { continue }
userProfile.tokenSwitch.votingProgram.payload.votes = userProfile.tokenSwitch.votingProgram.payload.tokenPower
distributeForVotingProgram(userProfile.tokenSwitch.votingProgram)
}
function resetVotes(node) {
@@ -89,11 +101,11 @@ function newGovernanceFunctionLibraryVotes() {
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
let property = schemaDocument.childrenNodesProperties[i]
if (node.type === 'User Profile' && property.name !== "votesDistribution") { continue }
if (node.type === 'User Profile' && property.name !== "votingProgram") { continue }
switch (property.type) {
case 'node': {
if (node.type === 'User Profile' && property.name === "votesDistribution") {
if (node.type === 'User Profile' && property.name === "votingProgram") {
let childNode = node[property.name]
resetVotes(childNode)
}
@@ -114,9 +126,10 @@ function newGovernanceFunctionLibraryVotes() {
}
}
function distributeForProfile(userProfile) {
let votes = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(userProfile.payload, 'tokens')
distributeVotes(userProfile, votes)
function distributeForVotingProgram(votingProgram) {
if (votingProgram.payload === undefined) { return }
let votes = votingProgram.payload.votes
distributeVotes(votingProgram, votes)
}
function distributeVotes(node, votes, switchPercentage) {
@@ -169,11 +182,11 @@ function newGovernanceFunctionLibraryVotes() {
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
let property = schemaDocument.childrenNodesProperties[i]
if (node.type === 'User Profile' && property.name !== "votesDistribution") { continue }
if (node.type === 'User Profile' && property.name !== "votingProgram") { continue }
switch (property.type) {
case 'node': {
if (node.type === 'User Profile' && property.name === "votesDistribution") {
if (node.type === 'User Profile' && property.name === "votingProgram") {
let childNode = node[property.name]
if (childNode === undefined) { continue }
let percentage = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(childNode.payload, 'percentage')
@@ -217,11 +230,11 @@ function newGovernanceFunctionLibraryVotes() {
for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) {
let property = schemaDocument.childrenNodesProperties[i]
if (node.type === 'User Profile' && property.name !== "votesDistribution") { continue }
if (node.type === 'User Profile' && property.name !== "votingProgram") { continue }
switch (property.type) {
case 'node': {
if (node.type === 'User Profile' && property.name === "votesDistribution") {
if (node.type === 'User Profile' && property.name === "votingProgram") {
let childNode = node[property.name]
if (childNode === undefined) { continue }
let percentage = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(childNode.payload, 'percentage')
@@ -255,7 +268,16 @@ function newGovernanceFunctionLibraryVotes() {
function drawVotes(node, votes, percentage) {
votes = new Intl.NumberFormat().format(votes) + ' ' + 'Votes'
if (node.payload !== undefined) {
if (node.type === 'User Profile') {
if (node.type === 'Voting Program') {
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = false
node.payload.uiObject.setStatus("Votes = Tokens Power")
if (percentage !== undefined) {
node.payload.uiObject.setPercentage(percentage.toFixed(2))
}
return
}
if (
@@ -273,9 +295,13 @@ function newGovernanceFunctionLibraryVotes() {
) {
node.payload.uiObject.valueAngleOffset = 0
node.payload.uiObject.valueAtAngle = false
node.payload.uiObject.percentageAngleOffset = 0
node.payload.uiObject.percentageAtAngle = false
} else {
node.payload.uiObject.valueAngleOffset = 180
node.payload.uiObject.valueAtAngle = true
node.payload.uiObject.percentageAngleOffset = 180
node.payload.uiObject.percentageAtAngle = true
}
node.payload.uiObject.setValue(votes)
@@ -14,6 +14,8 @@ function newGovernanceUserProfileSpace() {
thisObject.container.initialize(MODULE_NAME)
thisObject.container.isDraggeable = false
waitingForResponses = 0
return thisObject
function initialize() {
@@ -39,6 +41,84 @@ function newGovernanceUserProfileSpace() {
function physics() {
if (UI.projects.foundations.spaces.designSpace.workspace === undefined) { return }
let userProfiles = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('User Profile')
if (waitingForResponses !== 0) { return }
/*
We will get all the user Profiles tokens from the blockchain, making a call
every 5 seconds so as not to exceed the rate limit.
*/
let timer = 0
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
if (userProfile.payload === undefined) { continue }
if (userProfile.payload.blockchainTokens === undefined) {
getBlockchainAccount(userProfile)
}
}
function getBlockchainAccount(userProfile) {
let signature = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(userProfile.payload, 'signature')
if (signature === undefined || signature === "") { return }
let request = {
url: 'WEB3',
params: {
method: "recoverAddress",
signature: JSON.stringify(signature)
}
}
httpRequest(JSON.stringify(request.params), request.url, onResponse)
function onResponse(err, data) {
/* Lets check the result of the call through the http interface */
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
userProfile.payload.uiObject.setErrorMessage('Call via HTTP Interface failed.')
return
}
let response = JSON.parse(data)
/* Lets check the result of the method call */
if (response.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
userProfile.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + response.error)
console.log('Call to WEB3 Server failed. ' + response.error)
return
}
let blockchainAccount = response.address
if (
blockchainAccount !== undefined &&
blockchainAccount !== "" &&
userProfile.payload.blockchainTokens === undefined
) {
waitingForResponses++
userProfile.payload.blockchainTokens = 0 // We need to set this value here so that the next call to BSCSCAN is not done more than once.
setTimeout(getBlockchainTokens, timer, userProfile, blockchainAccount)
timer = timer + 5000
}
}
}
function getBlockchainTokens(userProfile, blockchainAccount) {
console.log('blockchainAccount ', blockchainAccount)
const url = "https://api.bscscan.com/api?module=account&action=tokenbalance&contractaddress=0xfb981ed9a92377ca4d75d924b9ca06df163924fd&address=" + blockchainAccount + "&tag=latest&apikey=YourApiKeyToken"
fetch(url).then(function (response) {
return response.json();
}).then(function (data) {
console.log(data)
userProfile.payload.uiObject.setInfoMessage(data)
userProfile.payload.blockchainTokens = Number(data.result) / 1000000000000000000
waitingForResponses--
}).catch(function (err) {
const message = err.message + ' - ' + 'Can not access BSC SCAN servers.'
console.log(message)
userProfile.payload.uiObject.setErrorMessage(message, 1000)
waitingForResponses--
});
}
}
function draw() {
+10
View File
@@ -963,6 +963,11 @@
"propertyName": "assets",
"functionName": "newGovernanceFunctionLibraryAssets"
},
{
"name": "TokenPower",
"propertyName": "tokenPower",
"functionName": "newGovernanceFunctionLibraryTokenPower"
},
{
"name": "Votes",
"propertyName": "votes",
@@ -997,6 +1002,11 @@
"name": "User Referrals",
"propertyName": "userrReferrals",
"functionName": "newGovernanceFunctionLibraryUserReferrals"
},
{
"name": "Profile Constructor",
"propertyName": "profileConstructor",
"functionName": "newGovernanceFunctionLibraryProfileConstructor"
}
],
"utilities": [],