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

Open
wants to merge 68 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
92f2d9f
sqlc: static address migrations, models, queries
hieblmi Nov 9, 2023
c9da71a
looprpc: static address creation
hieblmi Feb 14, 2024
a7cbcbd
log: static address sub logger
hieblmi Nov 9, 2023
7e22d20
loopdb: static address store
hieblmi Nov 9, 2023
8ed9cb7
staticaddr: static address manager
hieblmi Nov 9, 2023
5b9f050
staticaddr: static address server
hieblmi Feb 14, 2024
1fc8818
daemon: integrate static address manager and sql store
hieblmi Nov 9, 2023
cf53844
perms: static address creation permission
hieblmi Nov 9, 2023
b4e4ef8
loop: static address creation client command
hieblmi Nov 9, 2023
b6f8d4d
looprpc: list unspent static address
hieblmi Nov 9, 2023
8d13cf0
staticaddr: track and list spends in manager
hieblmi Oct 25, 2023
9551390
staticaddr: list unspent outputs in server
hieblmi Oct 25, 2023
4679230
perms: list unspent outputs
hieblmi Oct 25, 2023
c3fae72
loop: list unspent static address outputs
hieblmi Oct 25, 2023
fd63b62
looprpc: include static address in swap client
hieblmi Feb 26, 2024
2ec9c78
sqlc: deposit queries, models and migrations
hieblmi Mar 7, 2024
7f1e5d6
staticaddr: interfaces
hieblmi Mar 7, 2024
24e7b55
staticaddr: deposit logger
hieblmi Mar 7, 2024
6d449b5
staticaddr: deposit manager and fsm
hieblmi Mar 7, 2024
909ec27
staticaddr: deposits for server and daemon
hieblmi Mar 7, 2024
39f77fe
staticaddr: add swap client to cmd
hieblmi Mar 7, 2024
843ef4b
unit: manager tests
hieblmi Apr 23, 2024
d0d480a
staticaddr: public deposit method scope
hieblmi Apr 25, 2024
8e0c23a
sqlc: withdrawal address for deposits
hieblmi May 6, 2024
7487b90
looprpc: deposit withdrawal endpoint
hieblmi May 6, 2024
e2446ca
swapserverrpc: server withdrawal endpoint
hieblmi May 6, 2024
d460e5e
log: unified static address logger
hieblmi May 6, 2024
0a1f78b
staticaddr: address and deposit adjustments for withdrawals
hieblmi May 6, 2024
8bdade6
staticaddr: withdrawal manager and interface
hieblmi May 6, 2024
69cf9f1
loopd: static address withdrawals support
hieblmi May 6, 2024
1fd8238
loop: static address withdrawals support
hieblmi May 6, 2024
00f8d5f
looprpc: static address summary
hieblmi Jun 5, 2024
633ca67
staticaddr: expose static address to client summary
hieblmi Jun 5, 2024
ac4f9ba
loopd: static address summary
hieblmi Jun 5, 2024
b10a422
looprpc: deposit outpoints for QuoteRequest
hieblmi Jun 6, 2024
31750d5
swapserverrpc: number of deposits for ServerLoopInQuoteRequest
hieblmi Jun 6, 2024
2cd8145
loopd: quoting for static address loop-ins
hieblmi Jun 6, 2024
3482993
cmd: quote for static address loop-ins
hieblmi Jun 6, 2024
39963b2
swapserverrpc: static address loop-ins
hieblmi Nov 19, 2024
d2012e7
looprpc: static address loop-ins
hieblmi Nov 19, 2024
c724604
sqlc: loop-in tables and queries
hieblmi Jul 30, 2024
f773985
log: static address loop-in logging
hieblmi Jul 30, 2024
edf5f60
staticaddr: enable deposits for swaps
hieblmi Jul 30, 2024
fcff53b
loopin: public scope for ValidateLoopInContract
hieblmi Sep 26, 2024
fb1305e
interface: add StaticAddressLoopInRequest interface
hieblmi Sep 26, 2024
ea3c5e5
staticaddr: configurable max htlc tx fee
hieblmi Oct 17, 2024
e72d40b
staticaddr: loopin
hieblmi Oct 30, 2024
32690c5
staticaddr: sql_store
hieblmi Oct 30, 2024
22b22e0
staticaddr: swap manager and fsm
hieblmi Oct 24, 2024
bb5a6a5
unit: manager mocks for static address loop-in
hieblmi Jul 30, 2024
d8ec87d
loopd: static address loop-in support
hieblmi Jul 30, 2024
701b187
cmd: static address loop-in
hieblmi Jul 30, 2024
dc21d43
staticaddr: cmd listdeposits and listswaps
hieblmi Nov 5, 2024
b8698e2
staticaddr: separate file for rpc service
hieblmi Nov 5, 2024
5e30133
staticaddr: change min deposit confs from 3 to 6
hieblmi Nov 5, 2024
ad122d2
staticaddr: fix fsm logging
hieblmi Nov 5, 2024
023d593
swapserverrpc: add new functions
sputn1ck Nov 14, 2024
bdfc16d
notifications: add support for new ntfn
sputn1ck Nov 14, 2024
fc90aa0
staticaddr/sql_store: Add fetching loop in by hash
sputn1ck Nov 14, 2024
c0e9d7a
staticaddr/loopin: add listening for sweep request
sputn1ck Nov 14, 2024
f8862c7
staticaddr/loopin: update fsm for server ntfn sigs
sputn1ck Nov 14, 2024
f8599ba
loopd/staticaddr: add ntfn manager
sputn1ck Nov 14, 2024
c1f3f75
staticaddr/loopin: remove unused code
sputn1ck Nov 14, 2024
c2281b8
loopcli/staticaddr: explicit loop in command
sputn1ck Nov 18, 2024
6982adb
cmd/staticaddr: hide behind build flag
sputn1ck Nov 19, 2024
0d30733
looprpc: addr and fee rate for withdrawals
hieblmi Nov 29, 2024
fb9562b
staticaddr: dest addr and fee rate for withdrawals
hieblmi Nov 29, 2024
5b68e42
Merge pull request #859 from hieblmi/withdrawal-fee-and-address
hieblmi Nov 29, 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