# @0xmonaco/types 中文文档

规范地址：https://npmcn.com/package/%400xmonaco/types/

版本：1\.1\.9
npm 元数据更新时间：2026-11-06T20:40:41.628Z
中文译文更新时间：2026-11-06T00:40:06.217Z
软件包许可：未声明

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%400xmonaco/types
原文对照：https://npmcn.com/package/%400xmonaco/types/?lang=original
项目主页：https://docs.0xmonaco.com/sdk/typescript

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：1.9 MB，172 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：2 个
- peer 依赖：viem ^2\.45\.2
- 首次发布：2025-08-28T01:53:22.102Z
- 最新版本发布：2026-11-06T20:40:41.473Z
- 近 30 天下载量：8105（2026-10-04 至 2026-11-02，npm 官方下载统计）
- 已发布版本数：195（近 12 个月 174 个）

## 中文简介

摩纳哥议定书的核心类型定义。 这个软件包提供整个摩纳哥生态系统使用的TypeScript类型和接口,侧重于SDK配置,金库操作,交易操作,市场数据,以及合同管理.

## 安装

```sh
npm install @0xmonaco/types
```

也可以使用：`pnpm add @0xmonaco/types`、`yarn add @0xmonaco/types`、`bun add @0xmonaco/types`

## README

# @ 0xmonaco/ 类型

摩纳哥议定书的核心类型定义。 这个软件包提供整个摩纳哥生态系统使用的TypeScript类型和接口,侧重于SDK配置,金库操作,交易操作,市场数据,以及合同管理.

## 安装

```bash
npm install @0xmonaco/types
```

**说明:** 这个软件包一般是安装于 `@0xmonaco/core` 或者说 `@0xmonaco/react`,但您可以在您的 TypeScript 项目中直接安装类型定义.

## 类型

### SDK 类型

核心 SDK 配置和主接口类型 :

```typescript
import { MonacoSDK, SDKConfig } from "@0xmonaco/types";

// SDK configuration
interface SDKConfig {
  walletClient?: WalletClient; // Wallet client for signing operations
  network: Network; // Use "mainnet" (Sei mainnet, production API)
  seiRpcUrl: string; // RPC URL for Sei blockchain interactions
}

// Main SDK interface
interface MonacoSDK {
  applications: ApplicationsAPI; // Applications operations API
  auth: AuthAPI; // Auth operations API
  vault: VaultAPI; // Vault operations API
  trading: TradingAPI; // Trading operations API
  market: MarketAPI; // Market metadata API
  profile: ProfileAPI; // Profile operations API
  websocket: {
    orders: OrdersWebSocketClient; // WebSocket client for real-time order events
    ohlcv: OHLCVWebSocketClient; // WebSocket client for real-time OHLCV data
    orderbook: OrderbookWebSocketClient; // WebSocket client for real-time orderbook updates
  };
  walletClient: WalletClient; // Wallet client for blockchain operations
  publicClient: PublicClient; // Public client for read-only operations

  // Authentication
  login(clientId: string, options?: { connectWebSocket?: boolean }): Promise<AuthState>;
  logout(): Promise<void>;
  refreshAuth(): Promise<AuthState>;
  getAuthState(): AuthState | undefined;

  // Account management
  isAuthenticated(): boolean;
  isConnected(): boolean;
  getAccountAddress(): string;
  getNetwork(): Network;
  getChainId(): number;
  waitForTransaction(
    hash: string,
    confirmations?: number,
    timeout?: number
  ): Promise<TransactionReceipt>;
}
```

### 默认类型

包括存款、提款、结余管理在内的金库业务类型:

```typescript
import { VaultAPI, Balance, TransactionResult } from "@0xmonaco/types";

// Vault operations
interface VaultAPI extends BaseAPI {
  approve(
    assetId: string,
    amount: bigint,
    autoWait?: boolean
  ): Promise<TransactionResult>;
  deposit(
    assetId: string,
    amount: bigint,
    autoWait?: boolean
  ): Promise<TransactionResult>;
  withdraw(
    assetId: string,
    amount: bigint,
    autoWait?: boolean
  ): Promise<TransactionResult>;
  getAllowance(assetId: string): Promise<bigint>;
  needsApproval(assetId: string, amount: bigint): Promise<boolean>;
  getVaultAddress(): Promise<string>;
}

// Vault response types
interface Balance {
  token: string;
  amount: bigint;
  formatted: string;
  symbol: string;
  decimals: number;
}

interface TransactionResult {
  hash: string;
  status: "pending" | "confirmed" | "failed";
  nonce: bigint;
  receipt?: TransactionReceipt;
}
```

