# @depay/web3-exchanges 中文文档

规范地址：https://npmcn.com/package/%40depay/web3-exchanges/

版本：15\.7\.3
npm 元数据更新时间：2025-09-21T14:15:40.876Z
中文译文更新时间：2026-11-12T00:42:37.244Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40depay/web3-exchanges
原文对照：https://npmcn.com/package/%40depay/web3-exchanges/?lang=original
项目主页：https://depay.com/
源码仓库：https://github.com/DePayFi/web3-exchanges

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

- 包体积（解压后）：2.9 MB，9 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：未声明
- Node.js 要求：\>=14
- 运行依赖：0 个
- peer 依赖：@depay/solana-web3\.js ^1\.98\.0，@depay/web3-blockchains ^9\.7\.9，@depay/web3-client ^11\.0\.2，@depay/web3-tokens ^11\.0\.0，decimal\.js ^10\.4\.3，ethers ^5\.7\.1
- 首次发布：2021-11-26T14:26:35.006Z
- 最新版本发布：2025-09-21T14:15:40.652Z
- 近 30 天下载量：3608（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：123（近 12 个月 0 个）

## 中文简介

JavaScript库简化了分散的Web3交换路由,用于多个块链和交换.

## 安装

```sh
npm install @depay/web3-exchanges
```

也可以使用：`pnpm add @depay/web3-exchanges`、`yarn add @depay/web3-exchanges`、`bun add @depay/web3-exchanges`

## README

## 快速启动

```
yarn add @depay/web3-exchanges
```

或者说

```
npm install --save @depay/web3-exchanges
```

```javascript
import Exchanges from '@depay/web3-exchanges'

Exchanges.uniswap_v2
Exchanges.orca

// scoped

Exchanges.ethereum.uniswap_v2 // Ethereum scoped uniswap_v2
Exchanges.solana.orca

let routes

routes = await Exchanges.route({
  blockchain: 'ethereum',
  tokenIn: '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb',
  tokenOut: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
  amountIn: 1
})

routes = await Exchanges.route({
  blockchain: 'solana',
  tokenIn: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
  tokenOut: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
  amountIn: 1
})

import { getWallets } from '@depay/web3-wallets'

const wallet = getWallets()[0]
const account = await wallet.account()

// check if prep is required to facilitate swap/exchange
const preparation = await route.getPrep({ account })

let permit2
if(prep?.transaction) {
  await wallet.sendTransaction(prep.transaction)
} else if (prep?.signature) {
  let signature = await wallet.sign(prep.signature)
  permit2 = {...prep.signature.message, signature}
}

// use connected wallet to sign and send the swap transaction
const transaction = await route.getTransaction({ account, permit2 })
wallet.sendTransaction(transaction)

```

## 支助

此库支持以下块链 :

