Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

evm-decimal-validation

/evm-decimal-validation

Waliduje i konfiguruje dziesiętne miejsca tokenów we wdrożeniach EVM: tokeny ERC20, wdrożenia wielołańcuchowe i przeliczanie kwot, gdy decimals różnią się między łańcuchami.

Repozytorium
eyay-toolkits ↗
Licencja
MIT
Ostatnia zmiana repozytorium
23.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
2
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
2
Przestarzałość

Brak sygnałów. Repozytorium zmienione 23.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Waliduje i konfiguruje dziesiętne miejsca tokenów we wdrożeniach EVM: tokeny ERC20, wdrożenia wielołańcuchowe i przeliczanie kwot, gdy decimals różnią się między łańcuchami.

Oryginalny opis (EN)

Validate and configure token decimals for EVM-compatible blockchain deployments. Use when working with ERC20 tokens, multi-chain deployments, token amount conversions, or when decimals might vary across chains.

Jak działa

  1. Quick Start
  2. Token Decimal Standards
  3. Validation Checklist
  4. Common Pitfalls
  5. Test Patterns
  6. Integration Points
  7. Token Decimals by Chain
  8. Sources
Sekcje z nagłówków SKILL.md, w oryginale · 187 linii, 650 słów
Podgląd SKILL.md
---
name: evm-decimal-validation
description: Validate and configure token decimals for EVM-compatible blockchain deployments. Use when working with ERC20 tokens, multi-chain deployments, token amount conversions, or when decimals might vary across chains.
---

# EVM Token Decimal Validation

Ensure token decimals are correctly configured for each blockchain deployment to prevent amount calculation errors.

## Quick Start

1. **Check current configuration** - Review network configs for decimal fields
2. **Validate against contracts** - Query on-chain decimals() for each deployment
3. **Update configuration** - Add per-chain decimals to network config
4. **Test conversions** - Verify FromWei/ToWei work correctly

## Token Decimal Standards

### Common Decimal Values

| Decimals | Use Case | Examples |
|----------|----------|----------|
| 18 | Standard ERC20 (most tokens) | WETH, DAI, USDC (on some chains) |
| 6 | Stablecoins | USDC, USDT (on Ethereum) |
| 8 | Bitcoin-wrapped | WBTC |
| 2 | Fiat-backed (cents) | IDRX, some CBDCs |
| 0 | Raw integers | Some wrapped tokens |

### Chain-Specific Variations

The same token contract deployed on different chains may use different decimals:

```
Token A on Ethereum:    18 decimals
Token A on Polygon:     0 decimals (different deployment)
Token A on BNB Chain:   0 decimals (different deployment)
```

## Validation Checklist

### Step 1: Audit Current Configuration

```bash
# Find hardcoded decimals
grep -rn "18)" --include="*.go" | grep -i "decimal\|wei\|amount"

# Check for decimals field in network config
grep -rn "Decimals" blockchain/networks.go
```

### Step 2: Query On-Chain Values

```go
// Get decimals from contract
decimals, err := contract.Decimals(nil)
if err != nil {
    return fmt.Errorf("failed to get decimals: %w", err)
}
```

### Step 3: Update Network Config

```go
type NetworkConfig struct {
    // ... existing fields ...
    Decimals uint8 // Token decimals for this deployment
}

// In SupportedNetworks
BaseMainnet: {
    // ...
    Decimals: 2, // From on-chain query
},
```

### Step 4: Add Helper Function

```go
// GetDecimals returns token decimals for a chain ID.
// Always provide a sensible fallback.
func GetDecimals(chainID uint64) uint8 {
    config, _, exists := GetNetworkConfigByChainID(chainID)
    if !exists {
        return 2 // Fallback to majority value
    }
    return config.Decimals
}
```

### Step 5: Replace Hardcoded Values

```go
// Before
return FromWei(balance, 18), nil

// After
return FromWei(balance, int32(GetDecimals(chainID))), nil
```

## Common Pitfalls

### Pitfall 1: Assuming All Chains Use Same Decimals

