# @exponent-labs/market-three-math 中文文档

规范地址：https://npmcn.com/package/%40exponent-labs/market-three-math/

版本：0\.9\.33
npm 元数据更新时间：2026-11-05T09:22:49.579Z
中文译文更新时间：2026-11-14T05:35:29.037Z
软件包许可：AGPL-3\.0

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

原始 npm 页面：https://www.npmjs.com/package/%40exponent-labs/market-three-math
原文对照：https://npmcn.com/package/%40exponent-labs/market-three-math/?lang=original

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

- 包体积（解压后）：588 kB，71 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：2 个
- 首次发布：2026-01-22T13:22:17.628Z
- 最新版本发布：2026-11-05T09:22:49.384Z
- 近 30 天下载量：13967（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：35（近 12 个月 35 个）

## 中文简介

精准CLMM(集中流动性市场制造者)市场数学模拟包.

## 安装

```sh
npm install @exponent-labs/market-three-math
```

也可以使用：`pnpm add @exponent-labs/market-three-math`、`yarn add @exponent-labs/market-three-math`、`bun add @exponent-labs/market-three-math`

## README

# @ exponent-labs/ market- 三马特

精准CLMM(集中流动性市场制造者)市场数学模拟包.

## 概览

这个软件包提供了从Exponent协议中实现 CLMM 数学函数的 TypeScript 执行. 它使客户方能够模拟:

-   **交换业务**:用准确的定价和费用计算模拟PT QQ SY交易
-   **流动存款**: 计算集中流动性头寸所需代号金额
-   **价格计算**: 在有效价格、隐含费率和勾选指数之间转换

实施是 Rust 链上程序代码中的直接端口 `solana/programs/exponent_clmm`。 。 。 .

## 安装

```bash
yarn add @exponent-labs/market-three-math
```

## 使用量

### 正在模拟交换

```typescript
import { MarketThreeState, SwapDirection, simulateSwap } from "@exponent-labs/market-three-math"

// Prepare market state
const marketState: MarketThreeState = {
  financials: {
    expirationTs: Date.now() / 1000 + 86400, // 1 day from now
    ptBalance: 1000000,
    syBalance: 1000000,
    liquidityBalance: 1000000,
  },
  configurationOptions: {
    lnFeeRateRoot: 0.001,
    rateScalarRoot: 5.0,
    treasuryFeeBps: 2000, // 20%
    lastLnImpliedRate: 0.05,
    epsilonClamp: 0.000001,
    minLpTickAmount: 1000,
    maxLpSupply: 10000000000,
    tickSpace: 100,
    priceDecimals: 4,
  },
  ticks: {
    currentTick: 500,
    currentSpotPrice: 0.05,
    feeGrowthIndexGlobalPt: 0,
    feeGrowthIndexGlobalSy: 0,
    ticks: [
      // ... tick data
    ],
    market: "marketAddress",
  },
  currentSyExchangeRate: 1.0,
}

// Simulate buying PT with SY
const swapResult = simulateSwap(marketState, {
  direction: SwapDirection.SyToPt,
  amountIn: 100000, // 100k SY
  syExchangeRate: 1.0,
  isCurrentFlashSwap: false,
  priceSpotLimit: 0.06, // Maximum price willing to pay
})

console.log("PT received:", swapResult.amountOut)
console.log("Fees paid:", swapResult.lpFeeChargedOutToken + swapResult.protocolFeeChargedOutToken)
console.log("Final price:", swapResult.finalSpotPrice)
```

### 模拟流动性存款

```typescript
import { estimateBalancedDeposit, simulateAddLiquidity } from "@exponent-labs/market-three-math"

// Estimate balanced amounts for a target liquidity
const { ptNeeded, syNeeded } = estimateBalancedDeposit(
  marketState,
  100000, // Target liquidity
  4.5, // Lower tick APY (%)
  5.5, // Upper tick APY (%)
)

// Simulate the actual deposit
const depositResult = simulateAddLiquidity(marketState, {
  lowerTick: 45000, // 4.5% in basis points
  upperTick: 55000, // 5.5% in basis points
  maxSy: syNeeded,
  maxPt: ptNeeded,
  syExchangeRate: 1.0,
})

console.log("Liquidity added:", depositResult.deltaL)
console.log("PT spent:", depositResult.ptSpent)
console.log("SY spent:", depositResult.sySpent)
```

### 与有效价格合作

