1
+ import { GroupRunner } from '@chainlink/external-adapter-framework/util/group-runner'
1
2
import BigNumber from 'bignumber.js'
2
3
import { ethers } from 'ethers'
3
4
import {
@@ -20,7 +21,7 @@ import { StaderConfig } from './utils/stader-config'
20
21
import { PermissionedPool } from './utils/permissioned-pool'
21
22
import { StakeManager } from './utils/stake-manager'
22
23
import { Pool } from './utils/pool'
23
- import { ValidatorFactory } from './utils/validator'
24
+ import { ValidatorFactory , type ActiveValidator , type WithdrawnValidator } from './utils/validator'
24
25
import { DepositEvent_ABI , StaderPenaltyContract_ABI } from '../config/StaderContractAbis'
25
26
import { SubscriptionTransport } from '@chainlink/external-adapter-framework/transports/abstract/subscription'
26
27
import { TransportDependencies } from '@chainlink/external-adapter-framework/transports'
@@ -170,30 +171,27 @@ export class BalanceTransport extends SubscriptionTransport<BaseEndpointTypes> {
170
171
171
172
const validatorBalances = [ ]
172
173
174
+ const calculateWithdrawnBalanceInGroups = new GroupRunner (
175
+ context . adapterSettings . GROUP_SIZE ,
176
+ ) . wrapFunction ( ( v : WithdrawnValidator ) => v . calculateBalance ( validatorDeposit ) )
177
+
173
178
// Perform active validator calculations
174
179
// These will need a call to get the penalty rate for each of them, so we have to batch these
175
- const withdrawnBatches = splitArrayIntoChunks (
176
- withdrawnValidators ,
180
+ validatorBalances . push (
181
+ ...( await Promise . all ( withdrawnValidators . map ( ( v ) => calculateWithdrawnBalanceInGroups ( v ) ) ) ) ,
182
+ )
183
+
184
+ const calculateActiveBalanceInGroups = new GroupRunner (
177
185
context . adapterSettings . GROUP_SIZE ,
186
+ ) . wrapFunction ( ( v : ActiveValidator ) =>
187
+ v . calculateBalance ( validatorDeposit , depositedBalanceMap [ v . addressData . address ] ) ,
178
188
)
179
- for ( const batch of withdrawnBatches ) {
180
- validatorBalances . push (
181
- ...( await Promise . all ( batch . map ( ( v ) => v . calculateBalance ( validatorDeposit ) ) ) ) ,
182
- )
183
- }
184
189
185
190
// Perform active validator calculations
186
191
// These will need a call to get the penalty rate for each of them, so we have to batch these
187
- const activeBatches = splitArrayIntoChunks ( activeValidators , context . adapterSettings . GROUP_SIZE )
188
- for ( const batch of activeBatches ) {
189
- validatorBalances . push (
190
- ...( await Promise . all (
191
- batch . map ( ( v ) =>
192
- v . calculateBalance ( validatorDeposit , depositedBalanceMap [ v . addressData . address ] ) ,
193
- ) ,
194
- ) ) ,
195
- )
196
- }
192
+ validatorBalances . push (
193
+ ...( await Promise . all ( activeValidators . map ( ( v ) => calculateActiveBalanceInGroups ( v ) ) ) ) ,
194
+ )
197
195
198
196
// Flatten all the balances out, they'll be aggregated in the proof-of-reserves EA
199
197
const balances = [
0 commit comments