### 贸易类型

交易业务的类型,包括订单的放置和管理:

```typescript
import {
  TradingAPI,
  OrderSide,
  OrderType,
  CreateOrderResponse,
  CancelOrderResponse,
  ReplaceOrderResponse,
  GetPaginatedOrdersResponse,
  GetOrderResponse,
} from "@0xmonaco/types";

// Trading operations
interface TradingAPI extends BaseAPI {
  placeLimitOrder(
    tradingPairId: string,
    side: OrderSide,
    quantity: string,
    price: string,
    options?: {
      tradingMode?: TradingMode;
      useMasterBalance?: boolean;
      expirationDate?: string;
      timeInForce?: TimeInForce;
    }
  ): Promise<CreateOrderResponse>;

  placeMarketOrder(
    tradingPairId: string,
    side: OrderSide,
    quantity: string,
    options?: {
      tradingMode?: TradingMode;
      slippageTolerance?: number;
    }
  ): Promise<CreateOrderResponse>;

  cancelOrder(orderId: string): Promise<CancelOrderResponse>;

  replaceOrder(
    orderId: string,
    newOrder: {
      price?: string;
      quantity: string;
      useMasterBalance?: boolean;
    }
  ): Promise<ReplaceOrderResponse>;

  getPaginatedOrders(
    params?: GetPaginatedOrdersParams
  ): Promise<GetPaginatedOrdersResponse>;
  getOrder(orderId: string): Promise<GetOrderResponse>;
}

// Trading types
type OrderSide = "BUY" | "SELL";
type OrderType = "LIMIT" | "MARKET";
type OrderStatus = "SUBMITTED" | "PARTIALLY_FILLED" | "FILLED" | "SETTLED_ON_CHAIN" | "SETTLED" | "CANCELLED" | "REJECTED" | "EXPIRED";
type TradingMode = "SPOT" | "MARGIN";
type TimeInForce = "GTC" | "IOC" | "FOK"; // GTC: Good Till Cancel, IOC: Immediate or Cancel, FOK: Fill or Kill

// Trading response types
interface CreateOrderResponse {
  order_id: string;
  status: "SUCCESS" | "FAILED";
  match_result?: {
    remaining_quantity: string;
    status: string;
  };
}

interface CancelOrderResponse {
  order_id: string;
  status: "SUCCESS" | "FAILED";
}

interface ReplaceOrderResponse {
  order_id: string;
  status: "SUCCESS" | "FAILED";
}
```

### 市场类型

市场数据操作的类型,包括交易对元数据:

```typescript
import {
  MarketAPI,
  TradingPair,
  GetTradingPairsParams,
  GetTradingPairsResponse,
  GetTradingPairResponse,
  TradingMode,
} from "@0xmonaco/types";

// Market operations
interface MarketAPI extends BaseAPI {
  getPaginatedTradingPairs(
    params?: GetTradingPairsParams,
  ): Promise<GetTradingPairsResponse>;
  getTradingPair(tradingPairId: string): Promise<TradingPair>;
  getTradingPairBySymbol(
    symbol: string,
    marketType?: TradingMode,
  ): Promise<TradingPair | undefined>;
}

// Market data types
interface TradingPair {
  id: string;
  symbol: string;
  baseToken: string;
  quoteToken: string;
  baseAssetId: string;
  quoteAssetId: string;
  baseTokenContract: string;
  quoteTokenContract: string;
  baseDecimals: number;
  baseIconUrl: string;
  quoteDecimals: number;
  quoteIconUrl: string;
  marketType: TradingMode;
  category: string;
  isActive: boolean;
  minOrderSize: string;
  maxOrderSize: string;
  quantityStepSize: string;
  tickSize: string;
  minLeverage?: string | null;
  maxLeverage?: string | null;
}

// Market response types
interface GetTradingPairsResponse {
  tradingPairs: TradingPair[];
  page: number;
  pageSize: number;
  total: number;
  totalPages: number;
}

interface GetTradingPairResponse {
  tradingPair: TradingPair;
}
```

### 合同类型

合同地址、实例和与合同有关的业务的类型:

```typescript
import {
  ContractAddresses,
  ContractInstances,
  Token,
  UserBalance,
} from "@0xmonaco/types";

// Contract addresses
interface ContractAddresses {
  VAULT: string; // Vault contract address for managing user balances
}

// Contract instances
type ContractInstances = {
  vault: GetContractReturnType<typeof CONTRACT_ABIS.vault>;
};

// Contract-related types
interface Token {
  address: string;
  decimals: number;
  symbol: string;
  name: string;
}

interface UserBalance {
  token: Token;
  amount: bigint;
  formatted: string;
}
```

