11const KeepRandomBeaconServiceImplV1 = artifacts . require ( "KeepRandomBeaconServiceImplV1.sol" ) ;
22const KeepRandomBeaconService = artifacts . require ( 'KeepRandomBeaconService.sol' ) ;
33const KeepRandomBeaconOperator = artifacts . require ( 'KeepRandomBeaconOperator.sol' ) ;
4+ const KeepRandomBeaconOperatorStatistics = artifacts . require ( 'KeepRandomBeaconOperatorStatistics.sol' ) ;
45const fs = require ( 'fs' ) ;
56
67// MAKE SURE NONE OF THOSE ACCOUNTS IS A MINER ACCOUNT
@@ -20,6 +21,7 @@ module.exports = async function() {
2021 const keepRandomBeaconService = await KeepRandomBeaconService . deployed ( ) ;
2122 const contractService = await KeepRandomBeaconServiceImplV1 . at ( keepRandomBeaconService . address ) ;
2223 const contractOperator = await KeepRandomBeaconOperator . deployed ( ) ;
24+ const contractStatistics = await KeepRandomBeaconOperatorStatistics . deployed ( ) ;
2325
2426 let accounts = operators . slice ( ) ;
2527 accounts . push ( requestor ) ;
@@ -39,7 +41,7 @@ module.exports = async function() {
3941
4042 for ( let i = 0 ; i < accounts . length ; i ++ ) {
4143 prevBalances [ i ] = await web3 . eth . getBalance ( accounts [ i ] ) ;
42- prevRewards [ i ] = ( await availableRewards ( accounts [ i ] , contractOperator ) ) . toString ( ) ;
44+ prevRewards [ i ] = ( await availableRewards ( accounts [ i ] , contractOperator , contractStatistics ) ) . toString ( ) ;
4345 }
4446
4547 let gasPrice = await web3 . eth . getGasPrice ( ) ;
@@ -79,7 +81,7 @@ module.exports = async function() {
7981 const balance = await web3 . eth . getBalance ( address ) ;
8082 const balanceChange = web3 . utils . toBN ( balance ) . sub ( web3 . utils . toBN ( prevBalances [ i ] ) ) . toString ( ) ;
8183
82- const reward = ( await availableRewards ( address , contractOperator ) ) . toString ( ) ;
84+ const reward = ( await availableRewards ( address , contractOperator , contractStatistics ) ) . toString ( ) ;
8385 const rewardChange = web3 . utils . toBN ( reward ) . sub ( web3 . utils . toBN ( prevRewards [ i ] ) ) . toString ( ) ;
8486
8587 const pricingClient = new PricingClient (
@@ -110,7 +112,7 @@ module.exports = async function() {
110112 }
111113} ;
112114
113- async function availableRewards ( account , contractOperator ) {
115+ async function availableRewards ( account , contractOperator , contractStatistics ) {
114116 const expiredGroupCount = ( await contractOperator . getFirstActiveGroupIndex ( ) ) . toNumber ( ) ;
115117 const activeGroupCount = ( await contractOperator . numberOfGroups ( ) ) . toNumber ( ) ;
116118 const totalGroupCount = expiredGroupCount + activeGroupCount ;
@@ -122,9 +124,9 @@ async function availableRewards(account, contractOperator) {
122124
123125 let accountRewards = web3 . utils . toBN ( 0 ) ;
124126 for ( let i = 0 ; i < groupsPublicKeys . length ; i ++ ) {
125- const groupMembersCount = ( await contractOperator . getGroupMemberIndices ( groupsPublicKeys [ i ] , account ) ) . length ;
127+ const groupMembersCount = await contractStatistics . countGroupMembership ( groupsPublicKeys [ i ] , account ) ;
126128 const groupMemberReward = await contractOperator . getGroupMemberRewards ( groupsPublicKeys [ i ] ) ;
127- accountRewards = accountRewards . add ( web3 . utils . toBN ( groupMembersCount ) . mul ( groupMemberReward ) ) ;
129+ accountRewards = accountRewards . add ( groupMembersCount . mul ( groupMemberReward ) ) ;
128130 }
129131
130132 return accountRewards ;
@@ -170,4 +172,4 @@ PricingClient.prototype.toString = function pricingClientToString() {
170172
171173function wait ( ms ) {
172174 return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
173- }
175+ }
0 commit comments