Skip to content

Commit

Permalink
Update TransactionClient.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai committed Jan 2, 2025
1 parent bd19bf7 commit 0c42fc3
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/clients/TransactionClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,28 @@ export class TransactionClient {

async simulateAndSubmit(chainId: number, txns: AugmentedTransaction[]): Promise<TransactionResponse[]> {
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);
}
}

0 comments on commit 0c42fc3

Please sign in to comment.