Skip to content

fix: morpho withdraw action dynamically fetches token decimals instead of hardcoding 18#965

Open
furkankoykiran wants to merge 1 commit intocoinbase:mainfrom
furkankoykiran:fix/morpho-withdraw-decimals
Open

fix: morpho withdraw action dynamically fetches token decimals instead of hardcoding 18#965
furkankoykiran wants to merge 1 commit intocoinbase:mainfrom
furkankoykiran:fix/morpho-withdraw-decimals

Conversation

@furkankoykiran
Copy link

Summary

Fixes #946

MorphoActionProvider.withdraw() used Web3.to_wei(assets, "ether") to convert the assets input 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:

  • Expected atomic amount: 100 * 10^6 = 100_000_000
  • Actual (buggy) atomic amount: 100 * 10^18 = 100_000_000_000_000_000_000 (12 orders of magnitude too large)

Changes

schemas.py

  • Added token_address field to MorphoWithdrawSchema (matching MorphoDepositSchema)
  • Changed assets description from "atomic units" to "whole units" to match the actual behavior

morpho_action_provider.py

  • Replaced Web3.to_wei(assets, "ether") with dynamic decimal lookup via wallet_provider.read_contract(), matching the existing deposit() implementation
  • Updated withdraw action description to include token_address, examples, and important notes (consistent with deposit)

test_morpho_action_provider.py

  • Updated all withdraw tests to include token_address in args and mock read_contract
  • Added test_morpho_withdraw_non_18_decimal_token to verify correct behavior with 6-decimal tokens (USDC)

changelog.d/946.bugfix.md

  • Added towncrier changelog entry

Testing

All 13 Morpho tests pass:

13 passed, 9 warnings in 7.88s

…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)
@cb-heimdall
Copy link

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 1
Sum 2

@github-actions github-actions bot added documentation Improvements or additions to documentation action provider New action provider python labels Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action provider New action provider documentation Improvements or additions to documentation python

Development

Successfully merging this pull request may close these issues.

Morpho withdraw action hardcodes 18 decimals

2 participants