peerswap icon indicating copy to clipboard operation
peerswap copied to clipboard

Premium

Open YusukeShimizu opened this issue 6 months ago • 24 comments

This PR adds premium to peerswap. design doc

Usage

doing swap

A premium limit will be added to the existing swap command. If not set, default is 0.

cln

lightning-cli peerswap-swap-out [short channel id] [amount in sats] [asset: btc or lbtc] [premium limit in sats]

lnd

pscli swapout --sat_amt=[sat amount] --channel_id=[chan_id from above] --asset=btc --premium_limit=[premium limit]

configure premium rate

The premium rate is pert per million and can be set for swapin and swapout respectively. swap_amount * premium_rate_ppm / 1000000 is the premium. Negative values can also be set to give a discount

policy.conf

swap_in_premium_rate_ppm=10000
swap_out_premium_rate_ppm=20000

You can check the premium rate set for each peer by using listpeers.

pscli listpeers
{
  "peers": [
    {
      "node_id": "0322d434b1f90b1ca1c35f2ecf3d250bd3884f5d2809156eb76929b91d73322bf0",
      "swaps_allowed": true,
      "supported_assets": [
        "btc",
        "lbtc"
      ],
      "channels": [
        {
          "channel_id": "120946279120897",
          "local_balance": "99996530",
          "remote_balance": "0",
          "active": true
        }
      ],
      "as_sender": {
        "swaps_out": "0",
        "swaps_in": "0",
        "sats_out": "0",
        "sats_in": "0"
      },
      "as_receiver": {
        "swaps_out": "0",
        "swaps_in": "0",
        "sats_out": "0",
        "sats_in": "0"
      },
      "paid_fee": "0",
      "swap_in_premium_rate_ppm": "100",
      "swap_out_premium_rate_ppm": "100"
    }
  ]
}

examples

If the max_acceptable_premium is lower than responder.

./bin/pscli peerswap1 swapout --channel_id $CHANID --sat_amt 1000000 --asset btc --premium_limit 1
2023/12/23 02:02:36 rpc error: code = Unknown desc = from the LND peer: unacceptable premium: 100, limit: 1

success

./bin/pscli peerswap1 swapout --channel_id $CHANID --sat_amt 1000000 --asset btc --premium_limit 100
{
  "swap": {
    "id": "eb5f41a515f737956300a38ab1f5286a67d580c4d3f838afdf48537c1133ed69",
    "created_at": "1702532654",
    "asset": "btc",
    "type": "swap-out",
    "role": "sender",
    "state": "State_SwapOutSender_AwaitTxConfirmation",
    "initiator_node_id": "02ea1fd791bb1b639e7119ac54505e3f553a7bb942877ccbb359affa8547046988",
    "peer_node_id": "034066fecfcdad7cb2f002c8c4234dbab26688db9617509ede4c7372c79ab94d0d",
    "amount": "1000000",
    "channel_id": "110:1:1",
    "opening_tx_id": "83f0b1174a3c55934ca9fa60398dbdfa76394db1450cbe2c1d2369ef80095b15",
    "claim_tx_id": "",
    "cancel_message": "",
    "lnd_chan_id": "120946279120897",
    "premium": "100"
  }
}

YusukeShimizu avatar Dec 23 '23 04:12 YusukeShimizu