Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StaticAddr: merge staging to master #853

Merged
merged 71 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
2c07434
sqlc: static address migrations, models, queries
hieblmi Nov 9, 2023
a9b41bf
looprpc: static address creation
hieblmi Feb 14, 2024
8f60a49
log: static address sub logger
hieblmi Nov 9, 2023
ca2ecac
loopdb: static address store
hieblmi Nov 9, 2023
8d777c2
staticaddr: static address manager
hieblmi Nov 9, 2023
d351d22
staticaddr: static address server
hieblmi Feb 14, 2024
40c731f
daemon: integrate static address manager and sql store
hieblmi Nov 9, 2023
14810b7
perms: static address creation permission
hieblmi Nov 9, 2023
a0d10fc
loop: static address creation client command
hieblmi Nov 9, 2023
ff08d9a
looprpc: list unspent static address
hieblmi Nov 9, 2023
a139272
staticaddr: track and list spends in manager
hieblmi Oct 25, 2023
eeaf291
staticaddr: list unspent outputs in server
hieblmi Oct 25, 2023
ded2526
perms: list unspent outputs
hieblmi Oct 25, 2023
edea672
loop: list unspent static address outputs
hieblmi Oct 25, 2023
b454d95
looprpc: include static address in swap client
hieblmi Feb 26, 2024
5f4fca8
sqlc: deposit queries, models and migrations
hieblmi Mar 7, 2024
52a11a0
staticaddr: interfaces
hieblmi Mar 7, 2024
d76c99c
staticaddr: deposit logger
hieblmi Mar 7, 2024
042fe9f
staticaddr: deposit manager and fsm
hieblmi Mar 7, 2024
3914ab8
staticaddr: deposits for server and daemon
hieblmi Mar 7, 2024
063e4a2
staticaddr: add swap client to cmd
hieblmi Mar 7, 2024
b7b553c
unit: manager tests
hieblmi Apr 23, 2024
70b2189
staticaddr: public deposit method scope
hieblmi Apr 25, 2024
55f7625
sqlc: withdrawal address for deposits
hieblmi May 6, 2024
b5b857a
looprpc: deposit withdrawal endpoint
hieblmi May 6, 2024
9e56be7
log: unified static address logger
hieblmi May 6, 2024
1f2ec79
staticaddr: address and deposit adjustments for withdrawals
hieblmi May 6, 2024
3dca153
staticaddr: withdrawal manager and interface
hieblmi May 6, 2024
a7f2f2d
loopd: static address withdrawals support
hieblmi May 6, 2024
ab10ee9
loop: static address withdrawals support
hieblmi May 6, 2024
aa7afa7
looprpc: static address summary
hieblmi Jun 5, 2024
ea2b3c8
staticaddr: expose static address to client summary
hieblmi Jun 5, 2024
8595c4a
loopd: static address summary
hieblmi Jun 5, 2024
549c33e
looprpc: deposit outpoints for QuoteRequest
hieblmi Jun 6, 2024
82b9579
loopd: quoting for static address loop-ins
hieblmi Jun 6, 2024
55ff8aa
cmd: quote for static address loop-ins
hieblmi Jun 6, 2024
b9e5875
looprpc: static address loop-ins
hieblmi Nov 19, 2024
494d091
sqlc: loop-in tables and queries
hieblmi Jul 30, 2024
3894370
log: static address loop-in logging
hieblmi Jul 30, 2024
c11e901
staticaddr: enable deposits for swaps
hieblmi Jul 30, 2024
2b31a48
loopin: public scope for ValidateLoopInContract
hieblmi Sep 26, 2024
4d8c258
interface: add StaticAddressLoopInRequest interface
hieblmi Sep 26, 2024
f3ec81f
staticaddr: configurable max htlc tx fee
hieblmi Oct 17, 2024
1e3f75b
staticaddr: loopin
hieblmi Oct 30, 2024
e7c3717
staticaddr: sql_store
hieblmi Oct 30, 2024
9a2270e
staticaddr: swap manager and fsm
hieblmi Oct 24, 2024
f8535a0
unit: manager mocks for static address loop-in
hieblmi Jul 30, 2024
21c37a9
loopd: static address loop-in support
hieblmi Jul 30, 2024
a3f7fe4
cmd: static address loop-in
hieblmi Jul 30, 2024
439d178
staticaddr: cmd listdeposits and listswaps
hieblmi Nov 5, 2024
781d3a0
staticaddr: separate file for rpc service
hieblmi Nov 5, 2024
e3e56ec
staticaddr: change min deposit confs from 3 to 6
hieblmi Nov 5, 2024
ed1585d
staticaddr: fix fsm logging
hieblmi Nov 5, 2024
216aebb
notifications: add support for new ntfn
sputn1ck Nov 14, 2024
409b2e9
staticaddr/sql_store: Add fetching loop in by hash
sputn1ck Nov 14, 2024
099e980
staticaddr/loopin: add listening for sweep request
sputn1ck Nov 14, 2024
3f6759c
staticaddr/loopin: update fsm for server ntfn sigs
sputn1ck Nov 14, 2024
a98e161
loopd/staticaddr: add ntfn manager
sputn1ck Nov 14, 2024
115558b
staticaddr/loopin: remove unused code
sputn1ck Nov 14, 2024
3deeb3a
loopcli/staticaddr: explicit loop in command
sputn1ck Nov 18, 2024
1c3921b
cmd/staticaddr: hide behind build flag
sputn1ck Nov 19, 2024
e32f7e3
looprpc: addr and fee rate for withdrawals
hieblmi Nov 29, 2024
042b513
staticaddr: dest addr and fee rate for withdrawals
hieblmi Nov 29, 2024
bfe09c5
staticaddr: add build tag
hieblmi Dec 4, 2024
fc6c9f2
staticaddr: add initiation height of address
hieblmi Dec 9, 2024
c9068ac
gomod: bump looprpc and swapserverrpc version
hieblmi Dec 10, 2024
b25b451
cmd: add static address warning
hieblmi Dec 11, 2024
9342b0f
staticaddr: remove build tag
hieblmi Dec 12, 2024
249a423
staticaddr: fix waring message formatting
hieblmi Dec 13, 2024
10b970c
staticaddr: no experimental flag for static
hieblmi Dec 13, 2024
acea303
staticaddr: check dust limits before withdrawing
hieblmi Dec 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ var (
ErrSwapAmountTooHigh = errors.New("swap amount too high")

// ErrExpiryTooFar is returned when the server proposes an expiry that
// is too soon for us.
// is too far in the future.
ErrExpiryTooFar = errors.New("swap expiry too far")

// ErrExpiryTooSoon is returned when the server proposes an expiry that
// is too soon.
ErrExpiryTooSoon = errors.New("swap expiry too soon")

// ErrInsufficientBalance indicates insufficient confirmed balance to
// publish a swap.
ErrInsufficientBalance = errors.New("insufficient confirmed balance")
Expand Down Expand Up @@ -137,6 +141,22 @@ type ClientConfig struct {
// MaxPaymentRetries is the maximum times we retry an off-chain payment
// (used in loop out).
MaxPaymentRetries int

// MaxStaticAddrHtlcFeePercentage is the percentage of the swap amount
// that we allow the server to charge for the htlc transaction.
// Although highly unlikely, this is a defense against the server
// publishing the htlc without paying the swap invoice, forcing us to
// sweep the timeout path.
MaxStaticAddrHtlcFeePercentage float64

// MaxStaticAddrHtlcBackupFeePercentage is the percentage of the swap
// amount that we allow the server to charge for the htlc backup
// transactions. This is a defense against the server publishing the
// htlc backup without paying the swap invoice, forcing us to sweep the
// timeout path. This value is elevated compared to
// MaxStaticAddrHtlcFeePercentage since it serves the server as backup
// transaction in case of fee spikes.
MaxStaticAddrHtlcBackupFeePercentage float64
}

// NewClient returns a new instance to initiate swaps with.
Expand Down Expand Up @@ -694,9 +714,9 @@ func (s *Client) LoopIn(globalCtx context.Context,
return swapInfo, nil
}

// LoopInQuote takes an amount and returns a break down of estimated
// costs for the client. Both the swap server and the on-chain fee estimator are
// queried to get to build the quote response.
// LoopInQuote takes an amount and returns a breakdown of estimated costs for
// the client. Both the swap server and the on-chain fee estimator are queried
// to get to build the quote response.
func (s *Client) LoopInQuote(ctx context.Context,
request *LoopInQuoteRequest) (*LoopInQuote, error) {

Expand Down Expand Up @@ -742,7 +762,7 @@ func (s *Client) LoopInQuote(ctx context.Context,

quote, err := s.Server.GetLoopInQuote(
ctx, request.Amount, s.lndServices.NodePubkey, request.LastHop,
request.RouteHints, request.Initiator,
request.RouteHints, request.Initiator, request.NumDeposits,
)
if err != nil {
return nil, err
Expand All @@ -752,7 +772,9 @@ func (s *Client) LoopInQuote(ctx context.Context,

// We don't calculate the on-chain fee if the HTLC is going to be
// published externally.
if request.ExternalHtlc {
// We also don't calculate the on-chain fee if the loop in is funded by
// static address deposits because we don't publish the HTLC on-chain.
if request.ExternalHtlc || request.NumDeposits > 0 {
return &LoopInQuote{
SwapFee: swapFee,
MinerFee: 0,
Expand Down
24 changes: 16 additions & 8 deletions cmd/loop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ var (
Name: "verbose, v",
Usage: "show expanded details",
}

commands = []cli.Command{
loopOutCommand, loopInCommand, termsCommand,
monitorCommand, quoteCommand, listAuthCommand, fetchL402Command,
listSwapsCommand, swapInfoCommand, getLiquidityParamsCommand,
setLiquidityRuleCommand, suggestSwapCommand, setParamsCommand,
getInfoCommand, abandonSwapCommand, reservationsCommands,
instantOutCommand, listInstantOutsCommand,
}
)

const (
Expand Down Expand Up @@ -142,14 +151,7 @@ func main() {
tlsCertFlag,
macaroonPathFlag,
}
app.Commands = []cli.Command{
loopOutCommand, loopInCommand, termsCommand,
monitorCommand, quoteCommand, listAuthCommand, fetchL402Command,
listSwapsCommand, swapInfoCommand, getLiquidityParamsCommand,
setLiquidityRuleCommand, suggestSwapCommand, setParamsCommand,
getInfoCommand, abandonSwapCommand, reservationsCommands,
instantOutCommand, listInstantOutsCommand,
}
app.Commands = commands

err := app.Run(os.Args)
if err != nil {
Expand Down Expand Up @@ -279,6 +281,12 @@ func displayInDetails(req *looprpc.QuoteRequest,
"wallet.\n\n")
}

if req.DepositOutpoints != nil {
fmt.Printf("On-chain fees for static address loop-ins are not " +
"included.\nThey were already paid when the deposits " +
"were created.\n\n")
}

printQuoteInResp(req, resp, verbose)

fmt.Printf("\nCONTINUE SWAP? (y/n): ")
Expand Down
82 changes: 70 additions & 12 deletions cmd/loop/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"time"

"github.com/btcsuite/btcd/btcutil"
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/looprpc"
"github.com/lightningnetwork/lnd/routing/route"
Expand All @@ -19,10 +20,11 @@ var quoteCommand = cli.Command{
}

var quoteInCommand = cli.Command{
Name: "in",
Usage: "get a quote for the cost of a loop in swap",
ArgsUsage: "amt",
Description: "Allows to determine the cost of a swap up front",
Name: "in",
Usage: "get a quote for the cost of a loop in swap",
ArgsUsage: "amt",
Description: "Allows to determine the cost of a swap up front." +
"Either specify an amount or deposit outpoints.",
Flags: []cli.Flag{
cli.StringFlag{
Name: lastHopFlag.Name,
Expand All @@ -33,20 +35,38 @@ var quoteInCommand = cli.Command{
verboseFlag,
privateFlag,
routeHintsFlag,
cli.StringSliceFlag{
Name: "deposit_outpoint",
Usage: "one or more static address deposit outpoints " +
"to quote for. Deposit outpoints are not to " +
"be used in combination with an amount. Each" +
"additional outpoint can be added by " +
"specifying --deposit_outpoint tx_id:idx",
},
},
Action: quoteIn,
}

func quoteIn(ctx *cli.Context) error {
// Show command help if the incorrect number arguments was provided.
if ctx.NArg() != 1 {
if ctx.NArg() != 1 && !ctx.IsSet("deposit_outpoint") {
return cli.ShowCommandHelp(ctx, "in")
}

args := ctx.Args()
amt, err := parseAmt(args[0])
if err != nil {
return err
var (
manualAmt btcutil.Amount
depositAmt btcutil.Amount
depositOutpoints []string
err error
ctxb = context.Background()
)

if ctx.NArg() == 1 {
args := ctx.Args()
manualAmt, err = parseAmt(args[0])
if err != nil {
return err
}
}

client, cleanup, err := getClient(ctx)
Expand All @@ -62,11 +82,20 @@ func quoteIn(ctx *cli.Context) error {
return err
}

if ctx.IsSet("deposit_outpoint") {
depositOutpoints = ctx.StringSlice("deposit_outpoint")
depositAmt, err = depositAmount(ctxb, client, depositOutpoints)
if err != nil {
return err
}
}

quoteReq := &looprpc.QuoteRequest{
Amt: int64(amt),
Amt: int64(manualAmt),
ConfTarget: int32(ctx.Uint64("conf_target")),
LoopInRouteHints: hints,
Private: ctx.Bool(privateFlag.Name),
DepositOutpoints: depositOutpoints,
}

if ctx.IsSet(lastHopFlag.Name) {
Expand All @@ -80,7 +109,6 @@ func quoteIn(ctx *cli.Context) error {
quoteReq.LoopInLastHop = lastHopVertex[:]
}

ctxb := context.Background()
quoteResp, err := client.GetLoopInQuote(ctxb, quoteReq)
if err != nil {
return err
Expand All @@ -98,10 +126,36 @@ func quoteIn(ctx *cli.Context) error {
"amount.\n")
}

// If the user specified static address deposits, we quoted for their
// total value and need to display that value instead of the manually
// selected one.
if manualAmt == 0 {
quoteReq.Amt = int64(depositAmt)
}
printQuoteInResp(quoteReq, quoteResp, ctx.Bool("verbose"))
return nil
}

func depositAmount(ctx context.Context, client looprpc.SwapClientClient,
depositOutpoints []string) (btcutil.Amount, error) {

addressSummary, err := client.ListStaticAddressDeposits(
ctx, &looprpc.ListStaticAddressDepositsRequest{
Outpoints: depositOutpoints,
},
)
if err != nil {
return 0, err
}

var depositAmt btcutil.Amount
for _, deposit := range addressSummary.FilteredDeposits {
depositAmt += btcutil.Amount(deposit.Value)
}

return depositAmt, nil
}

var quoteOutCommand = cli.Command{
Name: "out",
Usage: "get a quote for the cost of a loop out swap",
Expand Down Expand Up @@ -174,7 +228,11 @@ func printQuoteInResp(req *looprpc.QuoteRequest,

totalFee := resp.HtlcPublishFeeSat + resp.SwapFeeSat

fmt.Printf(satAmtFmt, "Send on-chain:", req.Amt)
if req.DepositOutpoints != nil {
fmt.Printf(satAmtFmt, "Previously deposited on-chain:", req.Amt)
} else {
fmt.Printf(satAmtFmt, "Send on-chain:", req.Amt)
}
fmt.Printf(satAmtFmt, "Receive off-chain:", req.Amt-totalFee)

switch {
Expand Down
Loading
Loading