-
Notifications
You must be signed in to change notification settings - Fork 2
/
fees.go
58 lines (51 loc) · 1.61 KB
/
fees.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package libwallet
import (
"github.com/btcsuite/btcutil"
"github.com/muun/libwallet/fees"
)
type BestRouteFees struct {
MaxCapacity int64
FeeProportionalMillionth int64
FeeBase int64
}
type BestRouteFeesList struct {
list []fees.BestRouteFees
}
func (l *BestRouteFeesList) Add(f *BestRouteFees) {
l.list = append(l.list, fees.BestRouteFees{
MaxCapacity: btcutil.Amount(f.MaxCapacity),
FeeProportionalMillionth: uint64(f.FeeProportionalMillionth),
FeeBase: btcutil.Amount(f.FeeBase),
})
}
type FundingOutputPolicies struct {
MaximumDebt int64
PotentialCollect int64
MaxAmountFor0Conf int64
}
type SwapFees struct {
RoutingFee int64
SweepFee int64 // TODO: this should be called outputPadding, keeping name for retrocompat for now
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),
},
false,
)
return &SwapFees{
RoutingFee: int64(swapFees.RoutingFee),
SweepFee: int64(swapFees.OutputPadding),
DebtType: string(swapFees.DebtType),
DebtAmount: int64(swapFees.DebtAmount),
ConfirmationsNeeded: int64(swapFees.ConfirmationsNeeded),
}
}