移除流动池

本指南中,我们将通过 DotSwap 提供的一个示例来展示如何进行移除流动池,这个过程包括:

  • 移除流动池

    • 预移除请求

    • 获取移除待签名 PSBT

    • 发送移除已签名 PSBT

  • 获取移除预估数量

RUNES/BRC20/ARC20 移除接口相同,根据coin_type_*区分。

预移除请求

POST /brc20swap/v2/pre_remove_liquid

export interface PreRemoveLiquidReq {
  coin_type_1: string;
  coin_type_2: string;
  fee_rate: string;
  payer_btc_addr: string;
  payer_ord_addr: string;
  payer_pub_key: string;
  percent: string;
  slipper: string;
  tick1: string;
  tick2: string;
}

示例

{
    "tick1": "BTC",
    "tick2": "RUNEONERUNEONE",
    "coin_type_1": "btc",
    "coin_type_2": "runes",
    "payer_ord_addr": "tb1qge80xavle7c7k0tk7vceaavwcgpsr3jchl0w3e",
    "payer_btc_addr": "tb1qge80xavle7c7k0tk7vceaavwcgpsr3jchl0w3e",
    "percent": "15",
    "slipper": "12",
    "fee_rate": "57",
    "payer_pub_key": "02d3ac7452920b1cc4653516dd4f4381a2df0a8c0aac6e3446e633a73ea63eee81:02d3ac7452920b1cc4653516dd4f4381a2df0a8c0aac6e3446e633a73ea63eee81"
}

1、返回结果原值传给 create_remove_liquid_psbt (下一个接口)

获取移除待签名 psbt

POST /brc20swap/v2/create_remove_liquid_psbt

export interface CreateRemoveLiquidPsbtReq {
  check_sum: string;
  coin_type_1: string;
  coin_type_2: string;
  expect_amount1: string;
  expect_amount2: string;
  expect_transfer_fee: number;
  fee_rate: string;
  payer_btc_addr: string;
  payer_ord_addr: string;
  payer_pub_key: string;
  percent: string;
  slipper: string;
  tick1: string;
  tick2: string;
  tx_size: number;
  usr_cnt: number;
  vins: string[];
}

示例

{
    "expect_amount1": "1500",
    "expect_amount2": "75",
    "expect_transfer_fee": 20121,
    "check_sum": "D6CCF094281BC79DD4AF6E7A7FBF1CDA",
    "tx_size": 353,
    "usr_cnt": 1,
    "vins": [
        "6cf1c2614a4eaaadf68769909b04687a2ddc4d6082fe4a78654dfad08a9a9323:6"
    ],
    "tick1": "BTC",
    "tick2": "RUNEONERUNEONE",
    "coin_type_1": "btc",
    "coin_type_2": "runes",
    "payer_ord_addr": "tb1qge80xavle7c7k0tk7vceaavwcgpsr3jchl0w3e",
    "payer_btc_addr": "tb1qge80xavle7c7k0tk7vceaavwcgpsr3jchl0w3e",
    "percent": "15",
    "slipper": "12",
    "fee_rate": "57",
    "payer_pub_key": "02d3ac7452920b1cc4653516dd4f4381a2df0a8c0aac6e3446e633a73ea63eee81:02d3ac7452920b1cc4653516dd4f4381a2df0a8c0aac6e3446e633a73ea63eee81"
}

发送移除已签名 PSBT

POST /brc20swap/v2/remove_liquid_by_psbt

export interface removeLiquidByPsbtReq {
  order_id: string;
  psbt: string;
  checksum: string;
  to_sign_inputs?: {
    index?: number;
    type?: string;
  }[];
}

示例

{
    "psbt": "70736274ff01007d020000000123939a8ad0fa4d65784afe82604ddc2d7a68049b906987f6adaa4e4a61c2f16c0600000000ffffffff02994e00000000000022512054f638dfba2ea8d607a59ec681a1ec479f741b0f505a116fe20172fde877eede52ca040000000000160014464ef3759fcfb1eb3d76f3319ef58ec20301c658000000000001011ffc3a050000000000160014464ef3759fcfb1eb3d76f3319ef58ec20301c65801086b0247304402200b398be45be70f30793de6e31aa9a9007a954f391f82e12b7a72c663af5d94570220230c28c921ca20e94669fab5abb7baf9cc908d121d2a5ffb96643e02c2d529bd012102d3ac7452920b1cc4653516dd4f4381a2df0a8c0aac6e3446e633a73ea63eee81000000",
    "order_id": "liquid_972788279311073280",
    "checksum": "CAA324EB56C64FA1A6646C9AED0E2BAF",
    "to_sign_inputs": null
}

获取移除预估数量

POST /brc20swap/get_liquid_info

export interface LiquidInfoBody {
  address: string;
  lp_precent: number;
  from_tick: string;
  to_tick: string;
}

示例

{
    "address": "tb1qge80xavle7c7k0tk7vceaavwcgpsr3jchl0w3e",
    "lp_precent": 35,
    "from_tick": "BTC",
    "to_tick": "RUNEONERUNEONE",
    "from_coin_type": "btc",
    "to_coin_type": "runes"
}

手续费说明

用户实际获得的数量,需要扣掉多签托管机构的服务费,该服务费费率使用后端返回的字段mutisign_fee_proportion(目前是 0.3%,未来如果托管机构变动,我们将会跟着调整)

手续费计算

  • btc-brc20\runes 移除手续费 = btc 聪数*0.3%

  • btc-arc20 移除手续费 = btc 聪数*0.3%+arc20 聪数*0.3%

  • brc20-brc20 移除手续费 = 免费

用户实际获得数量计算示例

if (from_coin_type === "btc") {
  finally_from_amount = from_amount * (1 - mutisign_fee_proportion);
  if (to_coin_type === "arc20") {
    finally_from_amount =
      finally_from_amount - to_amount * mutisign_fee_proportion;
  }
  finally_to_amount = to_amount;
}
if (to_coin_type === "btc") {
  finally_from_amount = from_amount;
  finally_to_amount = to_amount * (1 - mutisign_fee_proportion);
  if (to_coin_type === "arc20") {
    finally_to_amount =
      finally_to_amount - from_amount * mutisign_fee_proportion;
  }
}

1、预估数量会根据总流动池的数量实时变化,所以前端可进行轮询请求,以获得最新数量

Last updated