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

Contribution: Governance: Liquidity Program Implemented.
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2021-10-19 11:11:43 -04:00
commit eb54b91226
14 files changed
+1046 -291

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

+103 -42
View File
@@ -295,11 +295,11 @@
"savedPayload": {
"position": {
"x": 16657.465367689296,
"y": 44560.21626285766
"y": 44561.21626285766
},
"targetPosition": {
"x": 16445.333333333332,
"y": 44772.348297213626
"y": 44773.348297213626
},
"floatingObject": {
"isPinned": false,
@@ -448,11 +448,11 @@
"savedPayload": {
"position": {
"x": 16745.333333333332,
"y": 44772.348297213626
"y": 44773.348297213626
},
"targetPosition": {
"x": 16445.333333333332,
"y": 44772.348297213626
"y": 44773.348297213626
},
"floatingObject": {
"isPinned": false,
@@ -483,12 +483,12 @@
"id": "5bd09ac2-6c9f-4a7d-a547-c05a8a1e98e2",
"savedPayload": {
"position": {
"x": 16953.771869867836,
"y": 44937.549992057524
"x": 16947.243115576017,
"y": 44907.83461803883
},
"targetPosition": {
"x": 16657.465367689296,
"y": 44984.48033156959
"y": 44985.48033156959
},
"floatingObject": {
"isPinned": false,
@@ -520,12 +520,12 @@
"id": "9eb846a4-effb-4380-9487-1a82011b0488",
"savedPayload": {
"position": {
"x": 17192.069282202316,
"y": 45256.87463141332
"x": 17237.020863462738,
"y": 45140.771758631105
},
"targetPosition": {
"x": 16924.767324945806,
"y": 45120.67748149145
"x": 16947.243115576017,
"y": 45063.12604510035
},
"floatingObject": {
"isPinned": false,
@@ -544,12 +544,12 @@
"id": "80d4f08f-bb7f-48a2-9cef-be12befcac2e",
"savedPayload": {
"position": {
"x": 16924.767324945806,
"y": 45120.67748149145
"x": 16947.243115576017,
"y": 45063.12604510035
},
"targetPosition": {
"x": 16657.465367689296,
"y": 44984.48033156959
"y": 44985.48033156959
},
"floatingObject": {
"isPinned": false,
@@ -581,12 +581,12 @@
"id": "d2cf4c65-b4bd-4fa8-b0da-f73a38b8419a",
"savedPayload": {
"position": {
"x": 16929.859667533023,
"y": 45519.08424608261
"x": 17081.729436401223,
"y": 45409.74440028152
},
"targetPosition": {
"x": 16793.66251761116,
"y": 45251.7822888261
"x": 16869.59740204526,
"y": 45197.61236592555
},
"floatingObject": {
"isPinned": false,
@@ -605,12 +605,73 @@
"id": "68e3f570-4156-4be6-8881-c526a06f85d0",
"savedPayload": {
"position": {
"x": 16793.66251761116,
"y": 45251.7822888261
"x": 16869.59740204526,
"y": 45197.61236592555
},
"targetPosition": {
"x": 16657.465367689296,
"y": 44984.48033156959
"y": 44985.48033156959
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
},
{
"type": "Pool Class",
"name": "Liquidity Program",
"config": "{}",
"project": "Governance",
"poolClasses": [],
"pools": [
{
"type": "Pool",
"name": "Liquidity Rewards",
"config": "{\n \"codeName\": \"Liquidity-Rewards\"\n}",
"project": "Governance",
"poolClasses": [],
"pools": [],
"id": "a7651e92-ab96-49fc-af9c-f936682dd7a4",
"savedPayload": {
"position": {
"x": 16812.75679475081,
"y": 45565.03582734303
},
"targetPosition": {
"x": 16735.111081220053,
"y": 45275.25807945631
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
},
"uiObject": {
"isRunning": false
}
}
}
],
"id": "477faa7a-da4f-4949-9439-a2475ed683de",
"savedPayload": {
"position": {
"x": 16735.111081220053,
"y": 45275.25807945631
},
"targetPosition": {
"x": 16657.465367689296,
"y": 44985.48033156959
},
"floatingObject": {
"isPinned": false,
@@ -642,12 +703,12 @@
"id": "24e62dd3-4d7b-4eba-b401-493c155d85d0",
"savedPayload": {
"position": {
"x": 16563.604688665157,
"y": 45577.09333592668
"x": 16502.17394062778,
"y": 45565.03582734303
},
"targetPosition": {
"x": 16610.535028177226,
"y": 45280.786833748134
"x": 16579.81965415854,
"y": 45275.25807945631
},
"floatingObject": {
"isPinned": false,
@@ -666,12 +727,12 @@
"id": "f09429a2-3f6c-4210-bb73-0c8efd254c82",
"savedPayload": {
"position": {
"x": 16610.535028177226,
"y": 45280.786833748134
"x": 16579.81965415854,
"y": 45275.25807945631
},
"targetPosition": {
"x": 16657.465367689296,
"y": 44984.48033156959
"y": 44985.48033156959
},
"floatingObject": {
"isPinned": false,
@@ -692,11 +753,11 @@
"savedPayload": {
"position": {
"x": 16657.465367689296,
"y": 44984.48033156959
"y": 44985.48033156959
},
"targetPosition": {
"x": 16445.333333333332,
"y": 44772.348297213626
"y": 44773.348297213626
},
"floatingObject": {
"isPinned": false,
@@ -717,11 +778,11 @@
"savedPayload": {
"position": {
"x": 16445.333333333332,
"y": 44772.348297213626
"y": 44773.348297213626
},
"targetPosition": {
"x": 16145.333333333332,
"y": 44772.348297213626
"y": 44773.348297213626
},
"floatingObject": {
"isPinned": false,
@@ -754,11 +815,11 @@
"savedPayload": {
"position": {
"x": 15633.201298977368,
"y": 44984.48033156959
"y": 44985.48033156959
},
"targetPosition": {
"x": 15845.333333333332,
"y": 44772.348297213626
"y": 44773.348297213626
},
"floatingObject": {
"isPinned": false,
@@ -797,11 +858,11 @@
"savedPayload": {
"position": {
"x": 15545.333333333332,
"y": 44772.348297213626
"y": 44773.348297213626
},
"targetPosition": {
"x": 15845.333333333332,
"y": 44772.348297213626
"y": 44773.348297213626
},
"floatingObject": {
"isPinned": false,
@@ -840,11 +901,11 @@
"savedPayload": {
"position": {
"x": 15633.201298977368,
"y": 44560.21626285766
"y": 44561.21626285766
},
"targetPosition": {
"x": 15845.333333333332,
"y": 44772.348297213626
"y": 44773.348297213626
},
"floatingObject": {
"isPinned": false,
@@ -877,11 +938,11 @@
"savedPayload": {
"position": {
"x": 15845.333333333332,
"y": 44772.348297213626
"y": 44773.348297213626
},
"targetPosition": {
"x": 16145.333333333332,
"y": 44772.348297213626
"y": 44773.348297213626
},
"floatingObject": {
"isPinned": false,
@@ -902,11 +963,11 @@
"savedPayload": {
"position": {
"x": 16145.333333333332,
"y": 44772.348297213626
"y": 44773.348297213626
},
"targetPosition": {
"x": 16145.333333333332,
"y": 44772.348297213626
"y": 44773.348297213626
},
"floatingObject": {
"isPinned": false,
File diff suppressed because it is too large. Load diff
@@ -18,6 +18,16 @@
"relatedUiObject": "Staking Program",
"relatedUiObjectProject": "Governance"
},
{
"action": "Add UI Object",
"actionProject": "Visual-Scripting",
"actionFunction": "payload.executeAction",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "stakingProgram",
"label": "Add Liquidity Program",
"relatedUiObject": "Liquidity Program",
"relatedUiObjectProject": "Governance"
},
{
"action": "Add UI Object",
"actionProject": "Visual-Scripting",
@@ -58,6 +68,12 @@
"childType": "Staking Program",
"autoAdd": false
},
{
"name": "liquidityProgram",
"type": "node",
"childType": "Liquidity Program",
"autoAdd": false
},
{
"name": "delegationProgram",
"type": "node",
@@ -0,0 +1,52 @@
{
"type": "Liquidity Program",
"menuItems": [
{
"action": "Configure",
"actionFunction": "uiObject.configEditor.activate",
"label": "Configure",
"iconPathOn": "configuration",
"iconPathOff": "configuration"
},
{
"action": "Add UI Object",
"actionProject": "Visual-Scripting",
"disableIfPropertyIsDefined": true,
"propertyToCheckFor": "tokensAwarded",
"actionFunction": "payload.executeAction",
"label": "Add Tokens Awarded",
"relatedUiObject": "Tokens Awarded",
"relatedUiObjectProject": "Governance"
},
{
"action": "Delete UI Object",
"actionProject": "Visual-Scripting",
"askConfirmation": true,
"confirmationLabel": "Confirm to Delete",
"label": "Delete",
"iconPathOn": "delete-entity",
"iconPathOff": "delete-entity",
"actionFunction": "payload.executeAction"
}
],
"editors": {
"config": true
},
"initialValues": {
"config": "{}"
},
"attachingRules": {
"compatibleTypes": "->Financial Programs->"
},
"addLeftIcons": true,
"level": 1,
"propertyNameAtParent": "liquidityProgram",
"childrenNodesProperties": [
{
"name": "tokensAwarded",
"type": "node",
"childType": "Tokens Awarded",
"autoAdd": true
}
]
}
@@ -6,8 +6,8 @@ function newGovernanceFunctionLibraryDistributionProcess() {
}
const DISTRIBUTION_PROCESS_RECALCULATION_DELAY = 5000
let loop
let loop
return thisObject
function initialize() {
@@ -18,7 +18,7 @@ function newGovernanceFunctionLibraryDistributionProcess() {
function finalize() {
loop = false
}
function calculate() {
let pools = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('Pools')
@@ -110,6 +110,13 @@ function newGovernanceFunctionLibraryDistributionProcess() {
userProfiles
)
/*
Run the Liquidity Program
*/
UI.projects.governance.functionLibraries.liquidityProgram.calculate(
pools,
userProfiles
)
/*
Run the Claims Program
*/
UI.projects.governance.functionLibraries.claimsProgram.calculate(
@@ -0,0 +1,176 @@
function newGovernanceFunctionLibraryLiquidityProgram() {
let thisObject = {
calculate: calculate
}
return thisObject
function calculate(
pools,
userProfiles
) {
let programPoolTokenReward
/*
In order to be able to calculate the share of the Program Pool for each User Profile,
we need to accumulate all the Liquidity Power that each User Profile at their Program
node has, because with that Power is that each Program node gets a share of the pool.
*/
let accumulatedProgramPower = 0
/* Scan Pools Until finding the Pool for this program*/
for (let i = 0; i < pools.length; i++) {
let poolsNode = pools[i]
programPoolTokenReward = UI.projects.governance.utilities.pools.findPool(poolsNode, "Liquidity-Rewards")
if (programPoolTokenReward !== undefined) { break }
}
if (programPoolTokenReward === undefined || programPoolTokenReward === 0) { return }
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
if (userProfile.tokenPowerSwitch === undefined) { continue }
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Liquidity Program")
if (program === undefined) { continue }
if (program.payload === undefined) { continue }
resetProgram(program)
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
if (userProfile.tokenPowerSwitch === undefined) { continue }
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Liquidity Program")
if (program === undefined) { continue }
if (program.payload === undefined) { continue }
validateProgram(program, userProfile)
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
if (userProfile.tokenPowerSwitch === undefined) { continue }
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Liquidity Program")
if (program === undefined) { continue }
if (program.payload === undefined) { continue }
if (program.payload.liquidityProgram.isActive === false) { continue }
distributeProgram(program, userProfile)
}
for (let i = 0; i < userProfiles.length; i++) {
let userProfile = userProfiles[i]
if (userProfile.tokenPowerSwitch === undefined) { continue }
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Liquidity Program")
if (program === undefined) { continue }
if (program.payload === undefined) { continue }
if (program.payload.liquidityProgram.isActive === false) { continue }
calculateProgram(program)
}
function resetProgram(node) {
if (node === undefined) { return }
if (node.payload === undefined) { return }
if (node.payload.liquidityProgram === undefined) {
node.payload.liquidityProgram = {
count: 0,
percentage: 0,
outgoingPower: 0,
ownPower: 0,
incomingPower: 0,
awarded: {
tokens: 0,
percentage: 0
}
}
} else {
node.payload.liquidityProgram.count = 0
node.payload.liquidityProgram.percentage = 0
node.payload.liquidityProgram.outgoingPower = 0
node.payload.liquidityProgram.ownPower = 0
node.payload.liquidityProgram.incomingPower = 0
node.payload.liquidityProgram.awarded = {
tokens: 0,
percentage: 0
}
}
}
function validateProgram(node, userProfile) {
/*
This program is not going to run unless the Profile has Liquidity Tokens, and for
that users needs to execute the setup procedure of signing their Github
username with their private key.
*/
if (
userProfile.payload.liquidityTokens === undefined
) {
node.payload.liquidityProgram.isActive = false
userProfile.payload.uiObject.setErrorMessage(
"Waiting for liquidity balance. It takes 6 seconds to load the liquidity provided by each profile, bacause you are using a free API provided by BSC Scan.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
} else {
userProfile.payload.uiObject.resetErrorMessage()
node.payload.liquidityProgram.isActive = true
}
}
function distributeProgram(programNode, userProfile) {
if (programNode === undefined || programNode.payload === undefined) { return }
/*
Here we will convert Liquidity Tokens into Liquidity Power.
As per system rules Liquidity Powar = userProfile.payload.liquidityTokens
*/
let programPower = userProfile.payload.liquidityTokens
programNode.payload.liquidityProgram.ownPower = programPower
accumulatedProgramPower = accumulatedProgramPower + programPower
}
function calculateProgram(programNode) {
if (programNode.payload === undefined) { return }
if (programNode.tokensAwarded === undefined || programNode.tokensAwarded.payload === undefined) {
programNode.payload.uiObject.setErrorMessage(
"Tokens Awarded Node is needed in order for this Program to get Tokens from the Program Pool.",
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
return
}
/*
Here we will calculate which share of the Program Pool this user will get in tokens.
To do that, we use the ownPower, to see which proportion of the accumulatedProgramPower
represents.
*/
programNode.payload.liquidityProgram.awarded.percentage = programNode.payload.liquidityProgram.ownPower * 100 / accumulatedProgramPower
programNode.payload.liquidityProgram.awarded.tokens = programPoolTokenReward * programNode.payload.liquidityProgram.awarded.percentage / 100
drawProgram(programNode)
}
function drawProgram(node) {
if (node.payload !== undefined) {
const ownPowerText = parseFloat(node.payload.liquidityProgram.ownPower.toFixed(2)).toLocaleString('en')
const percentageText = parseFloat(node.payload.liquidityProgram.awarded.percentage.toFixed(2)).toLocaleString('en')
node.payload.uiObject.statusAngleOffset = 0
node.payload.uiObject.statusAtAngle = false
node.payload.uiObject.setStatus(ownPowerText + ' Liquidity Power' + ' - ' + percentageText + ' % Pool ', UI.projects.governance.globals.designer.SET_STATUS_COUNTER)
}
if (node.tokensAwarded !== undefined && node.tokensAwarded.payload !== undefined) {
const tokensAwardedText = parseFloat(node.payload.liquidityProgram.awarded.tokens.toFixed(0)).toLocaleString('en')
const tokensAwardedBTC = ' ≃ ' + UI.projects.governance.utilities.conversions.estimateSATokensInBTC(node.payload.liquidityProgram.awarded.tokens | 0) + ' BTC'
node.tokensAwarded.payload.uiObject.valueAngleOffset = 0
node.tokensAwarded.payload.uiObject.valueAtAngle = false
node.tokensAwarded.payload.uiObject.setValue(tokensAwardedText + ' SA Tokens' + tokensAwardedBTC, UI.projects.governance.globals.designer.SET_VALUE_COUNTER)
}
}
}
}
+2 -1
View File
@@ -3,7 +3,8 @@ function newGovernanceGlobalsSaToken() {
SA_TOKEN_BSC_CONTRACT_ADDRESS: '0xfb981ed9a92377ca4d75d924b9ca06df163924fd',
SA_TOKEN_BSC_CONTRACT_ABI: '[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"},{"name":"amount","type":"uint256"}],"name":"mint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_subtractedValue","type":"uint256"}],"name":"decreaseApproval","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"listAddress","type":"address"},{"name":"isBlackListed","type":"bool"}],"name":"blackListAddress","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_addedValue","type":"uint256"}],"name":"increaseApproval","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_name","type":"string"},{"name":"_symbol","type":"string"},{"name":"_decimals","type":"uint256"},{"name":"_supply","type":"uint256"},{"name":"tokenOwner","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"burner","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"blackListed","type":"address"},{"indexed":false,"name":"value","type":"bool"}],"name":"Blacklist","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value",Line truncated
SA_TOKEN_BSC_TREASURY_ACCOUNT_ADDRESS: '0x8d4d2557ce99f83f658adf61eef3e61e04c2ac2c',
SA_TOKEN_BSC_DECIMAL_FACTOR: 1000000000000000000
SA_TOKEN_BSC_DECIMAL_FACTOR: 1000000000000000000,
SA_TOKEN_BSC_PANCAKE_LIQUIDITY_POOL_CONTRACT_ADDRESS: '0x7164b91db59c50156b63d0e31da08cd47b031711'
}
return thisObject
}
@@ -0,0 +1,122 @@
function newGovernanceReportsLiquidity() {
let thisObject = {
addHTML: addHTML,
initialize: initialize,
finalize: finalize
}
return thisObject
function initialize() {
}
function finalize() {
}
function addHTML(tabIndex, filters) {
/*
Parameters
*/
let table = 'Liquidity'
let programName = 'Liquidity Program'
let programPropertyName = 'liquidityProgram'
/*
Setup Filters
*/
let filtersObject
if (filters !== undefined) {
try {
filtersObject = JSON.parse(filters)
} catch (err) { }
}
/*
Other Variables
*/
let tableRecords = []
let tableRecordDefinition = {
"properties": [
{
"name": "name",
"label": "User Profile",
"type": "string",
"order": "ascending",
"textAlign": "left"
},
{
"name": "LiquidityPower",
"label": "Liquidity Power",
"type": "number",
"order": "descending",
"textAlign": "center",
"format": "2 decimals"
},
{
"name": "Percentage",
"label": "Percentage",
"type": "number",
"order": "descending",
"textAlign": "center",
"format": "percentage"
},
{
"name": "tokensAwarded",
"label": "Awarded",
"type": "number",
"order": "descending",
"textAlign": "center",
"format": "2 decimals"
}
]
}
/*
Here we get from the workspace all User Profiles.
*/
let userProfiles = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('User Profile')
/*
Transform the result array into table records.
*/
for (let j = 0; j < userProfiles.length; j++) {
let userProfile = userProfiles[j]
if (userProfile.tokenPowerSwitch === undefined) { continue }
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, programName)
if (program === undefined) { continue }
if (program.payload === undefined) { continue }
if (program.payload[programPropertyName] === undefined) { continue }
let tableRecord = {
"name": userProfile.name,
"LiquidityPower": program.payload[programPropertyName].ownPower,
"percentage": program.payload[programPropertyName].awarded.percentage,
"tokensAwarded": program.payload[programPropertyName].awarded.tokens | 0
}
if (UI.projects.governance.utilities.filters.applyFilters(filters, filtersObject, tableRecord) === true) {
tableRecords.push(tableRecord)
}
}
/*
Get the sorting order for this table.
*/
let sortingOrder = UI.projects.governance.spaces.reportsSpace.tablesSortingOrders[table]
/*
Set the default sorting order for this table.
*/
if (sortingOrder === undefined) {
UI.projects.governance.spaces.reportsSpace.tablesSortingOrders[table] = {
property: 'tokensAwarded',
order: 'descending'
}
sortingOrder = UI.projects.governance.spaces.reportsSpace.tablesSortingOrders[table]
}
return UI.projects.governance.utilities.tables.addHTML(
table,
tableRecords,
tableRecordDefinition,
sortingOrder,
tabIndex
)
}
}
@@ -41,6 +41,7 @@ function newGovernanceReportsReportsPage() {
'Claims',
'Votes',
'Staking',
'Liquidity',
'Delegation',
'Pools',
'Assets',
@@ -133,6 +134,12 @@ function newGovernanceReportsReportsPage() {
resultCounter = response.resultCounter
break
}
case 'Liquidity': {
let response = UI.projects.governance.spaces.reportsSpace.liquidity.addHTML(10, filters)
HTML = HTML + response.HTML
resultCounter = response.resultCounter
break
}
case 'Delegation': {
let response = UI.projects.governance.spaces.reportsSpace.delegation.addHTML(11, filters)
HTML = HTML + response.HTML
@@ -15,6 +15,7 @@ function newGobernanceReportsSpace() {
claims: undefined,
votes: undefined,
staking: undefined,
liquidity: undefined,
delegations: undefined,
github: undefined,
airdrop: undefined,
@@ -91,6 +92,9 @@ function newGobernanceReportsSpace() {
thisObject.staking.finalize()
thisObject.staking = undefined
thisObject.liquidity.finalize()
thisObject.liquidity = undefined
thisObject.delegation.finalize()
thisObject.delegation = undefined
@@ -150,6 +154,7 @@ function newGobernanceReportsSpace() {
thisObject.claims = newGovernanceReportsClaims()
thisObject.votes = newGovernanceReportsVotes()
thisObject.staking = newGovernanceReportsStaking()
thisObject.liquidity = newGovernanceReportsLiquidity()
thisObject.delegation = newGovernanceReportsDelegation()
thisObject.github = newGovernanceReportsGithub()
thisObject.airdrop = newGovernanceReportsAirdrop()
@@ -171,6 +176,7 @@ function newGobernanceReportsSpace() {
thisObject.claims.initialize()
thisObject.votes.initialize()
thisObject.staking.initialize()
thisObject.liquidity.initialize()
thisObject.delegation.initialize()
thisObject.github.initialize()
thisObject.airdrop.initialize()
@@ -15,7 +15,7 @@ function newGovernanceUserProfileSpace() {
}
let waitingForResponses = 0
const BSC_SCAN_RATE_LIMIT_DELAY = 6000
const BSC_SCAN_RATE_LIMIT_DELAY = 12000
let reputationByAddress = new Map()
return thisObject
@@ -422,6 +422,9 @@ function newGovernanceUserProfileSpace() {
blockchainAccount !== "" &&
userProfile.payload.blockchainTokens === undefined
) {
waitingForResponses++
userProfile.payload.liquidityTokens = 0 // We need to set this value here so that the next call to BSCSCAN is not done more than once.
setTimeout(getBPancakeTokens, BSC_SCAN_RATE_LIMIT_DELAY / 2, userProfile, blockchainAccount)
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, BSC_SCAN_RATE_LIMIT_DELAY, userProfile, blockchainAccount)
@@ -459,6 +462,36 @@ function newGovernanceUserProfileSpace() {
waitingForResponses--
});
}
function getBPancakeTokens(userProfile, blockchainAccount) {
console.log('[INFO] Loading Pancake Balance for User Profile: ', userProfile.name, 'blockchainAccount: ', blockchainAccount)
const url = "https://api.bscscan.com/api?module=account&action=tokenbalance&contractaddress=" + UI.projects.governance.globals.saToken.SA_TOKEN_BSC_PANCAKE_LIQUIDITY_POOL_CONTRACT_ADDRESS + "&address=" + blockchainAccount + "&tag=latest&apikey=YourApiKeyToken"
fetch(url).then(function (response) {
return response.json();
}).then(function (data) {
//console.log(data)
if (data.result === "Max rate limit reached, please use API Key for higher rate limit") {
userProfile.payload.liquidityTokens = undefined // This enables this profile to query the blockchain again.
} else {
userProfile.payload.uiObject.setInfoMessage('Pancake Balance Succesfully Loaded.',
UI.projects.governance.globals.designer.SET_INFO_COUNTER_FACTOR
)
userProfile.payload.liquidityTokens = Number(data.result) / 1000000000000000000
console.log('Liquidity of ' + userProfile.name + ' is ', userProfile.payload.liquidityTokens)
}
waitingForResponses--
}).catch(function (err) {
const message = err.message + ' - ' + 'Can not access BSC SCAN servers.'
console.log(message)
if (userProfile.payload !== undefined) {
userProfile.payload.uiObject.setErrorMessage(message,
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
)
}
waitingForResponses--
});
}
}
function draw() {
+3 -2
View File
@@ -135,17 +135,18 @@ function newGovernanceUtilitiesTables() {
}
}
let value = tableRecord[property]
if (value === undefined) { value = 0 }
switch (format) {
case 'text': {
break
}
case 'integer': {
value = parseFloat(parseFloat(value | 0).toFixed(0)).toLocaleString('en')
value = parseFloat(parseFloat(value).toFixed(0)).toLocaleString('en')
break
}
case '2 decimals': {
value = parseFloat(parseFloat(value | 0).toFixed(2)).toLocaleString('en')
value = parseFloat(parseFloat(value).toFixed(2)).toLocaleString('en')
break
}
case 'percentage': {
+5
View File
@@ -1239,6 +1239,11 @@
"propertyName": "stakingProgram",
"functionName": "newGovernanceFunctionLibraryStakingProgram"
},
{
"name": "Liquidity Program",
"propertyName": "liquidityProgram",
"functionName": "newGovernanceFunctionLibraryLiquidityProgram"
},
{
"name": "Profile Constructor",
"propertyName": "profileConstructor",