From 9f18acb448fb7b2e22a0c05615c7f76a5ba2b664 Mon Sep 17 00:00:00 2001 From: Timotej Vesel Date: Thu, 5 Oct 2023 13:17:31 +0200 Subject: [PATCH] group1 - multiple deelgations for BEB, multiple p-addresses, end time --- p-chain-address.csv | 4 +++- src/services/CalculatingRewardsService.ts | 27 ++++++++++++----------- src/utils/interfaces.ts | 2 +- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/p-chain-address.csv b/p-chain-address.csv index fc3de86..5757f77 100644 --- a/p-chain-address.csv +++ b/p-chain-address.csv @@ -5,4 +5,6 @@ FTSO address,p chain address 0xAF7504242064532CbD3370aD7591452B1D09BBdc,flare1shr6l602f2cyg8fda4w50n2u02qscx7xnd6f2g 0x4990320858AE3528B645C60059281a66C3488888,flare12f943yd8auj7xhxn4xcht9vfpf8wvcm4952gvc 0x96616c93747baBE136bB56310bE2AE665b18dA63,flare13yt3jfxhczfmn7t9054868jknymrwjevk30rge -0x64D998BC81424131E5aF05071263fDeBD1a82986,flare19dc6w5s84wddducwhxjl9lw3vawcpcnjvqm6wj \ No newline at end of file +0x64D998BC81424131E5aF05071263fDeBD1a82986,flare19dc6w5s84wddducwhxjl9lw3vawcpcnjvqm6wj +0xF0F095bbd5e2E33e9c1703cdEDd0015280406E90,flare1ewq55d8gwfd7dy06fe9wu34ge8dklhljk65dhx +0xF0F095bbd5e2E33e9c1703cdEDd0015280406E90,flare1x678p78s7wugfnz6rcd0wp0h76l7pxh9f29488 \ No newline at end of file diff --git a/src/services/CalculatingRewardsService.ts b/src/services/CalculatingRewardsService.ts index c792735..122f604 100644 --- a/src/services/CalculatingRewardsService.ts +++ b/src/services/CalculatingRewardsService.ts @@ -133,10 +133,11 @@ export class CalculatingRewardsService { node.delegators = delegators; node.totalStakeAmount = node.selfBond + node.boost + selfDelegation + normalDelegations; } - if (node.pChainAddress !== "") { - node.cChainAddress = await addressBinder.methods.pAddressToCAddress(pAddressToBytes20(node.pChainAddress)).call(); - } else { + if (node.pChainAddress.length === 0) { this.logger.error(`FTSO ${node.ftsoAddress} did not provide its p-chain address`); + } else { + node.pChainAddress.sort((a, b) => a.toLowerCase() > b.toLowerCase() ? 1 : -1); + node.cChainAddress = await addressBinder.methods.pAddressToCAddress(pAddressToBytes20(node.pChainAddress[0])).call(); } if (node.cChainAddress === ZERO_ADDRESS) { this.logger.error(`Validator address ${node.pChainAddress} is not binded`); @@ -355,18 +356,22 @@ export class CalculatingRewardsService { nodeObj.selfBond = node.weight; nodeObj.ftsoAddress = ftsoAddress; nodeObj.stakeEnd = node.endTime; + nodeObj.pChainAddress = []; // node is in group 1 if (boostingAddresses.includes(node.inputAddresses[0]) && node.weight == BigInt(10000000 * 1e9)) { // bind p chain address to node id - const pAddr = pChainAddresses.find((obj) => obj.ftsoAddress == nodeObj.ftsoAddress); - nodeObj.pChainAddress = pAddr ? pAddr.pChainAddress : ""; + for (let obj of pChainAddresses) { + if (obj.ftsoAddress == nodeObj.ftsoAddress) { + nodeObj.pChainAddress.push(obj.pChainAddress); + } + } nodeObj.fee = defaultFee; nodeObj.group = 1; return nodeObj; } nodeObj.fee = node.feePercentage; - nodeObj.pChainAddress = nodeObj.bondingAddress; + nodeObj.pChainAddress.push(nodeObj.bondingAddress); nodeObj.group = 2 return nodeObj; } @@ -459,13 +464,9 @@ export class CalculatingRewardsService { if (delegation.nodeID !== node.nodeId) continue; // self-delegation - if (delegation.inputAddresses[0] === node.pChainAddress) { + if (node.pChainAddress.includes(delegation.inputAddresses[0])) { selfDelegations += delegation.weight; - // first self-delegation; delegations are sorted by start time, therefore the first one will always be taken - if (delegation.startTime < firstDelegationStartTime && delegation.endTime == node.stakeEnd) { - BEB = delegation.weight; - firstDelegationStartTime = delegation.startTime; - } + BEB += delegation.weight; } // FNL delegation (boosting) else if (boostingAddresses.includes(delegation.inputAddresses[0])) { @@ -503,7 +504,7 @@ export class CalculatingRewardsService { if (delegation.nodeID !== node.nodeId) continue; // self-delegation - if (delegation.inputAddresses[0] === node.pChainAddress) { + if (node.pChainAddress.includes(delegation.inputAddresses[0])) { selfDelegations += delegation.weight; } // FNL delegation (boosting) diff --git a/src/utils/interfaces.ts b/src/utils/interfaces.ts index 11d10be..6e8ee9f 100644 --- a/src/utils/interfaces.ts +++ b/src/utils/interfaces.ts @@ -34,7 +34,7 @@ export interface ActiveNode { bondingAddress: string; // p-chain address that opened stake ftsoAddress: string; // ftso (entity) address selfBond: bigint; // initial stake - pChainAddress: string; // p-chain address corresponding to validator (for group 2 it is same as bonding address) + pChainAddress: string[]; // p-chain address corresponding to validator (for group 2 it is same as bonding address) // used for self-delegations cChainAddress?: string // c-chain address (used for rewarding) corresponding to p-chain address selfDelegations: bigint; // delegations from validator to its node