Add additional USDT approve transaction to account for must-reset-to-0 behavior#413
Merged
Add additional USDT approve transaction to account for must-reset-to-0 behavior#413
Conversation
swansontec
approved these changes
Oct 31, 2025
USDT requires an allowance to be zero before it can be nonzero. Most, like 99% of tokens, don't require this behavior. We would ideally check the allowance first before adding any approval transactions to the swap to avoid unnecessary transactions. Instead of adding a bunch of node lists and queries here maybe we could plumb something through the engine or tools to access those node lists.
76d7c22 to
ea8d818
Compare
| const approvalData = getEvmApprovalData({ | ||
| contractAddress: tokenContractAddress, | ||
| nativeAmount: amount | ||
| }) |
There was a problem hiding this comment.
Bug: Incorrect ERC-20 approve data leading to failures
The createApprovalTx function passes tokenContractAddress to getEvmApprovalData for the contractAddress parameter. The ERC-20 approve function expects the spender address (the recipientAddress) as its first argument. This generates incorrect approval transaction data, leading to failed approval transactions.
| NON_STANDARD_APPROVAL_TOKENS[ | ||
| request.fromWallet.currencyInfo.pluginId | ||
| ].includes(request.fromTokenId) | ||
| ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
noneDescription
noneNote
Adds automatic zero-then-amount ERC20 approvals (for tokens like USDT) and migrates swap flows to support multiple pre-transactions across DEX plugins.
createEvmApprovalEdgeTransactionsto build one or two ERC20 approval pre-txs, including a zero-allowance reset for non-standard tokens (e.g.,ethereumUSDT).getEvmApprovalDatato encodeapprovecalldata locally.preTxwithpreTxsthroughout and pipes them viapendingTxsinmakeSpend/makeTx.lifi,rango,thorchain/swapkit,thorchain/thorchainCommon,unizen: usecreateEvmApprovalEdgeTransactionsand returnpreTxs.spookySwap,tombSwap,velodrome: migrate topreTxshandling.Written by Cursor Bugbot for commit ea8d818. This will update automatically on new commits. Configure here.