Skip to content

Commit

Permalink
group1 - multiple deelgations for BEB, multiple p-addresses, end time
Browse files Browse the repository at this point in the history
  • Loading branch information
timotejvesel committed Oct 5, 2023
1 parent f0bb9ba commit 9f18acb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 3 additions & 1 deletion p-chain-address.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ FTSO address,p chain address
0xAF7504242064532CbD3370aD7591452B1D09BBdc,flare1shr6l602f2cyg8fda4w50n2u02qscx7xnd6f2g
0x4990320858AE3528B645C60059281a66C3488888,flare12f943yd8auj7xhxn4xcht9vfpf8wvcm4952gvc
0x96616c93747baBE136bB56310bE2AE665b18dA63,flare13yt3jfxhczfmn7t9054868jknymrwjevk30rge
0x64D998BC81424131E5aF05071263fDeBD1a82986,flare19dc6w5s84wddducwhxjl9lw3vawcpcnjvqm6wj
0x64D998BC81424131E5aF05071263fDeBD1a82986,flare19dc6w5s84wddducwhxjl9lw3vawcpcnjvqm6wj
0xF0F095bbd5e2E33e9c1703cdEDd0015280406E90,flare1ewq55d8gwfd7dy06fe9wu34ge8dklhljk65dhx
0xF0F095bbd5e2E33e9c1703cdEDd0015280406E90,flare1x678p78s7wugfnz6rcd0wp0h76l7pxh9f29488
27 changes: 14 additions & 13 deletions src/services/CalculatingRewardsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9f18acb

Please sign in to comment.