Evm Token DecimalsSAFE
The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
Overview
The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
bd656e3e97c4OBSERVED · 2026-09-20What it tells the agent
The instruction file, verbatim from the audited commit — this is the text the model reads, and the surface the audit's instruction layer examines. Quoted here so you can judge it without cloning anything.
---
name: evm-token-decimals
description: EVMチェーン全体でサイレントな小数点不一致バグを防ぐ。ランタイムでの小数点照会、チェーン対応キャッシング、ブリッジドトークンの精度ドリフト、ボット・ダッシュボード・DeFiツール向けの安全な正規化をカバーします。
origin: ECC direct-port adaptation
version: "1.0.0"
---
# EVMトークン小数点
サイレントな小数点不一致は、エラーを発生させることなく残高やUSD値が桁違いになる最も簡単な方法のひとつです。
## 使用するタイミング
- Python、TypeScript、またはSolidityでERC-20残高を読み取る場合
- オンチェーン残高から法定通貨の値を計算する場合
- 複数のEVMチェーン間でトークン量を比較する場合
- ブリッジされた資産を扱う場合
- ポートフォリオトラッカー、ボット、またはアグリゲーターを構築する場合
## 仕組み
ステーブルコインが同じ小数点を使用していると仮定しないでください。ランタイムで`decimals()`を照会し、`(chain_id, token_address)`でキャッシュし、値の計算には小数点安全な数学を使用します。
## 使用例
### ランタイムで小数点を照会する
```python
from decimal import Decimal
from web3 import Web3
ERC20_ABI = [
{"name": "decimals", "type": "function", "inputs": [],
"outputs": [{"type": "uint8"}], "stateMutability": "view"},
{"name": "balanceOf", "type": "function",
"inputs": [{"name": "account", "type": "address"}],
"outputs": [{"type": "uint256"}], "stateMutability": "view"},
]
def get_token_balance(w3: Web3, token_address: str, wallet: str) -> Decimal:
contract = w3.eth.contract(
address=Web3.to_checksum_address(token_address),
abi=ERC20_ABI,
)
decimals = contract.functions.decimals().call()
raw = contract.functions.balanceOf(Web3.to_checksum_address(wallet)).call()
return Decimal(raw) / Decimal(10 ** decimals)
```
シンボルが他の場所で通常6小数点を持つからといって`1_000_000`をハードコードしないでください。
### チェーンとトークンでキャッシュする
```python
from functools import lru_cache
@lru_cache(maxsize=512)
def get_decimals(chain_id: int, token_address: str) -> int:
w3 = get_web3_for_chain(chain_id)
contract = w3.eth.contract(
address=Web3.to_checksum_address(token_address),
abi=ERC20_ABI,
)
return contract.functions.decimals().call()
```
### 特殊なトークンを防御的に処理する
```python
try:
decimals = contract.functions.decimals().call()
except Exception:
logging.warning(
"decimals() reverted on %s (chain %s), defaulting to 18",
token_address,
chain_id,
)
decimals = 18
```
フォールバックをログに記録して可視化しておく。古いまたは非標準トークンはまだ存在します。
### SolidityでWAD(18小数点)に正規化する
```solidity
interface IERC20Metadata {
function decimals() external view returns (uint8);
}
function normalizeToWad(address token, uint256 amount) internal view returns (uint256) {
uint8 d = IERC20Metadata(token).decimals();
if (d == 18) return amount;
if (d < 18) return amount * 10 ** (18 - d);
return amount / 10 ** (d - 18);
}
```
### ethersを使ったTypeScript
```typescript
import { Contract, formatUnits } from 'ethers';
const ERC20_ABI = [
'function decimals() view returns (uint8)',
'function balanceOf(address) view returns (uint256)',
];
async function getBalance(provider: any, tokenAddress: string, wallet: string): Promise<string> {
const token = new Contract(tokenAddress, ERC20_ABI, provider);
const [decimals, raw] = await Promise.all([
token.decimals(),
token.balanceOf(wallet),
]);
return formatUnits(raw, decimals);
}
```
### クイックなオンチェーン確認
```bash
cast call <token_address> "decimals()(uint8)" --rpc-url <rpc>
```
## ルール
- 常にランタイムで`decimals()`を照会する
- シンボルではなく、チェーンとトークンアドレスでキャッシュする
- floatではなく`Decimal`、`BigInt`、または同等の正確な数学を使用する
- ブリッジングやラッパーの変更後は小数点を再照会する
- 比較や価格計算の前に内部会計を一貫して正規化するTrust audit
SAFEgrade B · trust 89/100 Nothing in the source contradicts what it says it does. Grade A is reserved for packages that have also passed the behavioural sandbox.
| Layer | What it checks | Result |
|---|---|---|
| L0 | Provenance & inventory | PASS |
| L1 | Static analysis of the code | NA |
| L2 | Instruction surface (what it tells the agent) | PASS |
| L3 | Class-specific surface | PASS |
| L4 | Behavioural (sandbox) | SKIPPED |
What the source does
- Filesystem
- none-observed
- Network
- none-observed
- Shell
- none-observed
- Dependencies
- pinned
- Secrets in source
- none-found
Findings (0)
No findings outside the package's declared scope.
Gates applied: no_behavioural_pass.
bd656e3e97c4full audit observations/trust-audit/skill/affaan-m__evm-token-decimals.json · Report an issue / request a re-scanAudit history
Every audit this skill has had.
| Date | Source | Verdict | Grade | Score | Change |
|---|---|---|---|---|---|
| 2026-09-20 | bd656e3e97c4 | SAFE | B | 89 | first audit |
Questions
What does the Evm Token Decimals skill do?
The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
Is Evm Token Decimals safe to install?
The audit found nothing in the source that contradicts what it says it does, and graded it B (89/100). Grade A is held back for packages that have also passed a sandboxed behavioural run, which is why a clean skill reads B.
What can Evm Token Decimals access on my machine?
The audit observed no filesystem, network or shell use at all in its source.
How current is this page?
The grade is for one exact copy of the source (bd656e3e97c4), read on 2026-09-20. The repository is watched, and a new audit runs when it changes — this is the first audit.