Skip to content

Conversation

@liobrasil
Copy link
Contributor

Summary

  • Add EVMAmountUtils for explicit rounding direction and use it in ERC4626 and Uniswap V2/V3 swap quotes.
  • Align Uniswap V3 max-in price impact math for token0 and clarify 600 bps comment.
  • Enforce sink max using ceil-rounded EVM balances to avoid precision leaks.

Issues solved

Commit 1: Add EVM amount rounding helpers and use in swap quotes

  • Problem: ERC20 amounts with >8 decimals were converted inconsistently to UFix64, so quotes could overstate outputs or understate required inputs.
  • Fix: Centralize rounding rules in EVMAmountUtils (floor for outputs, ceil for inputs) and update swap connectors; move rounding tests to a dedicated file and add the contract to flow.json and test deployments.
  • Result: Quotes are conservative and consistent across connectors.

Commit 2: Ceil EVM balances when enforcing sink max

  • Problem: minimumCapacity rounded EVM balances down, leaving phantom capacity when balances were not UFix64-quantized; deposits could exceed sinkMax after conversion.
  • Fix: Round balances up when computing capacity; add a regression test for non-quantum EVM balances; include EVMAmountUtils in connector config groups.
  • Result: Sink max enforcement is reliable even with non-quantized balances.

Testing

  • make test (flow test --cover --covercode="contracts" --coverprofile="coverage.lcov" ./cadence/tests/*_test.cdc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants