Liquidity being read from different pools
This commit is contained in:
1 parent
8f2800d607
commit
815c642304
11 files changed
+788
-286
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -1064,7 +1064,7 @@
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"isCollapsed": true,
|
||||
"angleToParent": 1,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -18,16 +18,6 @@
|
||||
"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",
|
||||
@@ -68,12 +58,6 @@
|
||||
"childType": "Staking Program",
|
||||
"autoAdd": false
|
||||
},
|
||||
{
|
||||
"name": "liquidityProgram",
|
||||
"type": "node",
|
||||
"childType": "Liquidity Program",
|
||||
"autoAdd": false
|
||||
},
|
||||
{
|
||||
"name": "delegationProgram",
|
||||
"type": "node",
|
||||
|
||||
@@ -33,8 +33,7 @@
|
||||
"config": true
|
||||
},
|
||||
"initialValues": {
|
||||
"config": "{}"
|
||||
},
|
||||
"config": "{\n\"asset\": \"BTCB\"\n}" },
|
||||
"attachingRules": {
|
||||
"compatibleTypes": "->Financial Programs->"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"type": "Liquidity Programs",
|
||||
"menuItems": [
|
||||
{
|
||||
"action": "Configure",
|
||||
"actionFunction": "uiObject.configEditor.activate",
|
||||
"label": "Configure",
|
||||
"iconPathOn": "configuration",
|
||||
"iconPathOff": "configuration"
|
||||
},
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"actionProject": "Visual-Scripting",
|
||||
"actionFunction": "payload.executeAction",
|
||||
"label": "Add Liquidity Program",
|
||||
"relatedUiObject": "Liquidity Program",
|
||||
"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": "{}"
|
||||
},
|
||||
"addLeftIcons": true,
|
||||
"level": 2,
|
||||
"attachingRules": {
|
||||
"compatibleTypes": "->Token Power Switch->"
|
||||
},
|
||||
"propertyNameAtParent": "liquidityPrograms",
|
||||
"childrenNodesProperties": [
|
||||
{
|
||||
"name": "liquidityProgram",
|
||||
"type": "array",
|
||||
"childType": "Liquidity Program",
|
||||
"autoAdd": false
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -56,6 +56,16 @@
|
||||
"relatedUiObject": "Financial Programs",
|
||||
"relatedUiObjectProject": "Governance"
|
||||
},
|
||||
{
|
||||
"action": "Add UI Object",
|
||||
"actionProject": "Visual-Scripting",
|
||||
"actionFunction": "payload.executeAction",
|
||||
"disableIfPropertyIsDefined": true,
|
||||
"propertyToCheckFor": "liquidityPrograms",
|
||||
"label": "Add Liquidity Programs",
|
||||
"relatedUiObject": "Liquidity Programs",
|
||||
"relatedUiObjectProject": "Governance"
|
||||
},
|
||||
{
|
||||
"action": "Delete UI Object",
|
||||
"actionProject": "Visual-Scripting",
|
||||
@@ -109,6 +119,12 @@
|
||||
"type": "node",
|
||||
"childType": "Financial Programs",
|
||||
"autoAdd": false
|
||||
},
|
||||
{
|
||||
"name": "liquidityPrograms",
|
||||
"type": "node",
|
||||
"childType": "Liquidity Programs",
|
||||
"autoAdd": false
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -110,11 +110,22 @@ function newGovernanceFunctionLibraryDistributionProcess() {
|
||||
userProfiles
|
||||
)
|
||||
/*
|
||||
Run the Liquidity Program
|
||||
Run the Liquidity Program: One per SA Token Market
|
||||
*/
|
||||
UI.projects.governance.functionLibraries.liquidityProgram.calculate(
|
||||
pools,
|
||||
userProfiles
|
||||
userProfiles,
|
||||
'BTCB'
|
||||
)
|
||||
UI.projects.governance.functionLibraries.liquidityProgram.calculate(
|
||||
pools,
|
||||
userProfiles,
|
||||
'BNB'
|
||||
)
|
||||
UI.projects.governance.functionLibraries.liquidityProgram.calculate(
|
||||
pools,
|
||||
userProfiles,
|
||||
'BUSD'
|
||||
)
|
||||
/*
|
||||
Run the Claims Program
|
||||
|
||||
@@ -7,7 +7,8 @@ function newGovernanceFunctionLibraryLiquidityProgram() {
|
||||
|
||||
function calculate(
|
||||
pools,
|
||||
userProfiles
|
||||
userProfiles,
|
||||
asset
|
||||
) {
|
||||
let programPoolTokenReward
|
||||
/*
|
||||
@@ -20,7 +21,7 @@ function newGovernanceFunctionLibraryLiquidityProgram() {
|
||||
/* 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")
|
||||
programPoolTokenReward = UI.projects.governance.utilities.pools.findPool(poolsNode, "Liquidity-Rewards-" + asset)
|
||||
if (programPoolTokenReward !== undefined) { break }
|
||||
}
|
||||
if (programPoolTokenReward === undefined || programPoolTokenReward === 0) { return }
|
||||
@@ -29,7 +30,7 @@ function newGovernanceFunctionLibraryLiquidityProgram() {
|
||||
let userProfile = userProfiles[i]
|
||||
|
||||
if (userProfile.tokenPowerSwitch === undefined) { continue }
|
||||
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Liquidity Program")
|
||||
let program = UI.projects.governance.utilities.validations.onlyOneProgramBasedOnConfigProperty(userProfile, "Liquidity Program", 'asset', asset)
|
||||
if (program === undefined) { continue }
|
||||
if (program.payload === undefined) { continue }
|
||||
|
||||
@@ -39,7 +40,7 @@ function newGovernanceFunctionLibraryLiquidityProgram() {
|
||||
let userProfile = userProfiles[i]
|
||||
|
||||
if (userProfile.tokenPowerSwitch === undefined) { continue }
|
||||
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Liquidity Program")
|
||||
let program = UI.projects.governance.utilities.validations.onlyOneProgramBasedOnConfigProperty(userProfile, "Liquidity Program", 'asset', asset)
|
||||
if (program === undefined) { continue }
|
||||
if (program.payload === undefined) { continue }
|
||||
|
||||
@@ -49,7 +50,7 @@ function newGovernanceFunctionLibraryLiquidityProgram() {
|
||||
let userProfile = userProfiles[i]
|
||||
|
||||
if (userProfile.tokenPowerSwitch === undefined) { continue }
|
||||
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Liquidity Program")
|
||||
let program = UI.projects.governance.utilities.validations.onlyOneProgramBasedOnConfigProperty(userProfile, "Liquidity Program", 'asset', asset)
|
||||
if (program === undefined) { continue }
|
||||
if (program.payload === undefined) { continue }
|
||||
if (program.payload.liquidityProgram.isActive === false) { continue }
|
||||
@@ -60,7 +61,7 @@ function newGovernanceFunctionLibraryLiquidityProgram() {
|
||||
let userProfile = userProfiles[i]
|
||||
|
||||
if (userProfile.tokenPowerSwitch === undefined) { continue }
|
||||
let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, "Liquidity Program")
|
||||
let program = UI.projects.governance.utilities.validations.onlyOneProgramBasedOnConfigProperty(userProfile, "Liquidity Program", 'asset', asset)
|
||||
if (program === undefined) { continue }
|
||||
if (program.payload === undefined) { continue }
|
||||
if (program.payload.liquidityProgram.isActive === false) { continue }
|
||||
@@ -123,7 +124,7 @@ function newGovernanceFunctionLibraryLiquidityProgram() {
|
||||
Here we will convert Liquidity Tokens into Liquidity Power.
|
||||
As per system rules Liquidity Powar = userProfile.payload.liquidityTokens
|
||||
*/
|
||||
let programPower = userProfile.payload.liquidityTokens
|
||||
let programPower = userProfile.payload.liquidityTokens[asset]
|
||||
programNode.payload.liquidityProgram.ownPower = programPower
|
||||
|
||||
accumulatedProgramPower = accumulatedProgramPower + programPower
|
||||
|
||||
@@ -15,7 +15,7 @@ function newGovernanceUserProfileSpace() {
|
||||
}
|
||||
|
||||
let waitingForResponses = 0
|
||||
const BSC_SCAN_RATE_LIMIT_DELAY = 12000
|
||||
const BSC_SCAN_RATE_LIMIT_DELAY = 6000 * 4
|
||||
let reputationByAddress = new Map()
|
||||
|
||||
return thisObject
|
||||
@@ -423,11 +423,22 @@ function newGovernanceUserProfileSpace() {
|
||||
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)
|
||||
userProfile.payload.liquidityTokens = {
|
||||
BTCB: 0,
|
||||
BNB: 0,
|
||||
BUSD: 0
|
||||
}
|
||||
|
||||
setTimeout(getBPancakeTokens, BSC_SCAN_RATE_LIMIT_DELAY / 4 * 1, userProfile, blockchainAccount, 'BTCB', UI.projects.governance.globals.saToken.SA_TOKEN_BSC_PANCAKE_LIQUIDITY_POOL_BTCB_CONTRACT_ADDRESS)
|
||||
setTimeout(getBPancakeTokens, BSC_SCAN_RATE_LIMIT_DELAY / 4 * 2, userProfile, blockchainAccount, 'BNB', UI.projects.governance.globals.saToken.SA_TOKEN_BSC_PANCAKE_LIQUIDITY_POOL_BNB_CONTRACT_ADDRESS)
|
||||
setTimeout(getBPancakeTokens, BSC_SCAN_RATE_LIMIT_DELAY / 4 * 3, userProfile, blockchainAccount, 'BUSD', UI.projects.governance.globals.saToken.SA_TOKEN_BSC_PANCAKE_LIQUIDITY_POOL_BUSD_CONTRACT_ADDRESS)
|
||||
|
||||
/*
|
||||
Now we get the SA Tokens Balance.
|
||||
*/
|
||||
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)
|
||||
setTimeout(getBlockchainTokens, BSC_SCAN_RATE_LIMIT_DELAY / 4 * 4, userProfile, blockchainAccount)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -448,7 +459,7 @@ function newGovernanceUserProfileSpace() {
|
||||
)
|
||||
userProfile.payload.blockchainTokens = Number(data.result) / 1000000000000000000
|
||||
userProfile.payload.reputation = Math.min(reputationByAddress.get(blockchainAccount.toLowerCase()) | 0, userProfile.payload.blockchainTokens)
|
||||
console.log('Reputation of ' + userProfile.name + ' is ', userProfile.payload.reputation)
|
||||
console.log('[INFO] Reputation of ' + userProfile.name + ' is ', userProfile.payload.reputation)
|
||||
}
|
||||
waitingForResponses--
|
||||
}).catch(function (err) {
|
||||
@@ -463,9 +474,9 @@ function newGovernanceUserProfileSpace() {
|
||||
});
|
||||
}
|
||||
|
||||
function getBPancakeTokens(userProfile, blockchainAccount) {
|
||||
function getBPancakeTokens(userProfile, blockchainAccount, asset, marketContract) {
|
||||
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_BTCB_CONTRACT_ADDRESS + "&address=" + blockchainAccount + "&tag=latest&apikey=YourApiKeyToken"
|
||||
const url = "https://api.bscscan.com/api?module=account&action=tokenbalance&contractaddress=" + marketContract + "&address=" + blockchainAccount + "&tag=latest&apikey=YourApiKeyToken"
|
||||
|
||||
fetch(url).then(function (response) {
|
||||
return response.json();
|
||||
@@ -477,8 +488,8 @@ function newGovernanceUserProfileSpace() {
|
||||
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)
|
||||
userProfile.payload.liquidityTokens[asset] = Number(data.result) / 1000000000000000000
|
||||
console.log('[INFO] Liquidity of ' + userProfile.name + ' for asset ' + asset + ' is ', userProfile.payload.liquidityTokens[asset])
|
||||
}
|
||||
waitingForResponses--
|
||||
}).catch(function (err) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
function newGovernanceUtilitiesValidations () {
|
||||
function newGovernanceUtilitiesValidations() {
|
||||
let thisObject = {
|
||||
onlyOneProgram: onlyOneProgram
|
||||
onlyOneProgram: onlyOneProgram,
|
||||
onlyOneProgramBasedOnConfigProperty: onlyOneProgramBasedOnConfigProperty
|
||||
}
|
||||
|
||||
return thisObject
|
||||
@@ -15,7 +16,7 @@ function newGovernanceUtilitiesValidations () {
|
||||
userProfile.payload.uiObject.setErrorMessage(
|
||||
'Only one ' + programNodeType + ' is allowed.',
|
||||
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
|
||||
)
|
||||
)
|
||||
return
|
||||
}
|
||||
if (programs.length === 1) {
|
||||
@@ -23,4 +24,25 @@ function newGovernanceUtilitiesValidations () {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onlyOneProgramBasedOnConfigProperty(userProfile, programNodeType, configProperetyName, configProperetyValue) {
|
||||
/*
|
||||
Find all the nodes representing the current program.
|
||||
*/
|
||||
let programs = UI.projects.visualScripting.utilities.branches.nodeBranchToArray(userProfile, programNodeType)
|
||||
if (programs !== undefined) {
|
||||
for (let i = 0; i < programs.length; i++) {
|
||||
let program = programs[i]
|
||||
let propertyValue = UI.projects.visualScripting.utilities.nodeConfig.loadConfigProperty(program.payload, configProperetyName)
|
||||
if (propertyValue === configProperetyValue) {
|
||||
return program
|
||||
}
|
||||
}
|
||||
|
||||
userProfile.payload.uiObject.setErrorMessage(
|
||||
'Only one ' + programNodeType + ' is allowed. No program had a configProperty called ' + configProperetyName + ' with a value of ' + configProperetyValue,
|
||||
UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user