@@ -186,13 +186,17 @@ export class AllocationManager {
186
186
// We need to process both staking contract and subgraph service transactions separately
187
187
// as they cannot be multicalled
188
188
// Realistically, the only scenario where a batch would have both is shortly after the horizon upgrade
189
+ const stakingTransactions = preparedTransactions . filter (
190
+ ( tx : TransactionRequest ) =>
191
+ tx . to === this . network . contracts . HorizonStaking . target ,
192
+ )
193
+ const subgraphServiceTransactions = preparedTransactions . filter (
194
+ ( tx : TransactionRequest ) =>
195
+ tx . to === this . network . contracts . SubgraphService . target ,
196
+ )
189
197
190
198
// -- STAKING CONTRACT --
191
- const callDataStakingContract = preparedTransactions
192
- . filter (
193
- ( tx : TransactionRequest ) =>
194
- tx . to === this . network . contracts . HorizonStaking . target ,
195
- )
199
+ const callDataStakingContract = stakingTransactions
196
200
. filter ( ( tx : TransactionRequest ) => ! ! tx . data )
197
201
. map ( ( tx ) => tx . data as string )
198
202
@@ -221,41 +225,33 @@ export class AllocationManager {
221
225
)
222
226
223
227
// Mark all actions with staking contract transactions as successful
224
- for ( const preparedTransaction of preparedTransactions ) {
225
- if ( preparedTransaction . to === this . network . contracts . HorizonStaking . target ) {
226
- actionResults . push ( {
227
- actionID : preparedTransaction . actionID ,
228
- success : true ,
229
- result : stakingTransactionResult ,
230
- } )
231
- }
228
+ for ( const transaction of stakingTransactions ) {
229
+ actionResults . push ( {
230
+ actionID : transaction . actionID ,
231
+ success : true ,
232
+ result : stakingTransactionResult ,
233
+ } )
232
234
}
233
235
} catch ( error ) {
234
236
logger . error ( 'Failed to execute staking contract transaction' , { error } )
235
237
236
238
// Mark all actions with staking contract transactions as failed
237
- for ( const preparedTransaction of preparedTransactions ) {
238
- if ( preparedTransaction . to === this . network . contracts . HorizonStaking . target ) {
239
- actionResults . push ( {
240
- actionID : preparedTransaction . actionID ,
241
- success : false ,
242
- result : {
243
- actionID : preparedTransaction . actionID ,
244
- failureReason : `Failed to execute staking contract transaction: ${ error . message } ` ,
245
- protocolNetwork : preparedTransaction . protocolNetwork ,
246
- } ,
247
- } )
248
- }
239
+ for ( const transaction of stakingTransactions ) {
240
+ actionResults . push ( {
241
+ actionID : transaction . actionID ,
242
+ success : false ,
243
+ result : {
244
+ actionID : transaction . actionID ,
245
+ failureReason : `Failed to execute staking contract transaction: ${ error . message } ` ,
246
+ protocolNetwork : transaction . protocolNetwork ,
247
+ } ,
248
+ } )
249
249
}
250
250
}
251
251
}
252
252
253
253
// -- SUBGRAPH SERVICE --
254
- const callDataSubgraphService = preparedTransactions
255
- . filter (
256
- ( tx : TransactionRequest ) =>
257
- tx . to === this . network . contracts . SubgraphService . target ,
258
- )
254
+ const callDataSubgraphService = subgraphServiceTransactions
259
255
// Reallocate of a legacy allocation during the transition period can result in
260
256
// a staking and subgraph service transaction in the same batch. If the staking tx failed we
261
257
// should not execute the subgraph service tx.
@@ -291,31 +287,27 @@ export class AllocationManager {
291
287
)
292
288
293
289
// Mark all actions with subgraph service transactions as successful
294
- for ( const preparedTransaction of preparedTransactions ) {
295
- if ( preparedTransaction . to === this . network . contracts . SubgraphService . target ) {
296
- actionResults . push ( {
297
- actionID : preparedTransaction . actionID ,
298
- success : true ,
299
- result : subgraphServiceTransactionResult ,
300
- } )
301
- }
290
+ for ( const transaction of subgraphServiceTransactions ) {
291
+ actionResults . push ( {
292
+ actionID : transaction . actionID ,
293
+ success : true ,
294
+ result : subgraphServiceTransactionResult ,
295
+ } )
302
296
}
303
297
} catch ( error ) {
304
298
logger . error ( 'Failed to execute subgraph service transaction' , { error } )
305
299
306
300
// Mark all actions with subgraph service transactions as failed
307
- for ( const preparedTransaction of preparedTransactions ) {
308
- if ( preparedTransaction . to === this . network . contracts . SubgraphService . target ) {
309
- actionResults . push ( {
310
- actionID : preparedTransaction . actionID ,
311
- success : false ,
312
- result : {
313
- actionID : preparedTransaction . actionID ,
314
- failureReason : `Failed to execute subgraph service transaction: ${ error . message } ` ,
315
- protocolNetwork : preparedTransaction . protocolNetwork ,
316
- } ,
317
- } )
318
- }
301
+ for ( const transaction of subgraphServiceTransactions ) {
302
+ actionResults . push ( {
303
+ actionID : transaction . actionID ,
304
+ success : false ,
305
+ result : {
306
+ actionID : transaction . actionID ,
307
+ failureReason : `Failed to execute subgraph service transaction: ${ error . message } ` ,
308
+ protocolNetwork : transaction . protocolNetwork ,
309
+ } ,
310
+ } )
319
311
}
320
312
}
321
313
}
0 commit comments