Skip to content

Commit 0d763c8

Browse files
committed
return apy for validators call
1 parent 18133fd commit 0d763c8

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

bsc/hub_reader/src/HubReader.sol

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct Validator {
99
bool jailed;
1010
string moniker;
1111
uint64 commission;
12+
uint64 apy;
1213
}
1314

1415
struct Delegation {
@@ -25,7 +26,9 @@ contract HubReader {
2526
}
2627

2728
/*
28-
* @dev Get validators by offset and limit (pagination)
29+
* @dev Get validators by offset and limit (pagination), this is an intense function that execution might revert if limit is too large
30+
* for some node, the best way to call it is to use a batch JSON RPC calls with proper pagination (e.g. 15 or 20 validators per call)
31+
2932
* @param offset The offset to query validators
3033
* @param limit The limit to query validators
3134
*
@@ -55,9 +58,14 @@ contract HubReader {
5558
operatorAddress: operatorAddrs[i],
5659
moniker: moniker,
5760
commission: rate,
58-
jailed: jailed
61+
jailed: jailed,
62+
apy: 0
5963
});
6064
}
65+
uint64[] memory apys = this.getAPYs(operatorAddrs, block.timestamp);
66+
for (uint256 i = 0; i < validatorCount; i++) {
67+
validators[i].apy = apys[i];
68+
}
6169
return validators;
6270
}
6371

@@ -123,11 +131,14 @@ contract HubReader {
123131
operatorAddrs[i],
124132
dayIndex
125133
);
134+
if (total == 0) {
135+
continue;
136+
}
126137
uint256 reward = stakeHub.getValidatorRewardRecord(
127138
operatorAddrs[i],
128139
dayIndex
129140
);
130-
if (total == 0 || reward == 0) {
141+
if (reward == 0) {
131142
continue;
132143
}
133144
apys[i] = uint64((reward * 365 * 10000) / total);

0 commit comments

Comments
 (0)