@@ -136,59 +136,65 @@ func getMaxRoutingFee(amt btcutil.Amount) btcutil.Amount {
136
136
return swap .CalcFee (amt , maxRoutingFeeBase , maxRoutingFeeRate )
137
137
}
138
138
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
142
156
maxMinerFee btcutil.Amount
143
157
maxSwapFee btcutil.Amount
144
- maxPrepayAmt * btcutil.Amount
158
+ maxPrepayAmt btcutil.Amount
145
159
}
146
160
147
- func getLimits (amt btcutil.Amount , quote * looprpc.QuoteResponse ) * limits {
161
+ func getOutLimits (amt btcutil.Amount ,
162
+ quote * looprpc.OutQuoteResponse ) * outLimits {
163
+
148
164
maxSwapRoutingFee := getMaxRoutingFee (amt )
149
165
maxPrepayRoutingFee := getMaxRoutingFee (btcutil .Amount (
150
- quote .PrepayAmt ,
166
+ quote .PrepayAmtSat ,
151
167
))
152
- maxPrepayAmt := btcutil .Amount (quote .PrepayAmt )
168
+ maxPrepayAmt := btcutil .Amount (quote .PrepayAmtSat )
153
169
154
- return & limits {
155
- maxSwapRoutingFee : & maxSwapRoutingFee ,
156
- maxPrepayRoutingFee : & maxPrepayRoutingFee ,
170
+ return & outLimits {
171
+ maxSwapRoutingFee : maxSwapRoutingFee ,
172
+ maxPrepayRoutingFee : maxPrepayRoutingFee ,
157
173
158
174
// Apply a multiplier to the estimated miner fee, to not get
159
175
// the swap canceled because fees increased in the mean time.
160
- maxMinerFee : btcutil .Amount (quote .MinerFee ) * 100 ,
176
+ maxMinerFee : btcutil .Amount (quote .HtlcSweepFeeSat ) * 100 ,
161
177
162
- maxSwapFee : btcutil .Amount (quote .SwapFee ),
163
- maxPrepayAmt : & maxPrepayAmt ,
178
+ maxSwapFee : btcutil .Amount (quote .SwapFeeSat ),
179
+ maxPrepayAmt : maxPrepayAmt ,
164
180
}
165
181
}
166
182
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 {
169
185
170
186
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
- }
177
187
178
- if swapType == swap . TypeIn && externalHtlc {
188
+ if externalHtlc {
179
189
fmt .Printf ("On-chain fee for external loop in is not " +
180
190
"included.\n Sufficient fees will need to be paid " +
181
191
"when constructing the transaction in the external " +
182
192
"wallet.\n \n " )
183
193
}
184
194
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 ,
186
196
totalSuccessMax )
187
197
188
- if warning != "" {
189
- fmt .Println (warning )
190
- }
191
-
192
198
fmt .Printf ("CONTINUE SWAP? (y/n), expand fee detail (x): " )
193
199
194
200
var answer string
@@ -201,32 +207,55 @@ func displayLimits(swapType swap.Type, amt, minerFees btcutil.Amount, l *limits,
201
207
fmt .Println ()
202
208
f := "%-36s %d sat\n "
203
209
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:" ,
207
212
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
- }
215
213
}
216
214
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 )
221
216
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
229
221
}
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 )
230
259
fmt .Printf (f , "Max swap fee:" , l .maxSwapFee )
231
260
232
261
fmt .Printf ("CONTINUE SWAP? (y/n): " )
0 commit comments