Merge remote-tracking branch 'origin/fee-examples'

This commit is contained in:
ruben beck
2023-07-13 20:56:15 +02:00

View File

@@ -346,10 +346,10 @@ When the amount to be received exceeds the inbound liquidity of the node, a new
To calculate the fees for a channel being opened by the LSP:
```swift
func calculateChannelOpeningFee(amountStats: Int64) -> Int64? {
var channelOpeningFeeNeeded = isChannelOpeningFeeNeeded(amountStats: amountStats)
func calculateChannelOpeningFee(amountMsats: Int64) -> Int64? {
var channelOpeningFeeNeeded = isChannelOpeningFeeNeeded(amountMsats: amountMsats)
if channelOpeningFeeNeeded {
return calculateFeesForAmount(amountStats: amountStats)
return calculateFeesForAmount(amountMsats: amountMsats)
}
return nil
}
@@ -357,14 +357,12 @@ func calculateChannelOpeningFee(amountStats: Int64) -> Int64? {
How to detect if open channel fees are needed:
```swift
func isChannelOpeningFeeNeeded(amountStats: Int64) -> Bool {
func isChannelOpeningFeeNeeded(amountMsats: Int64) -> Bool {
do {
let nodeInfo = try sdk.nodeInfo()
if var liqudity = nodeInfo?.inboundLiquidityMsats{
liqudity /= 1000
print(liqudity)
return amountStats >= liqudity
if let inboundLiquidityMsats = nodeInfo?.inboundLiquidityMsats {
return inboundLiquidityMsats <= amountMsats
}
} catch {
@@ -379,19 +377,16 @@ LSP fees are calculated in two ways, either by a minimum fee set by the LSP or b
This information can be retrieved for each LSP and then calculated:
```swift
func calculateFeesForAmount(amountStats: Int64) -> Int64? {
func calculateFeesForAmount(amountMsats: Int64) -> Int64? {
do {
if let lspId = try sdk.lspId() {
let lspInfo = try sdk.fetchLspInfo(lspId: lspId)
// setupFee is the proportional fee charged based on the amount.
let setupFee = lspInfo!.channelFeePermyriad / 100
// minFee is the minimum fee required by the LSP to open a channel.
let minFee = lspInfo!.channelMinimumFeeMsat / 1000
// We calculate the dynamic fees in millisatoshis rounded to satoshis.
let channelDynamicFeeMsat = amountMsats * lspInfo!.channelFeePermyriad / 10_000 / 1000 * 1000
let feeSat = max(lspInfo!.channelMinimumFeeMsat,channelDynamicFeeMsat)
// A setup fee of {setupFee}% with a minimum of {minFee} will be applied for sending more than {liquidity}.
let channelFeesMsat = amountStats * setupFee / 1000
return max(channelFeesMsat, minFee)
return feeSat
}
} catch {
// Handle error
@@ -452,11 +447,11 @@ When the amount to be received exceeds the inbound liquidity of the node, a new
To calculate the fees for a channel being opened by the LSP:
```python
def calculate_channel_opening_fees(amount_sats):
def calculate_channel_opening_fees(amount_msats):
is_channel_opening_fee_needed = is_channel_opening_fee_needed()
if is_channel_opening_fee_needed:
return calculate_fees_for_amount(amount_sats)
return calculate_fees_for_amount(amount_msats)
else:
return None
```
@@ -464,9 +459,8 @@ def calculate_channel_opening_fees(amount_sats):
How to detect if open channel fees are needed:
```python
def is_channel_opening_fee_needed(amount_sats):
liqudity = sdk_services.node_info().inbound_liquidity_msats // 1000
return amount_sats >= liqudity
def is_channel_opening_fee_needed(amount_msats):
return sdk_services.node_info().inbound_liquidity_msats <= amount_msats
```
LSP fees are calculated in two ways, either by a minimum fee set by the LSP or by a fee per myriad calculated based on the amount being received. If the fee calculated from the fee per myriad is less than the minimum fee, the minimum fee is used.
@@ -474,21 +468,17 @@ LSP fees are calculated in two ways, either by a minimum fee set by the LSP or b
This information can be retrieved for each LSP and then calculated:
```python
def calculate_fees_for_amount(amount_sats):
def calculate_fees_for_amount(amount_msats):
# We need to open channel so we are calculating the fees for the LSP.
lsp_id = sdk_services.lsp_id()
lsp_info = sdk_services.fetch_lsp_info()
# setup_fee is the proportional fee charged based on the amount.
setup_fee = lsp_info.channel_fee_permyriad / 100
# We calculate the dynamic fees in millisatoshis rounded to satoshis.
channel_dynamic_fee = amount_msats * lsp_info.channel_minimum_fee_msat * lsp_info.channel_fee_permyriad / 10000 // 10000 * 10000
# min_fee is the minimum fee required by the LSP to open a channel.
min_fee = lsp_info.channel_minimum_fee_msat // 1000
fee_sat = max(lsp_info.channel_minimum_fee_msat, channel_dynamic_fee)
# A setup fee of {setup_fee} with a minimum of {min_fee} will be applied for sending more than {liquidity}.
channel_fee_msat = amount_sats * setup_fee // 1000
return max(channel_fee_msat, min_fee)
return fee_sat
```
</section>
@@ -500,24 +490,23 @@ When the amount to be received exceeds the inbound liquidity of the node, a new
To calculate the fees for a channel being opened by the LSP:
```go
func CalculateChannelOpeningFee(amountSats uint64) (uint64, error) {
isChannelOpeningFeeNeeded := isChannelOpeningFeeNeeded(amountSats)
func CalculateChannelOpeningFee(amountMsats uint64) (uint64, error) {
isChannelOpeningFeeNeeded := isChannelOpeningFeeNeeded(amountMsats)
if !isChannelOpeningFeeNeeded {
return 0, fmt.Errorf("Channel not needed")
}
return calculateFeesForAmount(amountSats), nil
return calculateFeesForAmount(amountMsats), nil
}
```
How to detect if open channel fees are needed:
```go
func isChannelOpeningFeeNeeded(amountSats uint64) bool {
func isChannelOpeningFeeNeeded(amountMsats uint64) bool {
nodeInfo, err := sdkServices.NodeInfo()
if err != nil {
// Handle error
}
liqudity := nodeInfo.InboundLiquidityMsats / 1000
return amountSats >= liqudity
return nodeInfo.InboundLiquidityMsats <= amountMsats
}
```
@@ -526,28 +515,25 @@ LSP fees are calculated in two ways, either by a minimum fee set by the LSP or b
This information can be retrieved for each LSP and then calculated:
```go
func calculateFeesForAmount(amountSats uint64) uint64 {
// We need to open channel so we are calculating the fees for the LSP
func calculateFeesForAmount(amountMsats uint64) uint64 {
lspId, err := sdkServices.LspId()
if err != nil {
// Handle error
log.Printf("received error %#v", err)
}
lspInfo, err := sdkServices.FetchLspInfo(*lspId)
if err != nil {
// Handle error
log.Printf("received error %#v", err)
}
// setupFee is the proportional fee charged based on the amount
setupFee := lspInfo.ChannelMinimumFeeMsat / 1000
// We calculate the dynamic fees in millisatoshis rounded to satoshis
channelDynamicFeeMSat := amountMsats * uint64(lspInfo.ChannelFeePermyriad) / 10000 / 1000 * 1000
// minFee is the minimum fee required by the LSP to open a channel.
minFee := lspInfo.ChannelMinimumFeeMsat / 1000
// A setup fee of {setupFee}% with a minimum of {minFee} will be applied for sending more than {liquidity}.
channelFeeMSat := amountSats * uint64(setupFee) / 1000
if channelFeeMSat > uint64(minFee) {
return channelFeeMSat
var feeSat uint64
if channelDynamicFeeMSat >= uint64(lspInfo.ChannelMinimumFeeMsat) {
feeSat = channelDynamicFeeMSat
} else {
feeSat = uint64(lspInfo.ChannelMinimumFeeMsat)
}
return uint64(minFee)
return uint64(feeSat)
}
```