Skip to content

Commit

Permalink
multi: use PPM rate-based premium limit
Browse files Browse the repository at this point in the history
This change interprets premium_limit as a PPM rate
Prevents confusion about total premium amounts
  • Loading branch information
YusukeShimizu committed Feb 28, 2025
1 parent 455eeb4 commit c84e53a
Show file tree
Hide file tree
Showing 20 changed files with 2,088 additions and 2,020 deletions.
28 changes: 14 additions & 14 deletions clightning/clightning_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ func (s *LiquidSendToAddress) LongDescription() string {

// SwapOut starts a new swapout (paying an Invoice for onchain liquidity)
type SwapOut struct {
ShortChannelId string `json:"short_channel_id"`
SatAmt uint64 `json:"amt_sat"`
Asset string `json:"asset"`
PremiumLimit int64 `json:"premium_limit"`
Force bool `json:"force"`
cl *ClightningClient `json:"-"`
ShortChannelId string `json:"short_channel_id"`
SatAmt uint64 `json:"amt_sat"`
Asset string `json:"asset"`
PremiumLimitRatePPM int64 `json:"premium_rate_limit_ppm"`
Force bool `json:"force"`
cl *ClightningClient `json:"-"`
}

func (l *SwapOut) New() interface{} {
Expand Down Expand Up @@ -262,7 +262,7 @@ func (l *SwapOut) Call() (jrpc2.Result, error) {
}

pk := l.cl.GetNodeId()
swapOut, err := l.cl.swaps.SwapOut(fundingChannels.Id, l.Asset, l.ShortChannelId, pk, l.SatAmt, l.PremiumLimit)
swapOut, err := l.cl.swaps.SwapOut(fundingChannels.Id, l.Asset, l.ShortChannelId, pk, l.SatAmt, l.PremiumLimitRatePPM)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -304,12 +304,12 @@ func (g *SwapOut) Get(client *ClightningClient) jrpc2.ServerMethod {

// SwapIn Starts a new swap in(providing onchain liquidity)
type SwapIn struct {
ShortChannelId string `json:"short_channel_id"`
SatAmt uint64 `json:"amt_sat"`
Asset string `json:"asset"`
PremiumLimit int64 `json:"premium_limit"`
Force bool `json:"force"`
cl *ClightningClient `json:"-"`
ShortChannelId string `json:"short_channel_id"`
SatAmt uint64 `json:"amt_sat"`
Asset string `json:"asset"`
PremiumLimitRatePPM int64 `json:"premium_limit_ppm"`
Force bool `json:"force"`
cl *ClightningClient `json:"-"`
}

func (l *SwapIn) New() interface{} {
Expand Down Expand Up @@ -378,7 +378,7 @@ func (l *SwapIn) Call() (jrpc2.Result, error) {
}

pk := l.cl.GetNodeId()
swapIn, err := l.cl.swaps.SwapIn(fundingChannels.Id, l.Asset, l.ShortChannelId, pk, l.SatAmt, l.PremiumLimit)
swapIn, err := l.cl.swaps.SwapIn(fundingChannels.Id, l.Asset, l.ShortChannelId, pk, l.SatAmt, l.PremiumLimitRatePPM)
if err != nil {
return nil, err
}
Expand Down
26 changes: 13 additions & 13 deletions cmd/peerswaplnd/pscli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ var (
Name: "peer_pubkey",
Required: true,
}
premiumLimitFlag = cli.Uint64Flag{
Name: "premium_limit",
Usage: "premium limit for a swap",
PremiumLimitRatePPMFlag = cli.Uint64Flag{
Name: "premium_limit_rate_ppm",
Usage: "premium limit for a swap in parts per million",
Required: false,
}
operationFlag = cli.StringFlag{
Expand All @@ -103,7 +103,7 @@ var (
satAmountFlag,
channelIdFlag,
assetFlag,
premiumLimitFlag,
PremiumLimitRatePPMFlag,
},
Action: swapOut,
}
Expand All @@ -115,7 +115,7 @@ var (
satAmountFlag,
channelIdFlag,
assetFlag,
premiumLimitFlag,
PremiumLimitRatePPMFlag,
},
Action: swapIn,
}
Expand Down Expand Up @@ -277,10 +277,10 @@ func swapIn(ctx *cli.Context) error {
defer cleanup()

res, err := client.SwapIn(context.Background(), &peerswaprpc.SwapInRequest{
ChannelId: ctx.Uint64(channelIdFlag.Name),
SwapAmount: ctx.Uint64(satAmountFlag.Name),
Asset: ctx.String(assetFlag.Name),
PremiumLimit: ctx.Int64(premiumLimitFlag.Name),
ChannelId: ctx.Uint64(channelIdFlag.Name),
SwapAmount: ctx.Uint64(satAmountFlag.Name),
Asset: ctx.String(assetFlag.Name),
PremiumLimitRatePpm: ctx.Int64(PremiumLimitRatePPMFlag.Name),
})
if err != nil {
return err
Expand All @@ -298,10 +298,10 @@ func swapOut(ctx *cli.Context) error {
defer cleanup()

res, err := client.SwapOut(context.Background(), &peerswaprpc.SwapOutRequest{
ChannelId: ctx.Uint64(channelIdFlag.Name),
SwapAmount: ctx.Uint64(satAmountFlag.Name),
Asset: ctx.String(assetFlag.Name),
PremiumLimit: ctx.Int64(premiumLimitFlag.Name),
ChannelId: ctx.Uint64(channelIdFlag.Name),
SwapAmount: ctx.Uint64(satAmountFlag.Name),
Asset: ctx.String(assetFlag.Name),
PremiumLimitRatePpm: ctx.Int64(PremiumLimitRatePPMFlag.Name),
})
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ A swap-out is when the initiator wants to pay a lightning payment in order to re

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

For LND:
```bash
pscli swapout --channel-id [chan_id] --sat_amt [amount in sats] --asset [btc or lbtc] --premium_limit [premium limit in sats]
pscli swapout --channel-id [chan_id] --sat_amt [amount in sats] --asset [btc or lbtc] --premium_limit_rate_ppm [premium limit in ppm]
```

### Swap-In
Expand All @@ -87,12 +87,12 @@ A swap-in is when the initiator wants to spend onchain bitcoin in order to recei

For CLN:
```bash
lightning-cli peerswap-swap-in [short channel id] [amount in sats] [asset: btc or lbtc] [premium limit in sats]
lightning-cli peerswap-swap-in [short channel id] [amount in sats] [asset: btc or lbtc] [premium limit in ppm]
```

For LND:
```bash
pscli swapin --channel_id [chan_id] --sat_amt [amount in sats] --asset [btc or lbtc] --premium_limit [premium limit in sats]
pscli swapin --channel_id [chan_id] --sat_amt [amount in sats] --asset [btc or lbtc] --premium_limit_rate_ppm [premium limit in ppm]
```

## Premium
Expand Down
Loading

0 comments on commit c84e53a

Please sign in to comment.