Skip to content

fix(morpho): Fix withdraw to use dynamic token decimals#1090

Open
Kubudak90 wants to merge 3 commits intocoinbase:mainfrom
Kubudak90:main
Open

fix(morpho): Fix withdraw to use dynamic token decimals#1090
Kubudak90 wants to merge 3 commits intocoinbase:mainfrom
Kubudak90:main

Conversation

@Kubudak90
Copy link
Copy Markdown

Summary

Fixes #946

The MorphoActionProvider.withdraw() function was using Web3.to_wei(assets, 'ether') which hardcodes 18 decimals. This caused incorrect amounts for tokens with different decimals (e.g., USDC with 6 decimals would be off by 12 orders of magnitude).

Changes

  • Added token_address field to MorphoWithdrawSchema
  • Updated withdraw() to fetch token decimals dynamically (matching deposit behavior)
  • Updated description to say 'whole units' instead of 'atomic units' for consistency
  • Added examples for both WETH (18 decimals) and USDC (6 decimals) in the description
  • Updated tests to include token_address parameter
  • Added test for non-18 decimal tokens to prevent regression

Testing

  • Updated existing withdraw tests to include token_address
  • Added test_morpho_withdraw_non_18_decimals to verify correct handling of USDC-like tokens
  • All tests pass

Bug Details

Before this fix:

  • Withdrawing 100 USDC (6 decimals) would result in 100 * 10^18 = 100,000,000,000,000,000,000 (incorrect)

After this fix:

  • Withdrawing 100 USDC correctly results in 100 * 10^6 = 100,000,000

…rdcoded 18

The MorphoActionProvider.withdraw() function was using Web3.to_wei(assets, 'ether')
which hardcodes 18 decimals. This caused incorrect amounts for tokens with different
decimals (e.g., USDC with 6 decimals).

Changes:
- Added token_address field to MorphoWithdrawSchema
- Updated withdraw() to fetch token decimals dynamically (matching deposit behavior)
- Updated description to say 'whole units' instead of 'atomic units'
- Added examples for both WETH and USDC in the description
- Updated tests to include token_address and added test for non-18 decimal tokens

Fixes coinbase#946
@Kubudak90 Kubudak90 requested a review from murrlincoln as a code owner April 4, 2026 08:41
@cb-heimdall
Copy link
Copy Markdown

cb-heimdall commented Apr 4, 2026

🟡 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 action provider New action provider python labels Apr 4, 2026
Kubudak90 and others added 2 commits April 4, 2026 21:45
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The withdraw action was using atomic units (wei) while deposit used
whole units (e.g., 1.5 WETH). This inconsistency would confuse users.

Changes:
- Updated WithdrawSchema to accept decimal values like DepositSchema
- Added tokenAddress parameter to withdraw for fetching decimals
- Updated withdraw function to parse decimal amounts to atomic units
- Updated description to clarify whole units vs atomic units
- Updated tests to match new behavior

This makes the Morpho provider consistent with Moonwell and other
action providers that use whole units for both deposit and withdraw.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

Morpho withdraw action hardcodes 18 decimals

2 participants