Skip to content

Conversation

@liobrasil
Copy link
Contributor

@liobrasil liobrasil commented Dec 25, 2025

Summary

  • Fixed a bug in ERC4626SwapConnectors.cdc where convertCadenceAmountToERC20Amount was using the vault address instead of the asset address when calculating uintMaxAllowed
  • This ensures the decimal conversion uses the correct token (the underlying asset) rather than the vault token

Test plan

  • Verify existing ERC4626 tests pass
  • Added regression test testQuoteInWithLargeAmountReturnsMaxWhenOverflow

Regression Test Explanation

The test donates assets directly to the vault (without minting shares) to create a 2:1 asset/share ratio. Then it requests a quote for UFix64.max shares:

  • With fix: Overflow check uses asset decimals (18), detects overflow, returns UFix64.max safely
  • With bug: Overflow check uses vault decimals (20), misses overflow, panics on conversion
uintRequired = 2 × UFix64.max × 10¹⁸ = 368B

Asset threshold (correct):  184B  →  368B > 184B  →  overflow detected ✓
Vault threshold (buggy):    18.4T →  368B < 18.4T →  overflow missed, panic!

🤖 Generated with Claude Code

…sion

Fix bug in ERC4626SourceConnector.quoteFor() where uintMaxAllowed was
being calculated using the vault's ERC4626 address instead of the
underlying asset's address. This caused incorrect decimal conversion
when the vault and underlying asset have different decimals.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@liobrasil liobrasil requested review from Kay-Zee and nialexsan January 6, 2026 00:20
@liobrasil liobrasil self-assigned this Jan 6, 2026
@liobrasil liobrasil requested a review from nvdtf January 6, 2026 00:21
Add regression test to verify quoteIn correctly uses asset decimals
instead of vault decimals when calculating max allowed amount.

- Add quote_in.cdc script to test quoteIn function directly
- Add testQuoteInUsesCorrectDecimalsForMaxAllowed test case

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@liobrasil liobrasil force-pushed the lionel/fix-erc4626-max-allowed-decimals branch from dac0d21 to bc1353c Compare January 6, 2026 16:13
@liobrasil liobrasil merged commit 1522d35 into main Jan 6, 2026
3 checks passed
@liobrasil liobrasil deleted the lionel/fix-erc4626-max-allowed-decimals branch January 6, 2026 16:18
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.

3 participants