@@ -43,32 +43,18 @@ contract HubReader {
4343 *
4444 * @return The validators
4545 */
46- function getValidators (
47- uint16 offset ,
48- uint16 limit
49- ) external view returns (Validator[] memory ) {
50- (address [] memory operatorAddrs , , uint256 totalLength ) = stakeHub
51- .getValidators (offset, limit);
46+ function getValidators (uint16 offset , uint16 limit ) external view returns (Validator[] memory ) {
47+ (address [] memory operatorAddrs ,, uint256 totalLength ) = stakeHub.getValidators (offset, limit);
5248 uint256 validatorCount = totalLength < limit ? totalLength : limit;
5349 Validator[] memory validators = new Validator [](validatorCount);
5450
5551 for (uint256 i = 0 ; i < validatorCount; i++ ) {
56- (, bool jailed , ) = stakeHub.getValidatorBasicInfo (
57- operatorAddrs[i]
58- );
59- string memory moniker = stakeHub
60- .getValidatorDescription (operatorAddrs[i])
61- .moniker;
62- uint64 rate = stakeHub
63- .getValidatorCommission (operatorAddrs[i])
64- .rate;
52+ (, bool jailed ,) = stakeHub.getValidatorBasicInfo (operatorAddrs[i]);
53+ string memory moniker = stakeHub.getValidatorDescription (operatorAddrs[i]).moniker;
54+ uint64 rate = stakeHub.getValidatorCommission (operatorAddrs[i]).rate;
6555
6656 validators[i] = Validator ({
67- operatorAddress: operatorAddrs[i],
68- moniker: moniker,
69- commission: rate,
70- jailed: jailed,
71- apy: 0
57+ operatorAddress: operatorAddrs[i], moniker: moniker, commission: rate, jailed: jailed, apy: 0
7258 });
7359 }
7460 uint64 [] memory apys = this .getAPYs (operatorAddrs, block .timestamp );
@@ -86,16 +72,13 @@ contract HubReader {
8672 *
8773 * @return The delegations of the delegator
8874 */
89- function getDelegations (
90- address delegator ,
91- uint16 offset ,
92- uint16 limit
93- ) external view returns (Delegation[] memory ) {
94- (
95- address [] memory operatorAddrs ,
96- address [] memory creditAddrs ,
97- uint256 totalLength
98- ) = stakeHub.getValidators (offset, limit);
75+ function getDelegations (address delegator , uint16 offset , uint16 limit )
76+ external
77+ view
78+ returns (Delegation[] memory )
79+ {
80+ (address [] memory operatorAddrs , address [] memory creditAddrs , uint256 totalLength ) =
81+ stakeHub.getValidators (offset, limit);
9982 uint256 validatorCount = totalLength < limit ? totalLength : limit;
10083 uint256 delegationCount = 0 ;
10184 Delegation[] memory delegations = new Delegation [](validatorCount);
@@ -107,10 +90,7 @@ contract HubReader {
10790
10891 if (amount > 0 ) {
10992 delegations[delegationCount] = Delegation ({
110- delegatorAddress: delegator,
111- validatorAddress: operatorAddrs[i],
112- shares: shares,
113- amount: amount
93+ delegatorAddress: delegator, validatorAddress: operatorAddrs[i], shares: shares, amount: amount
11494 });
11595 delegationCount++ ;
11696 }
@@ -131,38 +111,29 @@ contract HubReader {
131111 *
132112 * @return The undelegations of the delegator
133113 */
134- function getUndelegations (
135- address delegator ,
136- uint16 offset ,
137- uint16 limit
138- ) external view returns (Undelegation[] memory ) {
139- (
140- address [] memory operatorAddrs ,
141- address [] memory creditAddrs ,
142- uint256 totalLength
143- ) = stakeHub.getValidators (offset, limit);
114+ function getUndelegations (address delegator , uint16 offset , uint16 limit )
115+ external
116+ view
117+ returns (Undelegation[] memory )
118+ {
119+ (address [] memory operatorAddrs , address [] memory creditAddrs , uint256 totalLength ) =
120+ stakeHub.getValidators (offset, limit);
144121 uint256 validatorCount = totalLength < limit ? totalLength : limit;
145122
146123 // first loop to get the number of unbond requests
147124 uint256 undelegationCount = 0 ;
148125 for (uint256 i = 0 ; i < validatorCount; i++ ) {
149- undelegationCount += IStakeCredit (creditAddrs[i])
150- .pendingUnbondRequest (delegator);
126+ undelegationCount += IStakeCredit (creditAddrs[i]).pendingUnbondRequest (delegator);
151127 }
152128
153- Undelegation[] memory undelegations = new Undelegation [](
154- undelegationCount
155- );
129+ Undelegation[] memory undelegations = new Undelegation [](undelegationCount);
156130
157131 // resuse same local variable
158132 undelegationCount = 0 ;
159133 for (uint256 i = 0 ; i < validatorCount; i++ ) {
160- uint256 unbondCount = IStakeCredit (creditAddrs[i])
161- .pendingUnbondRequest (delegator);
134+ uint256 unbondCount = IStakeCredit (creditAddrs[i]).pendingUnbondRequest (delegator);
162135 for (uint256 j = 0 ; j < unbondCount; j++ ) {
163- IStakeCredit.UnbondRequest memory req = IStakeCredit (
164- creditAddrs[i]
165- ).unbondRequest (delegator, j);
136+ IStakeCredit.UnbondRequest memory req = IStakeCredit (creditAddrs[i]).unbondRequest (delegator, j);
166137 undelegations[undelegationCount] = Undelegation ({
167138 delegatorAddress: delegator,
168139 validatorAddress: operatorAddrs[i],
@@ -183,28 +154,22 @@ contract HubReader {
183154 *
184155 * @return The APYs of the validator in basis points, e.g. 195 is 1.95%
185156 */
186- function getAPYs (
187- address [] memory operatorAddrs ,
188- uint256 timestamp
189- ) external view returns (uint64 [] memory ) {
157+ // forge-lint: disable-next-line(mixed-case-function)
158+ function getAPYs (address [] memory operatorAddrs , uint256 timestamp ) external view returns (uint64 [] memory ) {
190159 uint256 dayIndex = timestamp / stakeHub.BREATHE_BLOCK_INTERVAL ();
191160 uint256 length = operatorAddrs.length ;
192161 uint64 [] memory apys = new uint64 [](length);
193162 for (uint256 i = 0 ; i < length; i++ ) {
194- uint256 total = stakeHub.getValidatorTotalPooledBNBRecord (
195- operatorAddrs[i],
196- dayIndex
197- );
163+ uint256 total = stakeHub.getValidatorTotalPooledBNBRecord (operatorAddrs[i], dayIndex);
198164 if (total == 0 ) {
199165 continue ;
200166 }
201- uint256 reward = stakeHub.getValidatorRewardRecord (
202- operatorAddrs[i],
203- dayIndex
204- );
167+ uint256 reward = stakeHub.getValidatorRewardRecord (operatorAddrs[i], dayIndex);
205168 if (reward == 0 ) {
206169 continue ;
207170 }
171+ // casting to uint64 is safe because APY basis points from hub totals fit in 64 bits
172+ // forge-lint: disable-next-line(unsafe-typecast)
208173 apys[i] = uint64 ((reward * 365 * 10000 ) / total);
209174 }
210175 return apys;
0 commit comments