diff --git a/src/clients/TransactionClient.ts b/src/clients/TransactionClient.ts index f009c4ea6..d8a1c7819 100644 --- a/src/clients/TransactionClient.ts +++ b/src/clients/TransactionClient.ts @@ -124,26 +124,28 @@ export class TransactionClient { async simulateAndSubmit(chainId: number, txns: AugmentedTransaction[]): Promise { const simulationResults = await this.simulate(txns); - const txnsToSubmit: AugmentedTransaction[] = []; this.logger.debug({ at: "TransactionClient", message: `Simulating ${txns.length} transactions before submitting the ones that pass simulation`, }); - for (let i = 0; i < simulationResults.length; i++) { - const { reason, succeed, transaction } = simulationResults[i]; - const { contract: targetContract, ...txnRequestData } = transaction; - if (!succeed) { - this.logger.warn({ - at: "TransactionClient", - message: `Failed to simulate calling ${transaction.method} on chain ${chainId}`, - reason, - contract: targetContract.address, - txnRequestData, - }); - } else { - txnsToSubmit.push(txns[i]); - } - } + const txnsToSubmit: AugmentedTransaction[] = simulationResults.reduce( + (_txnsToSubmit, { reason, succeed, transaction }, i) => { + const { contract: targetContract, ...txnRequestData } = transaction; + if (!succeed) { + this.logger.warn({ + at: "TransactionClient", + message: `Failed to simulate calling ${transaction.method} on chain ${chainId}`, + reason, + contract: targetContract.address, + txnRequestData, + }); + } else { + _txnsToSubmit.push(txns[i]); + } + return _txnsToSubmit; + }, + [] + ); return await this.submit(chainId, txnsToSubmit); } }