2020-11-09 10:05:29 -03:00
|
|
|
package libwallet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/btcsuite/btcutil"
|
|
|
|
"github.com/muun/libwallet/fees"
|
|
|
|
)
|
|
|
|
|
|
|
|
type BestRouteFees struct {
|
2021-11-12 19:06:13 -03:00
|
|
|
MaxCapacity int64
|
2020-11-09 10:05:29 -03:00
|
|
|
FeeProportionalMillionth int64
|
2021-11-12 19:06:13 -03:00
|
|
|
FeeBase int64
|
2020-11-09 10:05:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
type BestRouteFeesList struct {
|
|
|
|
list []fees.BestRouteFees
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *BestRouteFeesList) Add(f *BestRouteFees) {
|
|
|
|
l.list = append(l.list, fees.BestRouteFees{
|
2021-11-12 19:06:13 -03:00
|
|
|
MaxCapacity: btcutil.Amount(f.MaxCapacity),
|
2020-11-09 10:05:29 -03:00
|
|
|
FeeProportionalMillionth: uint64(f.FeeProportionalMillionth),
|
2021-11-12 19:06:13 -03:00
|
|
|
FeeBase: btcutil.Amount(f.FeeBase),
|
2020-11-09 10:05:29 -03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type FundingOutputPolicies struct {
|
|
|
|
MaximumDebt int64
|
|
|
|
PotentialCollect int64
|
|
|
|
MaxAmountFor0Conf int64
|
|
|
|
}
|
|
|
|
|
|
|
|
type SwapFees struct {
|
|
|
|
RoutingFee int64
|
2021-11-12 19:06:13 -03:00
|
|
|
SweepFee int64 // TODO: this should be called outputPadding, keeping name for retrocompat for now
|
2020-11-09 10:05:29 -03:00
|
|
|
DebtType string
|
|
|
|
DebtAmount int64
|
|
|
|
ConfirmationsNeeded int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func ComputeSwapFees(amount int64, bestRouteFees *BestRouteFeesList, policies *FundingOutputPolicies) *SwapFees {
|
|
|
|
swapFees := fees.ComputeSwapFees(
|
|
|
|
btcutil.Amount(amount),
|
|
|
|
bestRouteFees.list,
|
|
|
|
&fees.FundingOutputPolicies{
|
|
|
|
MaximumDebt: btcutil.Amount(policies.MaximumDebt),
|
|
|
|
PotentialCollect: btcutil.Amount(policies.PotentialCollect),
|
|
|
|
MaxAmountFor0Conf: btcutil.Amount(policies.MaxAmountFor0Conf),
|
|
|
|
},
|
2021-11-12 19:06:13 -03:00
|
|
|
false,
|
2020-11-09 10:05:29 -03:00
|
|
|
)
|
|
|
|
return &SwapFees{
|
|
|
|
RoutingFee: int64(swapFees.RoutingFee),
|
2021-11-12 19:06:13 -03:00
|
|
|
SweepFee: int64(swapFees.OutputPadding),
|
2020-11-09 10:05:29 -03:00
|
|
|
DebtType: string(swapFees.DebtType),
|
|
|
|
DebtAmount: int64(swapFees.DebtAmount),
|
|
|
|
ConfirmationsNeeded: int64(swapFees.ConfirmationsNeeded),
|
|
|
|
}
|
|
|
|
}
|