```typescript
import { EffSnap, normalizedTimeRemaining } from "@exponent-labs/market-three-math"

const secondsRemaining = 86400 // 1 day
const syExchangeRate = 1.0

const snap = new EffSnap(normalizedTimeRemaining(secondsRemaining), syExchangeRate)

// Convert ln implied rate to effective price
const lnImpliedRate = 0.05 // 5%
const effectivePrice = snap.getEffectivePrice(lnImpliedRate)

// Convert back from effective price to implied rate
const recoveredRate = snap.impliedRateFromEffectivePrice(effectivePrice)
```

## 关键概念

### 有效的价格模式

在以下情况下,CMM采用有效的价格模式:

```
C = e^(-τ * u) / r
```

地点:

-   `C` = 有效价格(每SYPT)
-   `τ` = 时间因素(正常至到期时间)
-   `u` = 以隐含价格计算(现货价格)
-   `r` =SY汇率

### 基于滴答的流动性

流动性集中在勾选范围,类似于Uniswap v3:

-   每个勾选符代表一个特定的暗示率
-   只有在当前价格在勾选范围内时才有流动性
-   为准确核算而存储 PT 和 SY 主机

### 收费结构

费用计算如下:

-   液化石油气费:由流动性提供者留存
-   礼宾费:送往国库(通常占总费用的20%)
-   到期后费率增加总额

## API 参考

### 类型

-   `MarketThreeState`: 模拟所需的完整市场状态
-   `SwapArgs`: 交换模拟参数
-   `SwapOutcome`: 互换模拟的结果
-   `AddLiquidityArgs`: 模拟流动性存款的论据
-   `AddLiquidityOutcome`: 流动性存款模拟结果
-   `Tick`: 单个勾选数据结构
-   `Ticks`: 完成带有元数据的勾选数组

### 职能

#### 交换函数

-   `simulateSwap(marketState, args)`: 模拟互换操作
-   `getSwapQuote(marketState, amountIn, direction)`: 快速引用以交换

#### 流动职能

-   `simulateAddLiquidity(marketState, args)`: 模拟流动性存款
-   `estimateBalancedDeposit(marketState, targetLiquidity, lowerTickApy, upperTickApy)`: PT/SY 余额估计数
-   `computeLiquidityTargetAndTokenNeeds(...)`: 低水平流动性计算

#### 工具函数

-   `EffSnap`: 有效的价格快照类
-   `calculateFeeRate(lnFeeRateRoot, secondsRemaining)`: 计算当前费率
-   `normalizedTimeRemaining(secondsRemaining)`: 将时间正常化为 \[0, 1\]
-   `getLnImpliedRate(tickKey)`: 将勾选键转换为暗示速率
-   `convertApyToApyBp(apyPercent)` 编号 : `convertApyBpToApy(apyBp)`: APY 转换公用事业

## 与 On-Chain 代码的关系

此套件是 Rust 执行程序的一个直接端口:

-   `solana/programs/exponent_clmm/src/state/market_three/helpers/swap.rs`
-   `solana/programs/exponent_clmm/src/state/market_three/helpers/add_liquidity.rs`
-   `solana/programs/exponent_clmm/src/utils/math.rs`

TypeScript执行与链上代码保持了数学等同,以确保准确的模拟.

## 许可证

AGPL-3.0 导弹

## 常见问题

### @exponent-labs/market-three-math 是什么？

精准CLMM\(集中流动性市场制造者\)市场数学模拟包\.

### 如何安装 @exponent-labs/market-three-math？

在项目目录运行 npm install @exponent-labs/market-three-math，或使用 pnpm add / yarn add / bun add。

### @exponent-labs/market-three-math 支持 TypeScript 吗？

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

### @exponent-labs/market-three-math 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @exponent-labs/market-three-math 可以商用吗？

@exponent-labs/market-three-math 使用 AGPL-3\.0 许可。最严格的 Copyleft：除分发外，通过网络向用户提供基于它的服务也需要开源对应源码。闭源 SaaS 使用前务必评估。以上为概括，不构成法律意见，请以许可原文为准。

### @exponent-labs/market-three-math 的下载量有多少？

根据 npm 官方下载统计，@exponent-labs/market-three-math 在 2026/10/14 – 2026/11/12 这 30 天内被下载 13,967 次，日均约 466 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @exponent-labs/market-three-math 还在维护吗？

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

