@@ -136,59 +136,65 @@ func getMaxRoutingFee(amt btcutil.Amount) btcutil.Amount {
136136 return swap .CalcFee (amt , maxRoutingFeeBase , maxRoutingFeeRate )
137137}
138138
139- type limits struct {
140- maxSwapRoutingFee * btcutil.Amount
141- maxPrepayRoutingFee * btcutil.Amount
139+ type inLimits struct {
140+ maxMinerFee btcutil.Amount
141+ maxSwapFee btcutil.Amount
142+ }
143+
144+ func getInLimits (quote * looprpc.InQuoteResponse ) * inLimits {
145+ return & inLimits {
146+ // Apply a multiplier to the estimated miner fee, to not get
147+ // the swap canceled because fees increased in the mean time.
148+ maxMinerFee : btcutil .Amount (quote .HtlcPublishFeeSat ) * 3 ,
149+ maxSwapFee : btcutil .Amount (quote .SwapFeeSat ),
150+ }
151+ }
152+
153+ type outLimits struct {
154+ maxSwapRoutingFee btcutil.Amount
155+ maxPrepayRoutingFee btcutil.Amount
142156 maxMinerFee btcutil.Amount
143157 maxSwapFee btcutil.Amount
144- maxPrepayAmt * btcutil.Amount
158+ maxPrepayAmt btcutil.Amount
145159}
146160
147- func getLimits (amt btcutil.Amount , quote * looprpc.QuoteResponse ) * limits {
161+ func getOutLimits (amt btcutil.Amount ,
162+ quote * looprpc.OutQuoteResponse ) * outLimits {
163+
148164 maxSwapRoutingFee := getMaxRoutingFee (amt )
149165 maxPrepayRoutingFee := getMaxRoutingFee (btcutil .Amount (
150- quote .PrepayAmt ,
166+ quote .PrepayAmtSat ,
151167 ))
152- maxPrepayAmt := btcutil .Amount (quote .PrepayAmt )
168+ maxPrepayAmt := btcutil .Amount (quote .PrepayAmtSat )
153169
154- return & limits {
155- maxSwapRoutingFee : & maxSwapRoutingFee ,
156- maxPrepayRoutingFee : & maxPrepayRoutingFee ,
170+ return & outLimits {
171+ maxSwapRoutingFee : maxSwapRoutingFee ,
172+ maxPrepayRoutingFee : maxPrepayRoutingFee ,
157173
158174 // Apply a multiplier to the estimated miner fee, to not get
159175 // the swap canceled because fees increased in the mean time.
160- maxMinerFee : btcutil .Amount (quote .MinerFee ) * 100 ,
176+ maxMinerFee : btcutil .Amount (quote .HtlcSweepFeeSat ) * 100 ,
161177
162- maxSwapFee : btcutil .Amount (quote .SwapFee ),
163- maxPrepayAmt : & maxPrepayAmt ,
178+ maxSwapFee : btcutil .Amount (quote .SwapFeeSat ),
179+ maxPrepayAmt : maxPrepayAmt ,
164180 }
165181}
166182
167- func displayLimits ( swapType swap. Type , amt , minerFees btcutil.Amount , l * limits ,
168- externalHtlc bool , warning string ) error {
183+ func displayInLimits ( amt , minerFees btcutil.Amount , l * inLimits ,
184+ externalHtlc bool ) error {
169185
170186 totalSuccessMax := l .maxMinerFee + l .maxSwapFee
171- if l .maxSwapRoutingFee != nil {
172- totalSuccessMax += * l .maxSwapRoutingFee
173- }
174- if l .maxPrepayRoutingFee != nil {
175- totalSuccessMax += * l .maxPrepayRoutingFee
176- }
177187
178- if swapType == swap . TypeIn && externalHtlc {
188+ if externalHtlc {
179189 fmt .Printf ("On-chain fee for external loop in is not " +
180190 "included.\n Sufficient fees will need to be paid " +
181191 "when constructing the transaction in the external " +
182192 "wallet.\n \n " )
183193 }
184194
185- fmt .Printf ("Max swap fees for %d sat Loop %v: %d sat\n " , amt , swapType ,
195+ fmt .Printf ("Max swap fees for %d sat Loop %v: %d sat\n " , amt , swap . TypeIn ,
186196 totalSuccessMax )
187197
188- if warning != "" {
189- fmt .Println (warning )
190- }
191-
192198 fmt .Printf ("CONTINUE SWAP? (y/n), expand fee detail (x): " )
193199
194200 var answer string
@@ -201,32 +207,55 @@ func displayLimits(swapType swap.Type, amt, minerFees btcutil.Amount, l *limits,
201207 fmt .Println ()
202208 f := "%-36s %d sat\n "
203209
204- switch swapType {
205- case swap .TypeOut :
206- fmt .Printf (f , "Estimated on-chain sweep fee:" ,
210+ if ! externalHtlc {
211+ fmt .Printf (f , "Estimated on-chain HTLC fee:" ,
207212 minerFees )
208- fmt .Printf (f , "Max on-chain sweep fee:" , l .maxMinerFee )
209-
210- case swap .TypeIn :
211- if ! externalHtlc {
212- fmt .Printf (f , "Estimated on-chain HTLC fee:" ,
213- minerFees )
214- }
215213 }
216214
217- if l .maxSwapRoutingFee != nil {
218- fmt .Printf (f , "Max off-chain swap routing fee:" ,
219- * l .maxSwapRoutingFee )
220- }
215+ fmt .Printf (f , "Max swap fee:" , l .maxSwapFee )
221216
222- if l .maxPrepayAmt != nil {
223- fmt .Printf (f , "Max no show penalty (prepay):" ,
224- * l .maxPrepayAmt )
225- }
226- if l .maxPrepayRoutingFee != nil {
227- fmt .Printf (f , "Max off-chain prepay routing fee:" ,
228- * l .maxPrepayRoutingFee )
217+ fmt .Printf ("CONTINUE SWAP? (y/n): " )
218+ fmt .Scanln (& answer )
219+ if answer == "y" {
220+ return nil
229221 }
222+ }
223+
224+ return errors .New ("swap canceled" )
225+ }
226+
227+ func displayOutLimits (amt , minerFees btcutil.Amount , l * outLimits ,
228+ warning string ) error {
229+
230+ totalSuccessMax := l .maxMinerFee + l .maxSwapFee + l .maxSwapRoutingFee +
231+ l .maxPrepayRoutingFee
232+
233+ fmt .Printf ("Max swap fees for %d sat Loop %v: %d sat\n " , amt , swap .TypeOut ,
234+ totalSuccessMax )
235+
236+ if warning != "" {
237+ fmt .Println (warning )
238+ }
239+
240+ fmt .Printf ("CONTINUE SWAP? (y/n), expand fee detail (x): " )
241+
242+ var answer string
243+ fmt .Scanln (& answer )
244+
245+ switch answer {
246+ case "y" :
247+ return nil
248+ case "x" :
249+ fmt .Println ()
250+ f := "%-36s %d sat\n "
251+
252+ fmt .Printf (f , "Estimated on-chain sweep fee:" , minerFees )
253+ fmt .Printf (f , "Max on-chain sweep fee:" , l .maxMinerFee )
254+ fmt .Printf (f , "Max off-chain swap routing fee:" ,
255+ l .maxSwapRoutingFee )
256+ fmt .Printf (f , "Max no show penalty (prepay):" , l .maxPrepayAmt )
257+ fmt .Printf (f , "Max off-chain prepay routing fee:" ,
258+ l .maxPrepayRoutingFee )
230259 fmt .Printf (f , "Max swap fee:" , l .maxSwapFee )
231260
232261 fmt .Printf ("CONTINUE SWAP? (y/n): " )
0 commit comments