Skip to content

📘 Book T7: The Types Reference (类型系统参考)

源码: src/types/

核心类型定义,为整个应用提供类型安全的基础。

📖 目录

文档说明
00-Index类型索引与设计原则
01-Amount精确金额计算 (Big.js)
02-Asset资产/代币信息类型
03-Staking跨链质押类型

🎯 核心要点

Amount - 精确金额

typescript
import { Amount } from '@/types/amount'

const balance = Amount.fromRaw('1000000000000000000', 18, 'ETH')
balance.toFormatted()  // "1"
balance.toRawString()  // "1000000000000000000"

Asset - 资产信息

typescript
import { AssetInfo } from '@/types/asset'

const asset: AssetInfo = {
  assetType: 'ETH',
  amount: Amount.fromFormatted('1.5', 18),
  decimals: 18,
  priceUsd: 2500,
}

Staking - 跨链质押

typescript
import { MintRequest, BurnRequest } from '@/types/staking'

// Mint: 外部链 → 内部链
// Burn: 内部链 → 外部链

设计原则

原则说明
不可变所有操作返回新实例
类型安全Zod Schema 运行时验证
自文档化方法名清晰表达意图
边界安全精度检查、溢出保护

相关文档

Released under the MIT License.