feat: add withdrawal simulation to relayer

This commit is contained in:
casiojapi
2025-04-14 19:02:36 -03:00
parent 49eda747cb
commit 5126c07a98
2 changed files with 14 additions and 0 deletions

View File

@@ -59,6 +59,14 @@ export class PrivacyPoolRelayer {
throw ZkError.invalidProof();
}
// simulate tx before broadcasting
const simulationResult = await this.sdkProvider.simulateWithdrawal(req, chainId);
if (!simulationResult.success) {
const simulationError = simulationResult.error || "Unknown simulation failure";
throw BlockchainError.txSimulationError(`Relay simulation failed: ${simulationError}`);
}
const response = await this.broadcastWithdrawal(req, chainId);
await this.db.updateBroadcastedRequest(requestId, response.hash);

View File

@@ -38,6 +38,12 @@ export interface ContractInteractions {
scope: Hash,
): Promise<TransactionResponse>;
simulateRelay(
withdrawal: Withdrawal,
withdrawalProof: WithdrawalProof,
scope: Hash
): Promise<{ success: boolean; gasEstimate?: bigint; error?: string }>;
ragequit(
commitmentProof: CommitmentProof,
privacyPoolAddress: Address,