feat: Derive fiat order sourceAmount from on-chain tx data#8694
feat: Derive fiat order sourceAmount from on-chain tx data#8694
sourceAmount from on-chain tx data#8694Conversation
…toAmount fallback
sourceAmount from on-chain tx data
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0a7e13c. Configure here.
|
|
||
| const decoded = erc20Interface.decodeFunctionData('transfer', tx.data); | ||
|
|
||
| return positiveOrUndefined(decoded._value.toString()); |
There was a problem hiding this comment.
ERC-20 path ignores tokenAddress, no tx.to verification
Medium Severity
getTransferredAmountFromTxHash accepts a tokenAddress parameter but, for ERC-20 tokens, never verifies that tx.to matches this address. It only uses tokenAddress to pick the native-vs-ERC-20 path. If the order.txHash points to a transfer call on a different ERC-20 contract, the function silently decodes and returns that unrelated amount. Because this is described as a generic reusable utility, callers may reasonably assume tokenAddress scopes the result to the intended token.
Reviewed by Cursor Bugbot for commit 0a7e13c. Configure here.


Explanation
Currently, the fiat submit flow derives
sourceAmountRawfromorder.cryptoAmount- a human-readable value reported by the on-ramp provider. This value may not precisely reflect what was actually received on-chain.This PR reads the actual transferred amount from the completed on-chain transaction (
order.txHash) instead. For native tokens, the amount is taken fromtx.value. For ERC-20 tokens, the amount is decoded from thetransfer(address,uint256)call data. If the on-chain read fails or the transaction hash is missing, the existingorder.cryptoAmountderivation is used as a fallback.The implementation introduces:
getTransferredAmountFromTxHash- a generic utility inutils/transaction-receipt.tsthat reads transferred amounts from any on-chain transaction (native or ERC-20). Takes explicitchainIdandtokenAddressparams for reusability.resolveSourceAmountRaw- a fiat-strategy-specific function instrategy/fiat/utils.tsthat orchestrates the on-chain read withorder.cryptoAmountfallback.getRawSourceAmountFromOrderCryptoAmount- the existing decimal-shift conversion, moved fromfiat-submit.tstostrategy/fiat/utils.tsand renamed for clarity.References
FiatStrategysubmit flow with order polling and relay execution #8347Checklist
Note
Medium Risk
Changes how fiat submission computes
sourceAmountRawby reading on-chain transaction data via RPC, which can impact relay quoting/submission correctness and adds new failure modes around provider reads and ERC-20 calldata decoding.Overview
Fiat submit now derives the relay
sourceAmountRawfrom the completed order’s on-chain transaction (order.txHash) when available, falling back to decimal-shiftingorder.cryptoAmountif the read fails or yields no amount.This introduces a reusable
getTransferredAmountFromTxHashutility to read nativetx.valueor decode ERC-20transfer(address,uint256)calldata, refactors the prior cryptoAmount conversion intogetRawSourceAmountFromOrderCryptoAmount, and updates/expands unit tests plus the package changelog accordingly.Reviewed by Cursor Bugbot for commit 0a7e13c. Bugbot is set up for automated code reviews on this repo. Configure here.