mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-18 14:24:19 +01:00
Merge remote-tracking branch 'origin/dart-examples-lsp-fiat-fee' into python-examples
This commit is contained in:
@@ -290,26 +290,43 @@ result, err := sdkServices.Refund(refundable.BitcoinAddress, destinationAddress,
|
|||||||
<div slot="title">Dart</div>
|
<div slot="title">Dart</div>
|
||||||
<section>
|
<section>
|
||||||
|
|
||||||
|
To calculate fees, you'll need to detect if channel opening fees are needed first and then calculate the fee for the amount you'll be receiving.
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
int calculateChannelOpeningFee(int amountSats) {
|
int calculateChannelOpeningFee(int amountSats) async {
|
||||||
|
bool isChannelOpeningFeeNeeded = await isChannelOpeningFeeNeeded(amountSats);
|
||||||
|
return isChannelOpeningFeeNeeded ? calculateFeesForAmount(amountSats) : 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
How to detect if open channel fees are needed.
|
||||||
|
|
||||||
|
```dart
|
||||||
|
bool isChannelOpeningFeeNeeded(int amountSats) async {
|
||||||
NodeState? nodeState = await getNodeState();
|
NodeState? nodeState = await getNodeState();
|
||||||
int liquidity = nodeState.inboundLiquidityMsats ~/ 1000;
|
int liquidity = nodeState.inboundLiquidityMsats ~/ 1000;
|
||||||
// Check if we need to open channel
|
// Check if we need to open channel
|
||||||
if(amountSats >= liquidity) {
|
return amountSats >= liquidity;
|
||||||
// We need to open channel so we are calculating the fees for the LSP
|
}
|
||||||
String? lspId = await getLspId();
|
```
|
||||||
LSPInformation? lspInformation = await fetchLspInfo(lspId!);
|
|
||||||
|
|
||||||
// setupFee is the proportional fee charged based on the amount
|
|
||||||
int setupFee = (lspInformation.channelFeePermyriad / 100);
|
|
||||||
// minFee is the minimum fee required by the LSP to open a channeş
|
|
||||||
int minFee = lspInfo.channelMinimumFeeMsat ~/ 1000;
|
|
||||||
// A setup fee of {setupFee}% with a minimum of {minFee} will be applied for sending more than {liquidity}.
|
|
||||||
|
|
||||||
int channelFeesMsat = (amountSats * setupFee ~/ 100);
|
How to calculate the fee for a specific amount.
|
||||||
// If the proportional fee is smaller than minimum fees, minimum fees is selected.
|
|
||||||
return max(channelFeesMsat, minFee);
|
```dart
|
||||||
}
|
int calculateFeesForAmount(int amountSats) async {
|
||||||
|
// We need to open channel so we are calculating the fees for the LSP
|
||||||
|
String? lspId = await getLspId();
|
||||||
|
LSPInformation? lspInformation = await fetchLspInfo(lspId!);
|
||||||
|
|
||||||
|
// setupFee is the proportional fee charged based on the amount
|
||||||
|
int setupFee = (lspInformation.channelFeePermyriad / 100);
|
||||||
|
// minFee is the minimum fee required by the LSP to open a channeş
|
||||||
|
int minFee = lspInfo.channelMinimumFeeMsat ~/ 1000;
|
||||||
|
// A setup fee of {setupFee}% with a minimum of {minFee} will be applied for sending more than {liquidity}.
|
||||||
|
|
||||||
|
int channelFeesMsat = (amountSats * setupFee ~/ 100);
|
||||||
|
// If the proportional fee is smaller than minimum fees, minimum fees is selected.
|
||||||
|
return max(channelFeesMsat, minFee);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
Reference in New Issue
Block a user