-   [以利亚](https://ethereum.org/)
-   [BNB 智能链](https://www.binance.org/smartChain)
-   [多边形](https://polygon.technology/)
-   [索拉纳](https://solana.com/)
-   [乐观主义](https://www.optimism.io/)
-   [坐标](https://arbitrum.io/)
-   [方图](https://fantom.foundation/)
-   [雪崩](https://www.avax.network/)
-   [肠道](https://gnosis.io/)
-   [基础](https://base.org/)
-   [世界链](https://worldcoin.org/world-chain)

该图书馆支持以下分散交换:

以利亚:

-   [Uniswap v3 请检查url=值 (帮助)](https://uniswap.org/)
-   [Uniswap v2 请检查url=值 (帮助)](https://uniswap.org/)
-   [韦斯](https://etherscan.io/token/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2)

BNB 智能链 :

-   [煎饼Swap v3](https://pancakeswap.info/)
-   [Uniswap v3 请检查url=值 (帮助)](https://uniswap.org/)
-   [煎饼Swap v2](https://pancakeswap.info/)
-   [世行银行](https://bscscan.com/address/0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c)

多边形 :

-   [Uniswap v3 请检查url=值 (帮助)](https://uniswap.org/)
-   [快速扫描](https://quickswap.exchange/)
-   [妇女](https://polygonscan.com/token/0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270)

索拉纳:

-   [奥尔卡](https://orca.so/)
-   [Ium](https://raydium.io/),只有CP(固定产品)和CL(集中流动性)池

乐观:

-   [Uniswap v3 请检查url=值 (帮助)](https://uniswap.org/)
-   [韦斯](https://optimistic.etherscan.io/address/0x4200000000000000000000000000000000000006)

基础 :

-   [Uniswap v2 请检查url=值 (帮助)](https://uniswap.org/)
-   [Uniswap v3 请检查url=值 (帮助)](https://uniswap.org/)
-   [韦斯](https://optimistic.etherscan.io/address/0x4200000000000000000000000000000000000006)

坐标 :

-   [Uniswap v3 请检查url=值 (帮助)](https://uniswap.org/)
-   [韦斯](https://arbiscan.io/address/0x82aF49447D8a07e3bd95BD0d56f35241523fBab1)

方汤:

-   [幽灵扫描](https://spookyswap.fi/)
-   [世界妇女联合会](https://ftmscan.com/token/0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83)

雪崩:

-   [商人Joe v2.1](https://traderjoexyz.com/)
-   [瓦瓦克斯](https://snowtrace.io/token/0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7)

肠道:

-   [Uniswap v3 请检查url=值 (帮助)](https://uniswap.org/)
-   [瓦克萨斯州](https://gnosisscan.io/token/0xe91d153e0b41518a2ce8dd3d7944fa863463a97d)

## 平台专用包装

如果你想只使用和包装特定平台,请使用特定平台的软件包:

### EVM(Ethereum虚拟机)平台特定包装

```javascript
import Exchanges from '@depay/web3-exchanges-evm'
```

### SVM(索拉纳虚拟机)平台特定包装

```javascript
import Exchanges from '@depay/web3-exchanges-svm'
```

## 数据结构

### 交换

分散交换数据按以下结构提供:

```
{
  name: String (e.g. uniswap_v2)
  label: String (e.g. Uniswap v2)
  logo: String (base64 encoded PNG)
  protocol: String (uniswap_v2, uniswap_v3 etc.)

  fee: Array (e.g. [100, 500, 3000, 10000]; available fee teirs on the exchange)
  slippage: Boolean (indicates if exchange has slippage)

  blockchains: String (e.g. ['ethereum'])
  [blockchain]: {
    router: Object (contains 'address' and 'api' to interact with the exchange router)
    factory: Object (contains 'address' and 'api' to interact with the exchange factory)
    pair: Object (contains 'api' to interact with an exchange pair)
    quoter: Object (contains 'address' and 'api' to interact with the exchange quoter)
  }
}
```

### 交换

交换配置输入到 `route` 函数 :

```
{
  blockchain: String (e.g. 'ethereum')
  tokenIn: String (e.g. '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb')
  tokenOut: String (e.g. '0xdAC17F958D2ee523a2206206994597C13D831ec7')
  amountIn: Human Readable Number (e.g. 1.2 and converted internally to BigNumber) or BigNumber if passed as string
  amountInMax: Human Readable Number (e.g. 1.2 and converted internally to BigNumber) or BigNumber if passed as string
  amountOut: Human Readable Number (e.g. 1.2 and converted internally to BigNumber) or BigNumber if passed as string
  amountOutMin: Human Readable Number (e.g. 1.2 and converted internally to BigNumber) or BigNumber if passed as string
}
```

-   `tokenIn`: 输入交换的符号( 钱包外出)
-   `amountIn`: 确切的令牌数量 In 输入到交换中( 钱包外)
-   `amountInMax`输入到交换( 钱包外出 )
-   `tokenOut`: 换出时预期发出的符号( 输入钱包)
-   `amountOut`: 交换中预计会发出的令牌的确切数量( 输入钱包)
-   `amountOutMin`: 预想从互换中取出( 输入钱包) 的分量

所提供的数额可分为以下几种:

-   过 `amountOutMin`交换将至少返回 `amountOutMin` 输入钱包. `amountIn` 将自动计算,并可以变化.
-   过 `amountOut`交换最多 `amountInMax` (根据所提供的准确数字计算) `amountOut`) (中文(简体) ). `amountInMax` 将自动计算,并可以变化.
-   过 `amountInMax`交换最多 `amountInMax` 从钱包取出. `amountOut` 将自动计算,并可以变化.
-   过 `amountIn`交换将至少返回 `amountOutMin` 输入钱包(根据所提供的准确数字计算) `amountIn`) (中文(简体) ). `amountOutMin` 将自动计算,并可以变化.

### 路线

线路通过呼叫返回 `route` 打开 `Exchanges` 或单笔 `exchange`。 。 。 .

单人 `Route` 结构如下:

```
{
  blockchain: String (e.g. 'ethereum')
  tokenIn: String (e.g. '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb')
  decimalsIn: Integer (e.g. 18)
  tokenOut: String (e.g. '0xdAC17F958D2ee523a2206206994597C13D831ec7')
  decimalsOut: Integer (e.g. 18)
  path: Array (e.g. ['0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb', '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0xdAC17F958D2ee523a2206206994597C13D831ec7'])
  pools: Object ([{ pool }])
  amounts: [BigNumber] (e.g. ['1000000000000000000', '2300000000000000000', '9900000000000000000'])
  amountIn: BigNumber (e.g. '1000000000000000000')
  amountOutMin: BigNumber (e.g. '32000000000000000000')
  amountOut: BigNumber (e.g. '32000000000000000000')
  amountInMax: BigNumber (e.g. '1000000000000000000')
  exchange: Exchange (see [Exchange data structure](#exchange))
  getPrep: async function (returns transaction object for approvals or signature request for permit2)
  getTransaction: async function (returns transaction object –> see @depay/web3-wallets for details)
}
```

见 [@depay/web3-钱包](https://github.com/DePayFi/@depay/web3-wallets#sendtransaction) 关于交易格式的细节.

## 页

该库对以下组合的金额采用滑行策略:

-   若为 `amountOutMin` 提供,对 `amountIn`。 。 。 .
-   若为 `amountOut` 提供,对 `amountInMax`。 。 。 .
-   若为 `amountInMax` 提供,对 `amountOut`。 。 。 .
-   若为 `amountIn` 提供,对 `amountOutMax`。 。 。 .

### 自动剪贴板

自动拖放 `0.5%` 默认滑行 .

对于允许接收先前区块引号的区块链(`EVM`),自动拖放额外检查:

-   极端方向
    
-   极端基本波动
    

并应用高于默认的滑行`0.5%`如果需要的话.

#### 极端方向价格变化

如果最后三个街区的价格有明确的方向变化, 目标价格将根据最后三个区块的速度预测.

##### 示例 极端方向价格变化

目前价格:1'500美元

最后3块: 1'500美元, 1'470美元, 1'440美元

速度:每区30美元

预测:1'530美元

页 2%

滑动 `2%` 将应用,因为它比默认的滑行要高.

_对于向下预测,不需要延误,因为交易不会失败._

#### 极端基本波动

如果最后3个街区有极端的地基波动, 无方向, 目标价格将是过去3个街区的最高价格,加上过去3个街区的最低价格变化.

##### 极端基态波动

目前价格:1'500美元

最后三个街区: 1'500美元, 1'490美元, 1'520美元

最小的变化:10美元

最高价格:1'520美元

预测:1'530美元(1'520美元+10美元)

页 2%

滑动 `2%` 将应用,因为它比默认的滑行要高.

## 职能

### 直接访问交换

```javascript
import Exchanges from '@depay/web3-exchanges'

Exchanges.uniswap_v2

```

### 特定区块链的访问交换范围

```javascript
import Exchanges from '@depay/web3-exchanges'

Exchanges.arbitrum.uniswap_v3
```

### 路由: 进行交换的路由和返回路由

```javascript
import Exchanges from '@depay/web3-exchanges'

let routes = Exchanges.route({
  blockchain: 'ethereum'
  tokenIn: '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb',
  tokenOut: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
  amountOutMin: 2
})
```

`route` 也可以要求交换:

```javascript
import Exchanges from '@depay/web3-exchanges'

let route = await Exchanges.ethereum.uniswap_v2.route({
  tokenIn: '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb',
  tokenOut: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
  amountIn: 1
})
```

## 发展

```
yarn install
yarn dev
```

## 常见问题

### @depay/web3-exchanges 是什么？

JavaScript库简化了分散的Web3交换路由,用于多个块链和交换\.

### 如何安装 @depay/web3-exchanges？

在项目目录运行 npm install @depay/web3-exchanges，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@depay/solana-web3\.js（^1\.98\.0）、@depay/web3-blockchains（^9\.7\.9）、@depay/web3-client（^11\.0\.2）、@depay/web3-tokens（^11\.0\.0）、decimal\.js（^10\.4\.3）、ethers（^5\.7\.1）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @depay/web3-exchanges 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/depay\_\_web3-exchanges 是否存在。

### @depay/web3-exchanges 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @depay/web3-exchanges 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=14。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @depay/web3-exchanges 可以商用吗？

@depay/web3-exchanges 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @depay/web3-exchanges 的下载量有多少？

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

### @depay/web3-exchanges 还在维护吗？

最新版本 15\.7\.3 发布于 2025/09/21（1\.1 年前）；至今共发布 123 个版本，其中过去 12 个月发布了 0 个；首次发布于 2021/11/26。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