```go
// WRONG: Hardcoded decimals
amount := FromWei(balance, 18)

// CORRECT: Per-chain decimals
amount := FromWei(balance, int32(GetDecimals(chainID)))
```

### Pitfall 2: Missing Fallback Value

```go
// WRONG: No fallback, potential nil pointer
return config.Decimals, nil

// CORRECT: Sensible fallback
if !exists {
    return 2 // Majority value or most common
}
return config.Decimals
```

### Pitfall 3: Not Validating Config Against Chain

```go
// Add startup validation
func ValidateDecimals() error {
    for name, config := range SupportedNetworks {
        onChainDecimals, err := queryOnChain(config)
        if err != nil {
            continue // Skip unreachable chains
        }
        if config.Decimals != onChainDecimals {
            return fmt.Errorf("%s: config=%d, on-chain=%d",
                name, config.Decimals, onChainDecimals)
        }
    }
    return nil
}
```

## Test Patterns

```go
func TestGetDecimals(t *testing.T) {
    testCases := map[uint64]uint8{
        8453: 2,  // Base
        137:  0,  // Polygon
        56:   0,  // BSC
    }

    for chainID, expected := range testCases {
        got := GetDecimals(chainID)
        if got != expected {
            t.Errorf("Chain %d: expected %d, got %d", chainID, expected, got)
        }
    }
}

func TestGetDecimalsFallback(t *testing.T) {
    got := GetDecimals(999999) // Unknown chain
    if got != 2 {
        t.Errorf("Unknown chain should return fallback, got %d", got)
    }
}
```

## Integration Points

When adding decimal validation, check these areas:

| Area | What to Check |
|------|---------------|
| Balance queries | `BalanceOf()` uses per-chain decimals |
| Total supply | `TotalSupply()` uses per-chain decimals |
| Transfers | `ParseTokenAmount()` receives correct decimals |
| Bridge operations | Both source and dest chains considered |
| Fee calculations | Platform fees use correct decimals |
| API responses | Human-readable amounts properly converted |

## Token Decimals by Chain

See `decimals-by-chain.md` for a reference guide of common tokens and their decimals across different EVM chains.

## Sources

- ERC20 Token Standard: https://eips.ethereum.org/EIPS/eip-20
- OpenZeppelin ERC20: https://docs.openzeppelin.com/contracts/4.x/erc20
Pliki w paczce (2)
  • SKILL.md 5 KB
  • decimals-by-chain.md 2 KB

Wersje

W bazie nie ma innych skilli o nazwie evm-decimal-validation.

Migawka bazy z 13.11.2026 · wersja paczki e0397320860f (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 1 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100evm-token-decimals
    Zapobiega cichym błędom niezgodności decimals między łańcuchami EVM: odczyt w runtime, cache zależny od łańcucha, dryf precyzji tokenów mostkowanych i bezpieczna normalizacja dla botów i narzędzi DeFi.
  • 100evm-token-decimals
    Zapobiega cichym błędom miejsc dziesiętnych tokenów EVM w różnych sieciach, w botach, pulpitach i narzędziach DeFi.
  • 90token-minter
    Generuje, buduje i wdraża własne tokeny ERC20 w sieciach EVM, z parametrami takimi jak nazwa, symbol, miejsca dziesiętne i podaż początkowa, także w sieci testowej Sepolia przez Foundry.
  • 100bridge-tokens
    Buduje mostkowanie tokenów między łańcuchami w przeglądarce lub na serwerze przez Circle App Kit albo Bridge Kit: USDC przez CCTP na EVM i Solanie oraz tokeny CCTPx przez wywołanie kit.bridge().
  • 100dotnet11-floating-point
    Pomaga przy przejściu na .NET 11, gdy konwersje double lub float na decimal i zaokrąglanie dają błędne wartości, z analizatorem DecimalConversion.
  • 95debridge
    Dostarcza SDK deBridge do budowy mostów międzyłańcuchowych, przesyłania wiadomości i transferów tokenów między Solaną a łańcuchami EVM.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.