[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M72XCT46NJMD1F9S8TYC32GA":3,"skill-same:01M72XCT46NJMD1F9S8TYC32GA":49},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":29,"repositoryHtmlUrl":30,"repositoryHomepageUrl":6,"ownerHtmlUrl":31,"ownerBlogUrl":32,"ownerDescription":33,"updatedAt":34,"install":35,"resources":48},"01M72XCT46NJMD1F9S8TYC32GA","evm-token-decimals",null,"防止跨EVM链的静默小数不匹配错误。涵盖运行时小数查找、链感知缓存、桥接代币精度漂移以及面向机器人、仪表盘和DeFi工具的安全归一化。","SriramGandhiS\u002FSkills","SriramGandhiS","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F211849986?v=4","01M72WQCW12BYX71C6WN584TTA","Sriram S","01M72WQCWTJ2RD0ET1X31AF1RC",1,"MIT","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fdocs\u002Fzh-CN\u002Fskills\u002Fevm-token-decimals\u002FSKILL.md",[],[],"2026-11-10 22:39:42",false,"---\nname: evm-token-decimals\ndescription: 防止跨EVM链的静默小数不匹配错误。涵盖运行时小数查找、链感知缓存、桥接代币精度漂移以及面向机器人、仪表盘和DeFi工具的安全归一化。\norigin: ECC direct-port adaptation\nversion: \"1.0.0\"\n---\n\n# EVM 代币精度\n\n静默的精度不匹配是导致余额或美元价值出现数量级偏差且不抛出错误的最常见原因之一。\n\n## 适用场景\n\n* 在 Python、TypeScript 或 Solidity 中读取 ERC-20 余额\n* 根据链上余额计算法币价值\n* 跨多条 EVM 链比较代币数量\n* 处理跨链桥接资产\n* 构建投资组合追踪器、机器人或聚合器\n\n## 工作原理\n\n切勿假设稳定币在所有链上使用相同的精度。在运行时查询 `decimals()`，按 `(chain_id, token_address)` 进行缓存，并使用精度安全的数学运算进行价值计算。\n\n## 示例\n\n### 运行时查询精度\n\n```python\nfrom decimal import Decimal\nfrom web3 import Web3\n\nERC20_ABI = [\n    {\"name\": \"decimals\", \"type\": \"function\", \"inputs\": [],\n     \"outputs\": [{\"type\": \"uint8\"}], \"stateMutability\": \"view\"},\n    {\"name\": \"balanceOf\", \"type\": \"function\",\n     \"inputs\": [{\"name\": \"account\", \"type\": \"address\"}],\n     \"outputs\": [{\"type\": \"uint256\"}], \"stateMutability\": \"view\"},\n]\n\ndef get_token_balance(w3: Web3, token_address: str, wallet: str) -> Decimal:\n    contract = w3.eth.contract(\n        address=Web3.to_checksum_address(token_address),\n        abi=ERC20_ABI,\n    )\n    decimals = contract.functions.decimals().call()\n    raw = contract.functions.balanceOf(Web3.to_checksum_address(wallet)).call()\n    return Decimal(raw) \u002F Decimal(10 ** decimals)\n```\n\n不要硬编码 `1_000_000`，因为同名代币在其他链上通常有 6 位小数。\n\n### 按链和代币缓存\n\n```python\nfrom functools import lru_cache\n\n@lru_cache(maxsize=512)\ndef get_decimals(chain_id: int, token_address: str) -> int:\n    w3 = get_web3_for_chain(chain_id)\n    contract = w3.eth.contract(\n        address=Web3.to_checksum_address(token_address),\n        abi=ERC20_ABI,\n    )\n    return contract.functions.decimals().call()\n```\n\n### 防御性处理异常代币\n\n```python\ntry:\n    decimals = contract.functions.decimals().call()\nexcept Exception:\n    logging.warning(\n        \"decimals() reverted on %s (chain %s), defaulting to 18\",\n        token_address,\n        chain_id,\n    )\n    decimals = 18\n```\n\n记录回退值并保持可见。旧版或非标准代币仍然存在。\n\n### 在 Solidity 中归一化为 18 位 WAD 精度\n\n```solidity\ninterface IERC20Metadata {\n    function decimals() external view returns (uint8);\n}\n\nfunction normalizeToWad(address token, uint256 amount) internal view returns (uint256) {\n    uint8 d = IERC20Metadata(token).decimals();\n    if (d == 18) return amount;\n    if (d \u003C 18) return amount * 10 ** (18 - d);\n    return amount \u002F 10 ** (d - 18);\n}\n```\n\n### 使用 ethers 的 TypeScript 示例\n\n```typescript\nimport { Contract, formatUnits } from 'ethers';\n\nconst ERC20_ABI = [\n  'function decimals() view returns (uint8)',\n  'function balanceOf(address) view returns (uint256)',\n];\n\nasync function getBalance(provider: any, tokenAddress: string, wallet: string): Promise\u003Cstring> {\n  const token = new Contract(tokenAddress, ERC20_ABI, provider);\n  const [decimals, raw] = await Promise.all([\n    token.decimals(),\n    token.balanceOf(wallet),\n  ]);\n  return formatUnits(raw, decimals);\n}\n```\n\n### 快速链上检查\n\n```bash\ncast call \u003Ctoken_address> \"decimals()(uint8)\" --rpc-url \u003Crpc>\n```\n\n## 规则\n\n* 始终在运行时查询 `decimals()`\n* 按链加代币地址进行缓存，而非按代币符号\n* 使用 `Decimal`、`BigInt` 或等效的精确数学运算，避免使用浮点数\n* 在跨链桥接或代币包装变更后重新查询精度\n* 在比较或定价前，始终将内部记账归一化为一致精度\n","# EVM 代币精度\n\n静默的精度不匹配是导致余额或美元价值出现数量级偏差且不抛出错误的最常见原因之一。\n\n## 适用场景\n\n* 在 Python、TypeScript 或 Solidity 中读取 ERC-20 余额\n* 根据链上余额计算法币价值\n* 跨多条 EVM 链比较代币数量\n* 处理跨链桥接资产\n* 构建投资组合追踪器、机器人或聚合器\n\n## 工作原理\n\n切勿假设稳定币在所有链上使用相同的精度。在运行时查询 `decimals()`，按 `(chain_id, token_address)` 进行缓存，并使用精度安全的数学运算进行价值计算。\n\n## 示例\n\n### 运行时查询精度\n\n```python\nfrom decimal import Decimal\nfrom web3 import Web3\n\nERC20_ABI = [\n    {\"name\": \"decimals\", \"type\": \"function\", \"inputs\": [],\n     \"outputs\": [{\"type\": \"uint8\"}], \"stateMutability\": \"view\"},\n    {\"name\": \"balanceOf\", \"type\": \"function\",\n     \"inputs\": [{\"name\": \"account\", \"type\": \"address\"}],\n     \"outputs\": [{\"type\": \"uint256\"}], \"stateMutability\": \"view\"},\n]\n\ndef get_token_balance(w3: Web3, token_address: str, wallet: str) -> Decimal:\n    contract = w3.eth.contract(\n        address=Web3.to_checksum_address(token_address),\n        abi=ERC20_ABI,\n    )\n    decimals = contract.functions.decimals().call()\n    raw = contract.functions.balanceOf(Web3.to_checksum_address(wallet)).call()\n    return Decimal(raw) \u002F Decimal(10 ** decimals)\n```\n\n不要硬编码 `1_000_000`，因为同名代币在其他链上通常有 6 位小数。\n\n### 按链和代币缓存\n\n```python\nfrom functools import lru_cache\n\n@lru_cache(maxsize=512)\ndef get_decimals(chain_id: int, token_address: str) -> int:\n    w3 = get_web3_for_chain(chain_id)\n    contract = w3.eth.contract(\n        address=Web3.to_checksum_address(token_address),\n        abi=ERC20_ABI,\n    )\n    return contract.functions.decimals().call()\n```\n\n### 防御性处理异常代币\n\n```python\ntry:\n    decimals = contract.functions.decimals().call()\nexcept Exception:\n    logging.warning(\n        \"decimals() reverted on %s (chain %s), defaulting to 18\",\n        token_address,\n        chain_id,\n    )\n    decimals = 18\n```\n\n记录回退值并保持可见。旧版或非标准代币仍然存在。\n\n### 在 Solidity 中归一化为 18 位 WAD 精度\n\n```solidity\ninterface IERC20Metadata {\n    function decimals() external view returns (uint8);\n}\n\nfunction normalizeToWad(address token, uint256 amount) internal view returns (uint256) {\n    uint8 d = IERC20Metadata(token).decimals();\n    if (d == 18) return amount;\n    if (d \u003C 18) return amount * 10 ** (18 - d);\n    return amount \u002F 10 ** (d - 18);\n}\n```\n\n### 使用 ethers 的 TypeScript 示例\n\n```typescript\nimport { Contract, formatUnits } from 'ethers';\n\nconst ERC20_ABI = [\n  'function decimals() view returns (uint8)',\n  'function balanceOf(address) view returns (uint256)',\n];\n\nasync function getBalance(provider: any, tokenAddress: string, wallet: string): Promise\u003Cstring> {\n  const token = new Contract(tokenAddress, ERC20_ABI, provider);\n  const [decimals, raw] = await Promise.all([\n    token.decimals(),\n    token.balanceOf(wallet),\n  ]);\n  return formatUnits(raw, decimals);\n}\n```\n\n### 快速链上检查\n\n```bash\ncast call \u003Ctoken_address> \"decimals()(uint8)\" --rpc-url \u003Crpc>\n```\n\n## 规则\n\n* 始终在运行时查询 `decimals()`\n* 按链加代币地址进行缓存，而非按代币符号\n* 使用 `Decimal`、`BigInt` 或等效的精确数学运算，避免使用浮点数\n* 在跨链桥接或代币包装变更后重新查询精度\n* 在比较或定价前，始终将内部记账归一化为一致精度\n",{"name":5,"origin":24,"version":25,"description":7},"ECC direct-port adaptation","1.0.0","master","d6ca01da0f24a3b0e26e4a8b7b66cbd25d429f5d","docs\u002Fzh-CN\u002Fskills\u002Fevm-token-decimals",0,"https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills","https:\u002F\u002Fgithub.com\u002FSriramGandhiS","https:\u002F\u002Fsriram.website\u002F","Curious guy who keeps tinkering until something works","2026-05-20 16:21:34",{"source":8,"skillName":5,"commands":36,"prompt":46,"zipAvailable":47},[37,40,43],{"tool":38,"command":39},"npx","npx skills add SriramGandhiS\u002FSkills --skill evm-token-decimals",{"tool":41,"command":42},"bunx","bunx skills add SriramGandhiS\u002FSkills --skill evm-token-decimals",{"tool":44,"command":45},"pnpm","pnpm dlx skills add SriramGandhiS\u002FSkills --skill evm-token-decimals","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fdocs\u002Fzh-CN\u002Fskills\u002Fevm-token-decimals\u002FSKILL.md",true,[],[50,58,63,69,76,83],{"skillNo":51,"name":52,"nameZh":6,"description":53,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":54,"categories":55,"keywords":56,"publishedAt":57},"01M732609EPJWV13PVTX3GT4TM","webgpu-threejs-tsl","Comprehensive guide for developing WebGPU-enabled Three.js applications using TSL (Three.js Shading Language). Covers WebGPU renderer setup, TSL syntax and node materials, compute shaders, post-processing effects, and WGSL integration. Use this skill when working with Three.js WebGPU, TSL shaders, node materials, or GPU compute in Three.js.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fwebgpu-threejs-tsl\u002Fskills\u002Fwebgpu-threejs-tsl\u002FSKILL.md",[],[],"2026-11-11 15:11:14",{"skillNo":59,"name":52,"nameZh":6,"description":53,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":60,"categories":61,"keywords":62,"publishedAt":57},"01M7325XM47AGWB6K6C4VXKE6B","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fwebgpu-threejs-tsl\u002FSKILL.md",[],[],{"skillNo":64,"name":65,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":57},"01M7325WP6DES69JKC840VMFEP","verification-loop","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fverification-loop\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":57},"01M7325TFQF1DZTQ6J3WGQQ1VR","tdd-workflow","Use this skill when writing new features, fixing bugs, or refactoring code. Enforces test-driven development with 80%+ coverage including unit, integration, and E2E tests.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Ftdd-workflow\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":57},"01M7325RGV9AY9PK92D2V8KKPW","strategic-compact","Suggests manual context compaction at logical intervals to preserve context through task phases rather than arbitrary auto-compaction.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fstrategic-compact\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":57},"01M7325MZC28SE86E7NMCNEFS4","security-review","Use this skill when adding authentication, handling user input, working with secrets, creating API endpoints, or implementing payment\u002Fsensitive features. Provides comprehensive security checklist and patterns.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fsecurity-review\u002FSKILL.md",[],[]]