### 网络类型

网络配置类型 :

```typescript
import { Network, NetworkEndpoints } from "@0xmonaco/types";

const publicNetwork: Network = "mainnet";

interface NetworkEndpoints {
  rpcUrl: string;
  apiUrl: string;
}
```

用于公共融合,使用 `"mainnet"`。 。 。 .

## 类型参考

### SDK 类型

-   `MonacoSDK`: 所有API 模块的主要 SDK 接口
-   `SDKConfig`: 摩纳哥 SDK 配置选项
-   `Network`: SDK网络预设类型. 公共一体化应当使用 `"mainnet"`。 。 。 .
-   `AuthState`: 认证状态信息

### 默认类型

-   `VaultAPI`: 保险库操作接口(存款、提取和余额)
-   `Balance`: 调试平衡信息
-   `TransactionResult`: 区块链交易的结果

### 贸易类型

-   `TradingAPI`: 交易业务接口(订单、位置)
-   `OrderSide`: 排序侧式 ("BUY" Q"SEL")
-   `OrderType`:顺序类型 ("LIMIT""MARKET")
-   `TimeInForce`: 有效时间类型 ("GTC""IOC""FOK")
-   `CreateOrderResponse`: 订单放置回复
-   `CancelOrderResponse`: 取消订单的答复
-   `ReplaceOrderResponse`: 更换订单的答复

### 市场类型

-   `MarketAPI`: 市场数据操作接口
-   `TradingPair`: 交易配对元数据及所有市场信息
-   `GetTradingPairsResponse`: 交易配对列表的响应包装
-   `GetTradingPairResponse`单对交易的响应包装

### 合同类型

-   `ContractAddresses`: 合同地址测绘
-   `ContractInstances`: 类型合同实例
-   `Token`: 与元数据连接接口
-   `UserBalance`: 用户的代号余额信息

## 项目结构

类型包被组织成特定域模块:

```
src/
├── api/            # Base API types
│   └── index.ts   # Common API interfaces
├── applications/   # Applications types
├── auth/           # Authentication types
├── contracts/      # Contract types
│   ├── index.ts   # Contract interfaces
│   └── balances.ts # Balance-related types
├── market/         # Market data types
│   └── index.ts   # Market API interface and types
├── profile/        # Profile types
├── sdk/            # SDK types
│   ├── index.ts   # Main SDK interfaces and configuration
│   └── network.ts # Network-related types
├── trading/        # Trading types
│   ├── index.ts   # Trading API interface
│   ├── orders.ts  # Order-related types
│   └── responses.ts # Trading response types
├── vault/          # Vault types
│   ├── index.ts   # Vault API interface
│   └── responses.ts # Vault response types
├── websocket/      # WebSocket types
└── index.ts        # Package exports
```

## 依赖关系

此软件包使用 `viem` 与区块链有关的类型:

-   `Address`, (中文(简体) ), `Hex`, (中文(简体) ), `Account`, (中文(简体) ), `WalletClient`, (中文(简体) ), `PublicClient` 从 `viem`
-   `GetContractReturnType` 合同实例打字

## 最佳做法

-   保持类型重点和单一目的
-   使用反映域名的描述性名称
-   带有 JSDoc 注释的文档复合类型
-   使用 TypeScript 的严格模式
-   保持后向兼容性
-   遵守既定的命名公约
-   同一文件中的分组相关类型
-   杠杆 `viem` 类型,而不是定义自定义的

## 常见问题

### @0xmonaco/types 是什么？

摩纳哥议定书的核心类型定义。 这个软件包提供整个摩纳哥生态系统使用的TypeScript类型和接口,侧重于SDK配置,金库操作,交易操作,市场数据,以及合同管理\.

### 如何安装 @0xmonaco/types？

在项目目录运行 npm install @0xmonaco/types，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：viem（^2\.45\.2）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @0xmonaco/types 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @0xmonaco/types 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @0xmonaco/types 可以商用吗？

@0xmonaco/types 使用 未声明 许可。package\.json 没有声明许可证。没有许可证的代码默认保留全部权利，商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括，不构成法律意见，请以许可原文为准。

### @0xmonaco/types 的下载量有多少？

根据 npm 官方下载统计，@0xmonaco/types 在 2026/10/04 – 2026/11/02 这 30 天内被下载 8,105 次，日均约 270 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @0xmonaco/types 还在维护吗？

最新版本 1\.1\.9 发布于 2026/11/07（今天）；至今共发布 195 个版本，其中过去 12 个月发布了 174 个；首次发布于 2025/08/28。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

