@@ -223,6 +223,27 @@ func (f *FeeCategoryLimit) loopOutLimits(amount btcutil.Amount,
223223 return nil
224224}
225225
226+ func (f * FeeCategoryLimit ) loopInLimits (amount btcutil.Amount ,
227+ quote * loop.LoopInQuote ) error {
228+
229+ maxServerFee := ppmToSat (amount , f .MaximumSwapFeePPM )
230+ if quote .SwapFee > maxServerFee {
231+ log .Debugf ("quoted swap fee: %v > maximum swap fee: %v" ,
232+ quote .SwapFee , maxServerFee )
233+
234+ return newReasonError (ReasonSwapFee )
235+ }
236+
237+ if quote .MinerFee > f .MaximumMinerFee {
238+ log .Debugf ("quoted miner fee: %v > maximum miner " +
239+ "fee: %v" , quote .MinerFee , f .MaximumMinerFee )
240+
241+ return newReasonError (ReasonMinerFee )
242+ }
243+
244+ return nil
245+ }
246+
226247// loopOutFees returns the prepay and routing and miner fees we are willing to
227248// pay for a loop out swap.
228249func (f * FeeCategoryLimit ) loopOutFees (amount btcutil.Amount ,
@@ -384,3 +405,42 @@ func splitOffChain(available, prepayAmt,
384405func scaleMinerFee (estimate btcutil.Amount ) btcutil.Amount {
385406 return estimate * btcutil .Amount (minerMultiplier )
386407}
408+
409+ func (f * FeePortion ) loopInLimits (amount btcutil.Amount ,
410+ quote * loop.LoopInQuote ) error {
411+
412+ // Calculate the total amount that this swap may spend in fees, as a
413+ // portion of the swap amount.
414+ totalFeeSpend := ppmToSat (amount , f .PartsPerMillion )
415+
416+ // Check individual fee components so that we can give more specific
417+ // feedback.
418+ if quote .MinerFee > totalFeeSpend {
419+ log .Debugf ("miner fee: %v greater than fee limit: %v, at " +
420+ "%v ppm" , quote .MinerFee , totalFeeSpend ,
421+ f .PartsPerMillion )
422+
423+ return newReasonError (ReasonMinerFee )
424+ }
425+
426+ if quote .SwapFee > totalFeeSpend {
427+ log .Debugf ("swap fee: %v greater than fee limit: %v, at " +
428+ "%v ppm" , quote .SwapFee , totalFeeSpend ,
429+ f .PartsPerMillion )
430+
431+ return newReasonError (ReasonSwapFee )
432+ }
433+
434+ fees := worstCaseInFees (
435+ quote .MinerFee , quote .SwapFee , defaultLoopInSweepFee ,
436+ )
437+
438+ if fees > totalFeeSpend {
439+ log .Debugf ("total fees for swap: %v > fee limit: %v, at " +
440+ "%v ppm" , fees , totalFeeSpend , f .PartsPerMillion )
441+
442+ return newReasonError (ReasonFeePPMInsufficient )
443+ }
444+
445+ return nil
446+ }
0 commit comments