-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Reset nonce if wallet is out of funds #791
Conversation
src/utils/error.ts
Outdated
@@ -16,11 +16,9 @@ const _parseMessage = (error: unknown): string | null => { | |||
|
|||
export const isNonceAlreadyUsedError = (error: unknown) => { | |||
const message = _parseMessage(error); | |||
const errorPhrases = ["nonce too low", "already known"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleanup, no logical change
if (value === 0n) { | ||
await deleteNoncesForBackendWallets([{ chainId, walletAddress: from }]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main change. If a transaction received an "insufficient funds" error from RPC and no value was provided, this wallet must be low on gas. Reset the nonce so the onchain nonce doesn't remain out of sync.
return { | ||
...queuedTransaction, | ||
status: "errored", | ||
errorMessage, | ||
} satisfies ErroredTransaction; | ||
} | ||
|
||
if (isNonceAlreadyUsedError(error) || isReplacementGasFeeTooLow(error)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just moving this below the "out of funds" block above. No logic changes.
PR-Codex overview
This PR focuses on simplifying error handling related to nonce usage and insufficient funds in the transaction process. It refines error checks and modifies the logic for handling insufficient funds, ensuring clearer responses and better nonce management.
Detailed summary
isNonceAlreadyUsedError
to use direct string checks instead of an array.isInsufficientFundsError
to check for a single phrase._sendTransaction
to improve handling of insufficient funds and nonce recycling.deleteNoncesForBackendWallets
call to reset nonce state when funds are insufficient.