engine
engine copied to clipboard
Atomic Transactions Processing
Part of my issue is processing transactions from same wallet by order.
I can verify from engine code that queued transactions are fetched from db with asc queuedAt it means FIFO
But here is an example of batch transaction and this happens also when i send 2 seperate TXs 1 after another with 1 second offset in time.
Below are 2 TXs ( Approve and Swap )
Its clear from the code that approval tx status changes to Sent before the swap tx .. But Swap tx is always failing because no allowance.
If i do the aproval first then wait few seconds and i execute same data for the swap , it succeed.
[ { "toAddress": "0xfff9976782d46cc05630d1f6ebab18b2324d6b14", "data": "0x095ea7b30000000000000000000000003bfa4769fb09eefc5a80d6e87c3b9c650f7ae48e00000000000000000000000000000000000004ee2d6d415b85acef8100000000", "value": "0x00", "txOverrides": { "gas": "70000" } }, { "toAddress": "0x3bFA4769FB09eefC5a80d6E87c3B9C650f7Ae48E", "data": "0x04e45aaf000000000000000000000000fff9976782d46cc05630d1f6ebab18b2324d6b140000000000000000000000001c7d4b196cb0c7b01d743fbc6116a902379c72380000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000003187fc5d134b4d21331a715abf58b1e9e580e56900000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "value": "0x00", "txOverrides": { "gas": "220000" } } ]
Here is the wallet:
https://sepolia.etherscan.io/address/0x2ef4075c77a6a6da393057880400794da57f4400
Its clear that sometimes only approval gets executed and sometimes both because i offset both tx by few seconds.
Is there a solution for dependent Txs like this use case? ( gas transfer from hot wallet >> Approval if needed >> Swap )
Isnt supposed that nonce force Txs from same wallet to be executed by right sequence?
As of now, there is no solution for dependent tx or ordering txs on Engine. The way to achieve this now is by sending the first transaction, waiting for it to get mined onchain and then sending the next transaction.
Isnt supposed that nonce force Txs from same wallet to be executed by right sequence?
Engine gets the transactions in order of queuedAt time, as you already noted. But, when we are sending the transactions, this step happens in parallel, thus you see sometimes the swap go first ahead of approval & vice-versa
It is an issue for all transactions that requires approval first and if the approval is not for maxUint256 ( every swap has to get approval first for example ). We can handle that by listening to mined TXs or we can create a multicall contract that execute calldata atomically. But that is my plan B.
How about increasing the gasPrice for the Approve call ?? that won't include it in the block before the swap??
Plus the failed swap Tx is not broadcasted to the blockchain . So is it the RPC executing staticCall first and since no enough allowance then it reverts ? @farhanW3
For now i set maxTxsToProcess to 1 , just to have it working but that breaks engine ability to batch process transactions.
Waiting for a solution. Thx @farhanW3 @arcoraven