fix: morpho withdraw action dynamically fetches token decimals instead of hardcoding 18#965
Open
furkankoykiran wants to merge 1 commit intocoinbase:mainfrom
Open
Conversation
…d of hardcoding 18 Fixes coinbase#946 - Added token_address to MorphoWithdrawSchema - Replaced Web3.to_wei(assets, 'ether') with dynamic decimal lookup via read_contract - Updated withdraw description to say 'whole units' matching deposit - Added test for non-18-decimal tokens (e.g. USDC with 6 decimals)
🟡 Heimdall Review Status
|
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.
Summary
Fixes #946
MorphoActionProvider.withdraw()usedWeb3.to_wei(assets, "ether")to convert theassetsinput to atomic units, which hardcodes 18 decimals regardless of the actual token's decimals. This produces incorrect amounts for any token that isn't 18 decimals (e.g., USDC with 6 decimals).Example: Withdrawing 100 USDC (6 decimals) from a Morpho vault:
100 * 10^6 = 100_000_000100 * 10^18 = 100_000_000_000_000_000_000(12 orders of magnitude too large)Changes
schemas.pytoken_addressfield toMorphoWithdrawSchema(matchingMorphoDepositSchema)assetsdescription from "atomic units" to "whole units" to match the actual behaviormorpho_action_provider.pyWeb3.to_wei(assets, "ether")with dynamic decimal lookup viawallet_provider.read_contract(), matching the existingdeposit()implementationwithdrawaction description to includetoken_address, examples, and important notes (consistent withdeposit)test_morpho_action_provider.pytoken_addressin args and mockread_contracttest_morpho_withdraw_non_18_decimal_tokento verify correct behavior with 6-decimal tokens (USDC)changelog.d/946.bugfix.mdTesting
All 13 Morpho tests pass: