55
55
56
56
57
57
58
- CLAIM_FEE_SIZE = 136
59
- LOCKUP_FEE_SIZE = 153 # assuming 1 output, 2 outputs
58
+ SWAP_TX_SIZE = 150 # default tx size, used for mining fee estimation
60
59
61
60
MIN_LOCKTIME_DELTA = 60
62
61
LOCKTIME_DELTA_REFUND = 70
@@ -130,9 +129,7 @@ def now():
130
129
@attr .s
131
130
class SwapFees :
132
131
percentage = attr .ib (type = int )
133
- normal_fee = attr .ib (type = int )
134
- lockup_fee = attr .ib (type = int )
135
- claim_fee = attr .ib (type = int )
132
+ mining_fee = attr .ib (type = int )
136
133
min_amount = attr .ib (type = int )
137
134
max_amount = attr .ib (type = int )
138
135
@@ -176,7 +173,7 @@ def create_claim_tx(
176
173
"""
177
174
# FIXME the mining fee should depend on swap.is_reverse.
178
175
# the txs are not the same size...
179
- amount_sat = txin .value_sats () - SwapManager ._get_fee (size = CLAIM_FEE_SIZE , config = config )
176
+ amount_sat = txin .value_sats () - SwapManager ._get_fee (size = SWAP_TX_SIZE , config = config )
180
177
if amount_sat < dust_threshold ():
181
178
raise BelowDustLimit ()
182
179
txin , locktime = SwapManager .create_claim_txin (txin = txin , swap = swap , config = config )
@@ -196,9 +193,7 @@ class SwapManager(Logger):
196
193
197
194
def __init__ (self , * , wallet : 'Abstract_Wallet' , lnworker : 'LNWallet' ):
198
195
Logger .__init__ (self )
199
- self .normal_fee = None
200
- self .lockup_fee = None
201
- self .claim_fee = None # part of the boltz prococol, not used by Electrum
196
+ self .mining_fee = None
202
197
self .percentage = None
203
198
self ._min_amount = None
204
199
self ._max_amount = None
@@ -417,7 +412,7 @@ async def _claim_swap(self, swap: SwapData) -> None:
417
412
else :
418
413
claim_tx .add_info_from_wallet (self .wallet )
419
414
claim_tx_fee = claim_tx .get_fee ()
420
- recommended_fee = self .get_claim_fee ()
415
+ recommended_fee = self .get_swap_tx_fee ()
421
416
if claim_tx_fee * 1.1 < recommended_fee :
422
417
should_bump_fee = True
423
418
self .logger .info (f'claim tx fee too low { claim_tx_fee } < { recommended_fee } . we will bump the fee' )
@@ -465,8 +460,8 @@ async def _claim_swap(self, swap: SwapData) -> None:
465
460
except TxBroadcastError :
466
461
self .logger .info (f'error broadcasting claim tx { txin .spent_txid } ' )
467
462
468
- def get_claim_fee (self ):
469
- return self .get_fee (CLAIM_FEE_SIZE )
463
+ def get_swap_tx_fee (self ):
464
+ return self .get_fee (SWAP_TX_SIZE )
470
465
471
466
def get_fee (self , size ):
472
467
# note: 'size' is in vbytes
@@ -546,7 +541,7 @@ def add_normal_swap(
546
541
) -> Tuple [SwapData , str , Optional [str ]]:
547
542
"""creates a hold invoice"""
548
543
if prepay :
549
- prepay_amount_sat = self .get_claim_fee () * 2
544
+ prepay_amount_sat = self .get_swap_tx_fee () * 2
550
545
invoice_amount_sat = lightning_amount_sat - prepay_amount_sat
551
546
else :
552
547
invoice_amount_sat = lightning_amount_sat
@@ -965,15 +960,11 @@ def server_update_pairs(self) -> None:
965
960
self .percentage = float (self .config .SWAPSERVER_FEE_MILLIONTHS ) / 10000
966
961
self ._min_amount = 20000
967
962
self ._max_amount = 10000000
968
- self .normal_fee = self .get_fee (CLAIM_FEE_SIZE )
969
- self .lockup_fee = self .get_fee (LOCKUP_FEE_SIZE )
970
- self .claim_fee = self .get_fee (CLAIM_FEE_SIZE )
963
+ self .mining_fee = self .get_fee (SWAP_TX_SIZE )
971
964
972
965
def update_pairs (self , pairs ):
973
966
self .logger .info (f'updating fees { pairs } ' )
974
- self .normal_fee = pairs .normal_fee
975
- self .lockup_fee = pairs .lockup_fee
976
- self .claim_fee = pairs .claim_fee
967
+ self .mining_fee = pairs .mining_fee
977
968
self .percentage = pairs .percentage
978
969
self ._min_amount = pairs .min_amount
979
970
self ._max_amount = pairs .max_amount
@@ -1006,13 +997,13 @@ def _get_recv_amount(self, send_amount: Optional[int], *, is_reverse: bool) -> O
1006
997
# see/ref:
1007
998
# https://github.com/BoltzExchange/boltz-backend/blob/e7e2d30f42a5bea3665b164feb85f84c64d86658/lib/service/Service.ts#L948
1008
999
percentage_fee = math .ceil (percentage * x / 100 )
1009
- base_fee = self .lockup_fee
1000
+ base_fee = self .mining_fee
1010
1001
x -= percentage_fee + base_fee
1011
1002
x = math .floor (x )
1012
1003
if x < dust_threshold ():
1013
1004
return
1014
1005
else :
1015
- x -= self .normal_fee
1006
+ x -= self .mining_fee
1016
1007
percentage_fee = math .ceil (x * percentage / (100 + percentage ))
1017
1008
x -= percentage_fee
1018
1009
if not self .check_invoice_amount (x ):
@@ -1034,7 +1025,7 @@ def _get_send_amount(self, recv_amount: Optional[int], *, is_reverse: bool) -> O
1034
1025
# see/ref:
1035
1026
# https://github.com/BoltzExchange/boltz-backend/blob/e7e2d30f42a5bea3665b164feb85f84c64d86658/lib/service/Service.ts#L928
1036
1027
# https://github.com/BoltzExchange/boltz-backend/blob/e7e2d30f42a5bea3665b164feb85f84c64d86658/lib/service/Service.ts#L958
1037
- base_fee = self .lockup_fee
1028
+ base_fee = self .mining_fee
1038
1029
x += base_fee
1039
1030
x = math .ceil (x / ((100 - percentage ) / 100 ))
1040
1031
if not self .check_invoice_amount (x ):
@@ -1046,7 +1037,7 @@ def _get_send_amount(self, recv_amount: Optional[int], *, is_reverse: bool) -> O
1046
1037
# https://github.com/BoltzExchange/boltz-backend/blob/e7e2d30f42a5bea3665b164feb85f84c64d86658/lib/service/Service.ts#L708
1047
1038
# https://github.com/BoltzExchange/boltz-backend/blob/e7e2d30f42a5bea3665b164feb85f84c64d86658/lib/rates/FeeProvider.ts#L90
1048
1039
percentage_fee = math .ceil (percentage * x / 100 )
1049
- x += percentage_fee + self .normal_fee
1040
+ x += percentage_fee + self .mining_fee
1050
1041
x = int (x )
1051
1042
return x
1052
1043
@@ -1062,13 +1053,13 @@ def get_recv_amount(self, send_amount: Optional[int], *, is_reverse: bool) -> Op
1062
1053
f"send_amount={ send_amount } -> recv_amount={ recv_amount } -> inverted_send_amount={ inverted_send_amount } " )
1063
1054
# second, add on-chain claim tx fee
1064
1055
if is_reverse and recv_amount is not None :
1065
- recv_amount -= self .get_claim_fee ()
1056
+ recv_amount -= self .get_swap_tx_fee ()
1066
1057
return recv_amount
1067
1058
1068
1059
def get_send_amount (self , recv_amount : Optional [int ], * , is_reverse : bool ) -> Optional [int ]:
1069
1060
# first, add on-chain claim tx fee
1070
1061
if is_reverse and recv_amount is not None :
1071
- recv_amount += self .get_claim_fee ()
1062
+ recv_amount += self .get_swap_tx_fee ()
1072
1063
# second, add percentage fee
1073
1064
send_amount = self ._get_send_amount (recv_amount , is_reverse = is_reverse )
1074
1065
# sanity check calculation can be inverted
@@ -1310,9 +1301,7 @@ async def get_pairs(self) -> None:
1310
1301
limits = response ['pairs' ]['BTC/BTC' ]['limits' ]
1311
1302
pairs = SwapFees (
1312
1303
percentage = fees ['percentage' ],
1313
- normal_fee = fees ['minerFees' ]['baseAsset' ]['normal' ],
1314
- lockup_fee = fees ['minerFees' ]['baseAsset' ]['reverse' ]['lockup' ],
1315
- claim_fee = fees ['minerFees' ]['baseAsset' ]['reverse' ]['claim' ],
1304
+ mining_fee = fees ['minerFees' ]['baseAsset' ]['mining_fee' ],
1316
1305
min_amount = limits ['minimal' ],
1317
1306
max_amount = limits ['maximal' ],
1318
1307
)
@@ -1327,7 +1316,7 @@ class NostrTransport(SwapServerTransport):
1327
1316
1328
1317
NOSTR_DM = 4
1329
1318
USER_STATUS_NIP38 = 30315
1330
- NOSTR_EVENT_VERSION = 2
1319
+ NOSTR_EVENT_VERSION = 3
1331
1320
OFFER_UPDATE_INTERVAL_SEC = 60 * 10
1332
1321
1333
1322
def __init__ (self , config , sm , keypair ):
@@ -1407,9 +1396,7 @@ def get_recent_offers(self) -> Sequence[Dict]:
1407
1396
def _parse_offer (self , offer ):
1408
1397
return SwapFees (
1409
1398
percentage = offer ['percentage_fee' ],
1410
- normal_fee = offer ['normal_mining_fee' ],
1411
- lockup_fee = offer ['reverse_mining_fee' ],
1412
- claim_fee = offer ['claim_mining_fee' ],
1399
+ mining_fee = offer ['mining_fee' ],
1413
1400
min_amount = offer ['min_amount' ],
1414
1401
max_amount = offer ['max_amount' ],
1415
1402
)
@@ -1420,9 +1407,7 @@ async def publish_offer(self, sm):
1420
1407
assert self .sm .is_server
1421
1408
offer = {
1422
1409
'percentage_fee' : sm .percentage ,
1423
- 'normal_mining_fee' : sm .normal_fee ,
1424
- 'reverse_mining_fee' : sm .lockup_fee ,
1425
- 'claim_mining_fee' : sm .claim_fee ,
1410
+ 'mining_fee' : sm .mining_fee ,
1426
1411
'min_amount' : sm ._min_amount ,
1427
1412
'max_amount' : sm ._max_amount ,
1428
1413
'relays' : sm .config .NOSTR_RELAYS ,
@@ -1502,7 +1487,7 @@ async def receive_offers(self):
1502
1487
await self .taskgroup .spawn (self .rebroadcast_event (event , server_relays ))
1503
1488
1504
1489
async def get_pairs (self ):
1505
- if self .config .SWAPSERVER_NPUB is None :
1490
+ if not self .config .SWAPSERVER_NPUB :
1506
1491
return
1507
1492
query = {
1508
1493
"kinds" : [self .USER_STATUS_NIP38 ],
0 commit comments