Governance: Referral Calculation Implemented
This commit is contained in:
1 parent
8ca0c05a1f
commit
85bc313b89
6 files changed
+132
-5
No files matched your search
@@ -1100,7 +1100,6 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
getAllFilesInDirectoryAndSubdirectories(folder, onFilesReady)
|
||||
|
||||
function onFilesReady(files) {
|
||||
console.log(files)
|
||||
respondWithContent(JSON.stringify(files), httpResponse)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ function newGovernanceFunctionLibraryDistributionProcess() {
|
||||
UI.projects.governance.functionLibraries.tokens.calculate(
|
||||
pools
|
||||
)
|
||||
|
||||
UI.projects.governance.functionLibraries.userrReferrals.calculate(
|
||||
userProfiles
|
||||
)
|
||||
|
||||
UI.projects.governance.functionLibraries.claims.calculate(
|
||||
features,
|
||||
|
||||
@@ -52,7 +52,7 @@ function newGovernanceFunctionLibraryTokens() {
|
||||
return
|
||||
}
|
||||
/*
|
||||
When we reach certain node types, we will halt the distribution, because thse are targets for
|
||||
When we reach certain node types, we will halt the distribution, because these are targets for
|
||||
token flow.
|
||||
*/
|
||||
if (
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
function newGovernanceFunctionLibraryUserReferrals() {
|
||||
let thisObject = {
|
||||
calculate: calculate
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function calculate(
|
||||
userProfiles
|
||||
) {
|
||||
/*
|
||||
We will first reset all the referral power, and then distribute it.
|
||||
*/
|
||||
for (let i = 0; i < userProfiles.length; i++) {
|
||||
let userProfile = userProfiles[i]
|
||||
resetUserReferrals(userProfile)
|
||||
}
|
||||
for (let i = 0; i < userProfiles.length; i++) {
|
||||
let userProfile = userProfiles[i]
|
||||
distributeForProfile(userProfile)
|
||||
}
|
||||
|
||||
function resetUserReferrals(node) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
node.payload.referring = {
|
||||
count: 0,
|
||||
power: 0
|
||||
}
|
||||
/*
|
||||
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'
|
||||
) {
|
||||
resetUserReferrals(node.userReferrer)
|
||||
return
|
||||
}
|
||||
/*
|
||||
If there is a reference parent defined, this means that the referral power is
|
||||
transfered to it.
|
||||
*/
|
||||
if (
|
||||
node.payload.referenceParent !== undefined &&
|
||||
node.type === 'User Referrer'
|
||||
) {
|
||||
resetUserReferrals(node.payload.referenceParent)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
function distributeForProfile(userProfile) {
|
||||
let referringPower = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(userProfile.payload, 'tokens')
|
||||
let referringCount = 0
|
||||
distributeUserReferrals(userProfile, referringPower, referringCount)
|
||||
}
|
||||
|
||||
function distributeUserReferrals(node, referringPower, referringCount) {
|
||||
if (node === undefined) { return }
|
||||
if (node.payload === undefined) { return }
|
||||
|
||||
node.payload.referring = {
|
||||
count: node.payload.referring.count + referringCount,
|
||||
power: node.payload.referring.power + referringPower
|
||||
}
|
||||
|
||||
drawUserReferrals(node, node.payload.referring.count, node.payload.referring.power)
|
||||
/*
|
||||
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'
|
||||
) {
|
||||
distributeUserReferrals(node.userReferrer, referringPower, 1, 0)
|
||||
return
|
||||
}
|
||||
/*
|
||||
If there is a reference parent defined, this means that the referral power is
|
||||
transfered to it.
|
||||
*/
|
||||
if (
|
||||
node.payload.referenceParent !== undefined &&
|
||||
node.type === 'User Referrer'
|
||||
) {
|
||||
distributeUserReferrals(node.payload.referenceParent, referringPower / 10, 1)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
function drawUserReferrals(node, count, power) {
|
||||
const powerText = new Intl.NumberFormat().format(power) + ' ' + 'Referring Power'
|
||||
if (node.payload !== undefined) {
|
||||
|
||||
node.payload.uiObject.valueAngleOffset = 0
|
||||
node.payload.uiObject.valueAtAngle = false
|
||||
|
||||
if (node.type === 'User Referrer') {
|
||||
node.payload.uiObject.setStatus(powerText)
|
||||
return
|
||||
}
|
||||
if (
|
||||
(node.type === 'User Profile' &&
|
||||
node.userReferrer !== undefined &&
|
||||
node.userReferrer.payload !== undefined &&
|
||||
node.userReferrer.payload.referenceParent !== undefined)
|
||||
||
|
||||
power >= 10000000
|
||||
) {
|
||||
node.payload.uiObject.setStatus(powerText + ' - ' + count + ' Referrals')
|
||||
return
|
||||
} else {
|
||||
node.payload.uiObject.setStatus('Define your referrer to collect tokens from your referrals.')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
resetVotes(featuresNode)
|
||||
}
|
||||
|
||||
/* Reset Votes at Features */
|
||||
/* Reset Votes at Assets */
|
||||
for (let i = 0; i < assets.length; i++) {
|
||||
let assetsNode = assets[i]
|
||||
resetVotes(assetsNode)
|
||||
@@ -53,7 +53,7 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
if (node.payload === undefined) { return }
|
||||
node.payload.votes = 0
|
||||
/*
|
||||
When we reach certain node types, we will halt the distribution, because thse are targets for
|
||||
When we reach certain node types, we will halt the distribution, because these are targets for
|
||||
voting power.
|
||||
*/
|
||||
if (
|
||||
@@ -125,7 +125,7 @@ function newGovernanceFunctionLibraryVotes() {
|
||||
node.payload.votes = node.payload.votes + votes
|
||||
drawVotes(node, node.payload.votes, switchPercentage)
|
||||
/*
|
||||
When we reach certain node types, we will halt the distribution, because thse are targets for
|
||||
When we reach certain node types, we will halt the distribution, because these are targets for
|
||||
voting power.
|
||||
*/
|
||||
if (
|
||||
|
||||
@@ -992,6 +992,11 @@
|
||||
"name": "Plugins Functions",
|
||||
"propertyName": "pluginsFunctions",
|
||||
"functionName": "newGovernanceFunctionLibraryPluginsFunctions"
|
||||
},
|
||||
{
|
||||
"name": "User Referrals",
|
||||
"propertyName": "userrReferrals",
|
||||
"functionName": "newGovernanceFunctionLibraryUserReferrals"
|
||||
}
|
||||
],
|
||||
"utilities": [],
|
||||
|
||||
Reference in new issue
Block a user