Skip to content

Commit 19f4758

Browse files
authored
Fixes for simulation on error & other fixes (#471)
1 parent ff331fd commit 19f4758

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
lines changed

src/db/transactions/getSentTxs.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export const getSentTxs = async ({ pgtx }: GetSentTxsParams = {}): Promise<
2121
AND "accountAddress" IS NULL
2222
AND "minedAt" IS NULL
2323
AND "errorMessage" IS NULL
24-
AND "retryCount" < ${config.maxTxsToUpdate}
2524
ORDER BY "nonce" ASC
2625
LIMIT ${config.maxTxsToUpdate}
2726
FOR UPDATE SKIP LOCKED

src/db/transactions/updateTx.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export const updateTx = async ({ pgtx, queueId, data }: UpdateTxParams) => {
9696
gasLimit: data.res?.gasLimit?.toString(),
9797
maxFeePerGas: data.res?.maxFeePerGas?.toString(),
9898
maxPriorityFeePerGas: data.res?.maxPriorityFeePerGas?.toString(),
99+
value: data.res?.value?.toString(),
99100
},
100101
});
101102
break;
@@ -119,13 +120,11 @@ export const updateTx = async ({ pgtx, queueId, data }: UpdateTxParams) => {
119120
minedAt: data.minedAt,
120121
blockNumber: data.blockNumber,
121122
onChainTxStatus: data.onChainTxStatus,
122-
transactionHash: data.transactionHash,
123123
transactionType: data.transactionType,
124124
gasPrice: data.gasPrice,
125125
gasLimit: data.gasLimit,
126126
maxFeePerGas: data.maxFeePerGas,
127127
maxPriorityFeePerGas: data.maxPriorityFeePerGas,
128-
nonce: data.nonce,
129128
},
130129
});
131130
break;

src/utils/errors.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,30 @@ export const parseTxError = async (
2828
return "Unexpected error.";
2929
}
3030

31-
const chain = await getChainByChainIdAsync(Number(tx.chainId));
31+
// EOA transactions
32+
if (tx.toAddress && tx.fromAddress && tx.data) {
33+
const chain = await getChainByChainIdAsync(Number(tx.chainId));
3234

33-
if ((err as EthersError)?.code === ethers.errors.INSUFFICIENT_FUNDS) {
34-
return `Insufficient ${chain.nativeCurrency?.symbol} on ${
35-
chain.name
36-
} in backend wallet ${tx.fromAddress!}.`;
37-
}
35+
if ((err as EthersError)?.code === ethers.errors.INSUFFICIENT_FUNDS) {
36+
return `Insufficient ${chain.nativeCurrency?.symbol} on ${chain.name} in backend wallet ${tx.fromAddress}.`;
37+
}
3838

39-
if ((err as EthersError)?.code === ethers.errors.UNPREDICTABLE_GAS_LIMIT) {
40-
try {
41-
const transaction = prepareTransaction({
42-
to: tx.toAddress!,
43-
value: BigInt(tx.value!),
44-
data: tx.data! as `0x${string}`,
45-
chain: {
46-
id: Number(tx.chainId!),
47-
rpc: chain.rpc[0],
48-
},
49-
client,
50-
});
51-
await simulateTransaction({ transaction, from: tx.fromAddress! });
52-
} catch (simErr: any) {
53-
return simErr?.message ?? simErr.toString();
39+
if ((err as EthersError)?.code === ethers.errors.UNPREDICTABLE_GAS_LIMIT) {
40+
try {
41+
const transaction = prepareTransaction({
42+
to: tx.toAddress,
43+
value: BigInt(tx.value || "0"),
44+
data: tx.data as `0x${string}`,
45+
chain: {
46+
id: Number(tx.chainId),
47+
rpc: chain.rpc[0],
48+
},
49+
client,
50+
});
51+
await simulateTransaction({ transaction, from: tx.fromAddress });
52+
} catch (simErr: any) {
53+
return simErr?.message ?? simErr.toString();
54+
}
5455
}
5556
}
5657

src/worker/tasks/updateMinedTx.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ export const updateMinedTx = async () => {
2828
return;
2929
}
3030

31-
const droppedTxs: (Transactions & { provider?: string })[] = [];
32-
3331
const txsWithReceipts = (
3432
await Promise.all(
3533
txs.map(async (tx) => {

0 commit comments

Comments
 (0)