fix(core): use on-chain balance diff for native ETH realized amounts#127
Open
quasystaty1 wants to merge 1 commit into
Open
fix(core): use on-chain balance diff for native ETH realized amounts#127quasystaty1 wants to merge 1 commit into
quasystaty1 wants to merge 1 commit into
Conversation
26586ee to
6976521
Compare
Native ETH legs don't emit ERC20 Transfer events, so the previous code fell back to the simulated amounts from strategy::Swap for both input and output. This caused realized profit to reflect expected values rather than actual on-chain outcomes. Now try_from_receipts queries the signer's ETH balance at block N-1 and N: - ETH in: amount_in = pre − post − gas_cost - ETH out: amount_out = post − pre + gas_cost The function is now async and takes a generic Provider, which calculate_realized_profit in Trade constructs from each chain's rpc_url. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
6976521 to
5a1f203
Compare
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.
Summary
Transferevents, sotry_from_receiptspreviously fell back to the simulatedstrategy::Swapamounts for any native ETH token, making realized profit reflect expected values rather than actual on-chain outcomesamount_in = pre_balance − post_balance − gas_costamount_out = post_balance − pre_balance + gas_costSwap::try_from_receiptsis nowasyncand takes a genericP: Provider;Trade::calculate_realized_profitconstructs lightweight read-only providers from each chain'srpc_urlWhat a reviewer should know
_transferOutcallsAddress.sendValuewith no log), so balance diff is the most practical on-chain approach withoutdebug_traceTransactionTest plan
realized_profit.slow_swap.amount_in/amount_outmatches the on-chain balance change🤖 Generated with Claude Code