Merged
Conversation
ethancjackson
approved these changes
Feb 24, 2025
gkoch78
approved these changes
Feb 24, 2025
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.
Bug Report: Token Base Unit Conversion Type Error
Issue
When executing token swaps, the approval transaction was failing with the error "Could not identify the intended function with name approve" due to incorrect type conversion in the token base unit calculation.
Root Cause
In alphaswarm/core/token.py, the TokenInfo.convert_to_base_units() method was returning a Decimal instead of an integer when converting token amounts to base units:
While the type hint BaseUnit = NewType("BaseUnit", int) suggested this should be an integer, the runtime wasn't enforcing the conversion. This caused Web3.py to receive a Decimal value when trying to call the ERC20 contract's approve function, which expects an integer value for the amount parameter.
Fix
Added explicit integer conversion in the base unit calculation:
Verification
Before: amount.base_units was Decimal('5000000000000000.000') # Encountered repeatedly in testing
After: amount.base_units is 5000000000000000 (integer) # Observed after applying fix.
Impact
This bug affected any operation requiring token approvals, particularly DEX swaps. The fix ensures proper type conversion when interacting with ERC20 contract functions that expect integer values for token amounts.
Discovery Context
The issue was discovered while debugging token swaps in the PriceMomentumCronAgent. The agent's correct usage of the swap tools helped surface this underlying type conversion issue in the core token handling code. (edited)