@blockworks-foundation/mango-client

中文文档
2.3.0发布于 2023/11/14MITTypeScriptCommonJS近 30 天下载 4079

与芒果市场Solana智能合约互动的图书馆.

中文使用文档
文档目录5 节
  1. 版本数
  2. 测试
  3. 所需资源
  4. 测试清算
  5. 示例

芒果客户端

一个与芒果程序接触的客户端

版本数

2.0.0 释放了June 9, 2021

  • 支持 Mango 的 5 个符号版本
  • 页:1

0.1.19 联合国

测试

所有测试都要在devnet上进行 全面测试运行,需要很长时间才能进行,有时由于连通性问题或其他工作人而失败 脱网因此,建议进行这样的孤立试验:

yarn test -g "<test description>"

例如,以下测试:

it('should log lotSizes', async() => {...});

就会像这样跑

yarn test -g "should log lotSizes"

您还可以指定一个测试组, 可以运行多个测试, 例如下面的组 -

describe('log stuff', async() => {...});

可以这样运行..

yarn test -g "should log lotSizes"

如果你真的想运行 全套测试只是运行 -

yarn test

所需资源

诸如伐木和订单匹配等一些测试将没有任何要求进行,但所有清算测试都期望有一个 AGGREGATOR_PATH 变量集 .env 数据。 。 。 .

这个 AGGREGATOR_PATH 变量应该是 solana-flux-聚合剂 可获取的路径 这里。 。 。 .

示例 .env 数据 文件 -

AGGREGATOR_PATH=~/solana-flux-aggregator

测试清算

套房中最能动的测试之一是清算测试,这可以在 stress testing partial liquidation 组只需在您的 IDE 中搜索它.

所有测试都有变异 stressTestLiquidation 函数.

这个函数大致由 -

  1. 创建和资金a 丽琪 待清算的账户
  2. 将预告价格改为订单价格 丽琪 是关于提交
  3. 代表缔约方提交长或短命令 丽琪
  4. 将甲骨文价格改为强制 丽琪低于维护门槛值的附带比率
  5. 创建和资金a 里科尔 将进行清算的账户
  6. 里科尔 进行清算

以下列出可以产生许多不同清算假设的参数:

mangoGroupSpotMarket: Market,
orderQuantity?: number, // Default = 1
customLiqeeOwner?: Account, // Default = null
shouldPartialLiquidate?: boolean, // Default = false
shouldCreateNewLiqor?: boolean, // Default = true
shouldFinishLiquidationInTest?: boolean, // Default = true
customOrderPrice?: number, // Default = 0
customOrderSize?: number, // Default = 0
leverageCoefficient?: number, // Default = 15
matchLeveragedOrder?: boolean, // Default = false
side?: 'buy' | 'sell' // Default = 'buy'
  • 芒果组点市场 应当创造清算机会的现货市场
  • 数量 指定多少命令 丽琪 账户应该创建, 它不影响命令Size
  • 自定义Liqee-Owner 如果您想要重新使用现有账户,则可以指定 liqee。如果您想要将清算情况连锁起来,则这样做是有用的。 如果空出, 将创建新账户
  • 应 PartialLiquidate (应参加) 指明应当定期清算还是部分清算
  • 应创建新地址 将建立一个新的liqor账户,为清算提供资金。 如果你把清算方案连在一起 不需要在每一个方案上建立一个清算人 这样你就可以设定它 false
  • 应完成定量 测试 - 和上面一样,您应该将这个参数设置为 false 或希望手工完成清算.
  • 自定义命令 - 如果不设定,它将使用 minPrice 市场
  • 自定义命令大小 - 如果不设定,它将使用 minSize 市场
  • 杠杆 - 此参数指定了当前 丽琪例如,15个系数将生效 丽琪 改为 15x
  • 匹配已调整的顺序 指定长或短是否应当相匹配,否则清算方案将与借款一起进行,以便始终保持与开放订单相同的货币。 如果设置为 true 它会把杠杆提高一倍.
  • 边 指定是长还是短才被清算

示例

async function main() {
  const client = new MangoClient()
  const cluster = 'mainnet-beta'
  const clusterUrl = process.env.CLUSTER_URL || IDS.cluster_urls[cluster]
  const connection = new Connection(clusterUrl, 'singleGossip')
  const programId = new PublicKey(IDS[cluster].mango_program_id)
  const dexProgramId = new PublicKey(IDS[cluster].dex_program_id)
  const mangoGroupPk = new PublicKey(IDS[cluster].mango_groups['BTC_ETH_USDT'].mango_group_pk)

  const keyPairPath = process.env.KEYPAIR || homedir() + '/.config/solana/id.json'

  const payer = new Account(JSON.parse(fs.readFileSync(keyPairPath, 'utf-8')))
  const mangoGroup = await client.getMangoGroup(connection, mangoGroupPk)
  const prices = await mangoGroup.getPrices(connection)
  const marginAccounts = (await client.getMarginAccountsForOwner(connection, programId, mangoGroup, payer))
  marginAccounts.sort(
    (a, b) => (a.computeValue(mangoGroup, prices) > b.computeValue(mangoGroup, prices) ? -1 : 1)
  )
  let marginAccount = marginAccounts[0]

  const market = await Market.load(connection, mangoGroup.spotMarkets[0], { skipPreflight: true, commitment: 'singleGossip'}, mangoGroup.dexProgramId)
  console.log('placing order')
  const txid = await client.placeOrder(connection, programId, mangoGroup, marginAccount, market, payer, 'buy', 48000, 0.0001)
  console.log('order placed')

  await sleep(5000)
  marginAccount = await client.getMarginAccount(connection, marginAccount.publicKey, mangoGroup.dexProgramId)
  const bids = await market.loadBids(connection)
  const asks = await market.loadAsks(connection)
  console.log('canceling orders')
  await marginAccount.cancelAllOrdersByMarket(connection, client, programId, mangoGroup, market, bids, asks, payer)
  console.log('orders canceled')
}

版本与发布记录

@blockworks-foundation/mango-client 共发布 154 个版本,首次发布于 2021/02/22;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.3.0latest2023/11/142 年前
3.6.202022/10/044 年前
3.6.192022/09/164 年前
3.6.182022/09/134 年前
3.6.172022/09/074 年前
3.6.162022/09/064 年前

其他发布通道:beta → 3.0.2,old → 2.1.4,next → 3.1.0。

关于 @blockworks-foundation/mango-client 的常见问题

@blockworks-foundation/mango-client 是什么?

与芒果市场Solana智能合约互动的图书馆.

如何安装 @blockworks-foundation/mango-client?

在项目目录运行 npm install @blockworks-foundation/mango-client,或使用 pnpm add / yarn add / bun add。

@blockworks-foundation/mango-client 支持 TypeScript 吗?

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

@blockworks-foundation/mango-client 支持 ESM 还是 CommonJS?

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

@blockworks-foundation/mango-client 需要什么版本的 Node.js?

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

@blockworks-foundation/mango-client 可以商用吗?

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

@blockworks-foundation/mango-client 的下载量有多少?

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

@blockworks-foundation/mango-client 还在维护吗?

最新版本 2.3.0 发布于 2023/11/14(2 年前);至今共发布 154 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/02/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。