这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@fengtality
Copy link
Contributor

@fengtality fengtality commented Jun 30, 2025

Summary

This PR fixes critical issues with Uniswap V3 router integration, specifically addressing BUY order failures and gas parameter optimization.

Changes

🐛 Bug Fixes

  • Fixed BUY order calculations: Properly handle EXACT_OUTPUT trades where the amount represents the desired output rather than input
  • Added balance checks: Validate user has sufficient token balance before executing swaps with clear error messages
  • Fixed gas handling: Set fixed gas limit of 300,000 for all Uniswap V3 swaps to prevent out-of-gas errors
  • Removed gas price minimum: Allow market-based gas prices instead of forcing 10 GWEI minimum

✨ Improvements

  • Dynamic network support: All Ethereum networks configured in ethereum.yml are now automatically supported
  • Removed hardcoded network lists: Networks are fetched dynamically from configuration
  • Simplified code: Removed unnecessary AlphaRouter workarounds and safety checks that are no longer needed

🧪 Testing

  • Added comprehensive test coverage for BUY and SELL operations
  • Added gas parameter validation tests
  • Updated mocks to reflect new gas limit of 300,000
  • All tests passing (8 tests for Uniswap router)

Technical Details

The main issue was that BUY orders were incorrectly calculating amounts. When a user wants to BUY 0.001 WETH with USDC, the system was treating this as an EXACT_INPUT trade instead of EXACT_OUTPUT, resulting in very small output amounts (1e-15 WETH).

Before

  • BUY 0.001 WETH → System tries to swap 0.001 USDC (wrong)
  • Gas limit from AlphaRouter: ~97,000 (too low)
  • Forced 10 GWEI minimum gas price

After

  • BUY 0.001 WETH → System correctly calculates ~2.5 USDC needed
  • Fixed gas limit: 300,000 (safe buffer)
  • Market-based gas price (can be 0.8 GWEI on mainnet)

Breaking Changes

None - All changes are backward compatible.

Related Issues

Fixes issues with Uniswap V3 BUY orders returning incorrect amounts and transactions failing due to insufficient gas.

fengtality and others added 3 commits June 30, 2025 16:38
- Fixed BUY order calculations to properly handle EXACT_OUTPUT trades
- Added balance checks before swap execution with clear error messages
- Set fixed gas limit of 300,000 for all Uniswap V3 swaps
- Removed minimum gas price constraint to use market rates
- Allow all Ethereum networks configured in ethereum.yml
- Dynamically fetch networks from configuration instead of hardcoded lists
- Added comprehensive tests for BUY/SELL operations and gas parameters

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

Co-Authored-By: Claude <noreply@anthropic.com>
- Removed EXACT_INPUT workaround for BUY orders as AlphaRouter now works correctly
- Removed BUY order sanity check as it's no longer needed
- Removed test README.md file

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

Co-Authored-By: Claude <noreply@anthropic.com>
- Removed calldata decoding and validation logic
- Removed amount validation checks for BUY orders
- Trust AlphaRouter's output without additional verification

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

Co-Authored-By: Claude <noreply@anthropic.com>
@fengtality fengtality requested a review from rapcmia June 30, 2025 23:45
@fengtality fengtality changed the title Core 2.7 fix Uniswap router buy fix Jun 30, 2025
@fengtality fengtality changed the title Uniswap router buy fix fix: fix Uniswap router BUY orders and improve gas handling Jun 30, 2025
@rapcmia rapcmia moved this to Under Review in Pull Request Board Jul 1, 2025
Copy link
Contributor

@rapcmia rapcmia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Test this PR with hummingbot dev branch using source ok
  • Run amm_price_example v2 script ok
  • Run fastify GET /connectors/uniswap/quote-swap ok
  • Compare price on uniswap mainnet ok

@rapcmia rapcmia changed the title fix: fix Uniswap router BUY orders and improve gas handling Fix / Uniswap router BUY orders and improve gas handling Jul 1, 2025
@rapcmia rapcmia merged commit adbeffb into development Jul 1, 2025
5 checks passed
@rapcmia rapcmia deleted the core-2.7-fix branch July 1, 2025 04:20
@rapcmia rapcmia moved this from Under Review to Development 2.6.2 in Pull Request Board Jul 1, 2025
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