mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-18 06:14:21 +01:00
Update Dart fees example
This commit is contained in:
@@ -410,20 +410,19 @@ 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:
|
To calculate the fees for a channel being opened by the LSP:
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
int calculateChannelOpeningFee(int amountSats) async {
|
int calculateChannelOpeningFee(int amountMsat) async {
|
||||||
bool isChannelOpeningFeeNeeded = await isChannelOpeningFeeNeeded(amountSats);
|
bool isChannelOpeningFeeNeeded = await isChannelOpeningFeeNeeded(amountMsat);
|
||||||
return isChannelOpeningFeeNeeded ? calculateFeesForAmount(amountSats) : 0;
|
return isChannelOpeningFeeNeeded ? calculateFeesForAmount(amountMsat) : 0;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
How to detect if open channel fees are needed:
|
How to detect if open channel fees are needed:
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
bool isChannelOpeningFeeNeeded(int amountSats) async {
|
// Assumes nodeState isn't empty
|
||||||
|
bool isChannelOpeningFeeNeeded(int amountMsat) async {
|
||||||
NodeState? nodeState = await getNodeState();
|
NodeState? nodeState = await getNodeState();
|
||||||
int liquidity = nodeState.inboundLiquidityMsats ~/ 1000;
|
return amountMsat >= nodeState.inboundLiquidityMsats;
|
||||||
// Check if we need to open channel.
|
|
||||||
return amountSats >= liquidity;
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -432,20 +431,14 @@ 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:
|
This information can be retrieved for each LSP and then calculated:
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
int calculateFeesForAmount(int amountSats) async {
|
// Assumes lspId & lspInformation isn't empty
|
||||||
// We need to open channel so we are calculating the fees for the LSP.
|
int calculateFeesForAmount(int amountMsat) async {
|
||||||
String? lspId = await getLspId();
|
String? lspId = await getLspId();
|
||||||
LSPInformation? lspInformation = await fetchLspInfo(lspId!);
|
LSPInformation? lspInformation = await fetchLspInfo(lspId);
|
||||||
|
|
||||||
// setupFee is the proportional fee charged based on the amount.
|
// We calculate the dynamic fees in millisatoshis rounded to satoshis.
|
||||||
int setupFee = (lspInformation.channelFeePermyriad / 100);
|
int channelFeesMsat = (amountMsat * lspInformation.channelFeePermyriad / 10000 / 1000 * 1000);
|
||||||
// minFee is the minimum fee required by the LSP to open a channel.
|
return max(channelFeesMsat, lspInformation.channelMinimumFeeMsat);
|
||||||
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