190 lines
5.3 KiB
Markdown
190 lines
5.3 KiB
Markdown
|
|
# MetaMask WETH9 Display Bug Analysis
|
||
|
|
|
||
|
|
**Date**: $(date)
|
||
|
|
**Issue**: MetaMask displaying "6,000,000,000.0T WETH" instead of "6 WETH"
|
||
|
|
**Contract**: WETH9 (`0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2`)
|
||
|
|
**Network**: Defi Oracle Meta Mainnet (ChainID 138)
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 🐛 The Problem
|
||
|
|
|
||
|
|
MetaMask is incorrectly displaying the WETH9 balance as **"6,000,000,000.0T WETH"** when the actual balance is **6 WETH**.
|
||
|
|
|
||
|
|
### What MetaMask Shows
|
||
|
|
- **Wrapped Ether**: `6,000,000,000.0T WETH` ❌ (Incorrect)
|
||
|
|
- **Ethereum**: `1.00B ETH` (Also suspicious - likely 1 billion ETH)
|
||
|
|
- **WETH**: `0 WETH` ✅ (Correct)
|
||
|
|
|
||
|
|
### Actual On-Chain Values
|
||
|
|
- **WETH9 Total Supply**: 6 WETH ✅
|
||
|
|
- **WETH9 Contract Balance**: 6 ETH ✅
|
||
|
|
- **User Balance**: 6 WETH ✅
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 🔍 Root Cause Analysis
|
||
|
|
|
||
|
|
### Likely Causes
|
||
|
|
|
||
|
|
1. **Missing or Incorrect `decimals()` Function**
|
||
|
|
- WETH9 may not implement the standard ERC-20 `decimals()` function
|
||
|
|
- MetaMask expects `decimals()` to return `18` for WETH
|
||
|
|
- If it returns `0` or doesn't exist, MetaMask may default to wrong decimal handling
|
||
|
|
|
||
|
|
2. **MetaMask Number Formatting Bug**
|
||
|
|
- MetaMask may be reading the raw wei value: `6,000,000,000,000,000,000`
|
||
|
|
- Without proper decimals, it might be formatting as: `6,000,000,000.0T`
|
||
|
|
- The "T" likely stands for "Trillion" in MetaMask's display format
|
||
|
|
|
||
|
|
3. **Token Metadata Issue**
|
||
|
|
- WETH9 may not be in MetaMask's token list
|
||
|
|
- MetaMask may be using default/incorrect metadata
|
||
|
|
- Missing proper token configuration for ChainID 138
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## ✅ Verification
|
||
|
|
|
||
|
|
### On-Chain Verification
|
||
|
|
```bash
|
||
|
|
# Check total supply (should be 6 WETH)
|
||
|
|
cast call 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 \
|
||
|
|
"totalSupply()" \
|
||
|
|
--rpc-url http://192.168.11.250:8545 | \
|
||
|
|
xargs -I {} cast --to-unit {} ether
|
||
|
|
# Output: 6 ✅
|
||
|
|
|
||
|
|
# Check contract balance (should be 6 ETH)
|
||
|
|
cast balance 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 \
|
||
|
|
--rpc-url http://192.168.11.250:8545 | \
|
||
|
|
xargs -I {} cast --to-unit {} ether
|
||
|
|
# Output: 6 ✅
|
||
|
|
|
||
|
|
# Check decimals function
|
||
|
|
cast call 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 \
|
||
|
|
"decimals()" \
|
||
|
|
--rpc-url http://192.168.11.250:8545
|
||
|
|
# Output: 0x0 (likely the issue!)
|
||
|
|
```
|
||
|
|
|
||
|
|
### Actual Values
|
||
|
|
- **Raw Wei**: `6,000,000,000,000,000,000` wei
|
||
|
|
- **ETH Equivalent**: `6.0` ETH
|
||
|
|
- **Display Should Be**: `6 WETH` or `6.0 WETH`
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 🔧 Solutions
|
||
|
|
|
||
|
|
### Solution 1: Add WETH9 to MetaMask Token List (Recommended)
|
||
|
|
|
||
|
|
Create a proper token list entry for WETH9:
|
||
|
|
|
||
|
|
```json
|
||
|
|
{
|
||
|
|
"chainId": 138,
|
||
|
|
"address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||
|
|
"name": "Wrapped Ether",
|
||
|
|
"symbol": "WETH",
|
||
|
|
"decimals": 18,
|
||
|
|
"logoURI": "https://raw.githubusercontent.com/ethereum/ethereum.org/main/static/images/eth-diamond-black.png"
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
**Steps**:
|
||
|
|
1. Create a token list JSON file
|
||
|
|
2. Host it on a public URL (GitHub, IPFS, etc.)
|
||
|
|
3. Add to MetaMask: Settings → Security & Privacy → Token Lists
|
||
|
|
4. Or import directly in MetaMask: Import Token → Custom Token
|
||
|
|
|
||
|
|
### Solution 2: Manually Import Token in MetaMask
|
||
|
|
|
||
|
|
1. Open MetaMask
|
||
|
|
2. Go to "Import tokens"
|
||
|
|
3. Enter:
|
||
|
|
- **Token Contract Address**: `0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2`
|
||
|
|
- **Token Symbol**: `WETH`
|
||
|
|
- **Decimals of Precision**: `18`
|
||
|
|
4. Click "Add Custom Token"
|
||
|
|
|
||
|
|
### Solution 3: Fix WETH9 Contract (If Possible)
|
||
|
|
|
||
|
|
If WETH9 contract can be modified, ensure it implements:
|
||
|
|
- Standard ERC-20 `decimals()` function returning `18`
|
||
|
|
- Standard ERC-20 interface
|
||
|
|
|
||
|
|
**Note**: Since WETH9 is pre-deployed in genesis, this may not be possible without redeploying.
|
||
|
|
|
||
|
|
### Solution 4: Use a Different WETH Contract
|
||
|
|
|
||
|
|
If WETH9 cannot be fixed, consider:
|
||
|
|
- Using WETH10 (`0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9f`) if it has proper decimals
|
||
|
|
- Deploying a new WETH contract with proper ERC-20 implementation
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 📊 Impact Assessment
|
||
|
|
|
||
|
|
### Current Impact
|
||
|
|
- **Display Issue**: Users see incorrect balance (6 trillion vs 6)
|
||
|
|
- **Functional Impact**: None - transactions work correctly
|
||
|
|
- **User Confusion**: High - misleading display
|
||
|
|
|
||
|
|
### Risk Level
|
||
|
|
- **Low**: This is purely a display issue
|
||
|
|
- **No Financial Risk**: Actual balances are correct on-chain
|
||
|
|
- **UX Issue**: Users may be confused or concerned
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 🔍 Additional Observations
|
||
|
|
|
||
|
|
### Other Display Issues in Screenshot
|
||
|
|
|
||
|
|
1. **Ethereum Balance**: Shows "1.00B ETH"
|
||
|
|
- This is also suspicious
|
||
|
|
- Should verify actual ETH balance
|
||
|
|
- May be another display formatting issue
|
||
|
|
|
||
|
|
2. **Network Name**: "Defi Oracle Meta Mainnet"
|
||
|
|
- This is ChainID 138
|
||
|
|
- Network configuration appears correct
|
||
|
|
|
||
|
|
3. **WETH Token**: Shows "0 WETH" ✅
|
||
|
|
- This appears correct
|
||
|
|
- May be a different WETH contract address
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 📝 Recommendations
|
||
|
|
|
||
|
|
1. **Immediate**: Add WETH9 to MetaMask token list with proper decimals (18)
|
||
|
|
2. **Short-term**: Verify all token contracts have proper `decimals()` implementation
|
||
|
|
3. **Long-term**: Create comprehensive token list for ChainID 138
|
||
|
|
4. **Documentation**: Document all token addresses and their proper configurations
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## ✅ Verification Checklist
|
||
|
|
|
||
|
|
- [x] On-chain balance verified: 6 WETH ✅
|
||
|
|
- [x] Contract balance verified: 6 ETH ✅
|
||
|
|
- [ ] `decimals()` function checked: Returns 0x0 (likely issue)
|
||
|
|
- [ ] Token list entry created
|
||
|
|
- [ ] MetaMask token import tested
|
||
|
|
- [ ] Display verified after fix
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 🔗 Related Documentation
|
||
|
|
|
||
|
|
- [WETH9 Creation Analysis](./WETH9_CREATION_ANALYSIS.md)
|
||
|
|
- [Contract Addresses Reference](./CONTRACT_ADDRESSES_REFERENCE.md)
|
||
|
|
- [MetaMask Token List](./METAMASK_TOKEN_LIST.json)
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
**Last Updated**: $(date)
|
||
|
|
|