Conversation
BowTiedDevil
added a commit
that referenced
this pull request
Jun 20, 2026
V3-V4-V3 reverted on mainnet with CurrencyNotSettled() (permutation row #17, ~50% simulatable). The inner V4 swap used a static solver amount (V4_SWAP_COMPACT(out_a)) and the V4 output was taken with a static V4_TAKE_COMPACT(out_b). V3's optimistic transfer delivers V3a's forward_a to the PoolManager before V3a's callback runs the V4 unlock, and the V4 swap computes its actual forward_b on-chain — so whenever the on-chain amounts differ from the solver's out_a/out_b (common under real price impact), a residual PM delta survived at unlock-end, causing CurrencyNotSettled. Switch to V4_SWAP_DYNAMIC (consume the actual settled forward_a delta via PM exttload) + V4_TAKE_DELTA (take the full actual forward_b output) + V4_SETTLE_ALL (sweep dust). The nesting is unchanged — V3's optimistic transfer already delivers forward_a before the callback, so the bug was the static amounts, not the nesting. Mirrors the V2-V2-V4 fix (commit 2e50553). Validation: structural regression test in tests/arbitrage/test_v3_v4_v3_encoder.py pins the new ordering. On-chain Ape+Foundry regression (executor repo) forces V4 over-production and proves the OLD stream reverts with CurrencyNotSettled while the NEW stream succeeds with profit, confirming the root cause and the fix. Plan: B2TSXX
BowTiedDevil
added a commit
that referenced
this pull request
Jun 21, 2026
V3-V4-V3 reverted on mainnet with CurrencyNotSettled() (row #17, ~50% simulatable). The inner V4 swap used a static solver amount (V4_SWAP_COMPACT(out_a)) and the V4 output was taken with a static V4_TAKE_COMPACT(out_b). V3's optimistic transfer delivers V3a's forward_a to the PoolManager before V3a's callback runs the V4 unlock, and the V4 swap computes its actual forward_b on-chain, so whenever on-chain amounts differ from the solver's out_a/out_b (common under price impact) a residual PM delta survives at unlock-end, causing CurrencyNotSettled. Switch to V4_SWAP_DYNAMIC (consume the actual settled forward_a delta via PM exttload) plus V4_TAKE_DELTA (take the full actual forward_b output) plus V4_SETTLE_ALL (sweep dust). Nesting is unchanged: V3's optimistic transfer already delivers forward_a before the callback, so the bug was the static amounts, not the nesting. Mirrors V2-V2-V4 (commit 2e50553). A structural regression test pins the new ordering, and an on-chain Ape+Foundry regression forces V4 over-production to prove the OLD stream reverts with CurrencyNotSettled while the NEW stream succeeds with profit. Plan: B2TSXX
BowTiedDevil
added a commit
that referenced
this pull request
Jul 21, 2026
V3-V4-V3 reverted on mainnet with CurrencyNotSettled() (row #17, ~50% simulatable). The inner V4 swap used a static solver amount (V4_SWAP_COMPACT(out_a)) and the V4 output was taken with a static V4_TAKE_COMPACT(out_b). V3's optimistic transfer delivers V3a's forward_a to the PoolManager before V3a's callback runs the V4 unlock, and the V4 swap computes its actual forward_b on-chain, so whenever on-chain amounts differ from the solver's out_a/out_b (common under price impact) a residual PM delta survives at unlock-end, causing CurrencyNotSettled. Switch to V4_SWAP_DYNAMIC (consume the actual settled forward_a delta via PM exttload) plus V4_TAKE_DELTA (take the full actual forward_b output) plus V4_SETTLE_ALL (sweep dust). Nesting is unchanged: V3's optimistic transfer already delivers forward_a before the callback, so the bug was the static amounts, not the nesting. Mirrors V2-V2-V4 (commit 2e50553). A structural regression test pins the new ordering, and an on-chain Ape+Foundry regression forces V4 over-production to prove the OLD stream reverts with CurrencyNotSettled while the NEW stream succeeds with profit. Plan: B2TSXX
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.
According to this fix, 84dd8d4
There are supposing the:
calculate,calculate_arbitrage,calculate_with_poolmust have theself._pre_calculation_check(override_state)_calculatemustn't have the_pre_calculation_check