Update minimum swap mining fee to 2 Sats/vbyte

This commit is contained in:
Reckless_Satoshi 2023-02-13 05:57:00 -08:00
parent 1c696beb5d
commit 6ef62a1fa4
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
3 changed files with 46 additions and 21 deletions

View File

@ -566,12 +566,12 @@ class Logics:
"mining_fee_rate"
]
# Hardcap mining fee suggested at 50 sats/vbyte
if suggested_mining_fee_rate > 50:
suggested_mining_fee_rate = 50
# Hardcap mining fee suggested at 100 sats/vbyte
if suggested_mining_fee_rate > 100:
suggested_mining_fee_rate = 100
onchain_payment.suggested_mining_fee_rate = max(
1.05, LNNode.estimate_fee(amount_sats=preliminary_amount)["mining_fee_rate"]
2.05, LNNode.estimate_fee(amount_sats=preliminary_amount)["mining_fee_rate"]
)
onchain_payment.swap_fee_rate = cls.compute_swap_fee_rate(
onchain_payment.balance
@ -688,13 +688,13 @@ class Logics:
if mining_fee_rate:
# not a valid mining fee
if float(mining_fee_rate) < 1:
if float(mining_fee_rate) < 2:
return False, {
"bad_address": "The mining fee is too low, must be higher than 1 Sat/vbyte"
"bad_address": "The mining fee is too low, must be higher than 2 Sat/vbyte"
}
elif float(mining_fee_rate) > 50:
elif float(mining_fee_rate) > 100:
return False, {
"bad_address": "The mining fee is too high, must be less than 50 Sats/vbyte"
"bad_address": "The mining fee is too high, must be less than 100 Sats/vbyte"
}
order.payout_tx.mining_fee_rate = float(mining_fee_rate)
# If not mining ee provider use backend's suggested fee rate
@ -703,7 +703,7 @@ class Logics:
tx = order.payout_tx
tx.address = address
tx.mining_fee_sats = int(tx.mining_fee_rate * 141)
tx.mining_fee_sats = int(tx.mining_fee_rate * 200)
tx.num_satoshis = cls.payout_amount(order, user)[1]["invoice_amount"]
tx.sent_satoshis = int(
float(tx.num_satoshis)
@ -1738,10 +1738,19 @@ class Logics:
)
if not order.is_swap:
platform_summary["routing_budget_sats"] = order.payout.routing_budget_sats
# Start Deprecated after v0.3.1
platform_summary["routing_fee_sats"] = order.payout.fee
# End Deprecated after v0.3.1
platform_summary["trade_revenue_sats"] = int(
order.trade_escrow.num_satoshis
- order.payout.num_satoshis
- order.payout.routing_budget_sats
# Start Deprecated after v0.3.1 (will be `- order.payout.routing_budget_sats`)
- (
order.payout.fee
if order.payout.routing_budget_sats == 0
else order.payout.routing_budget_sats
)
# End Deprecated after v0.3.1
)
else:
platform_summary["routing_fee_sats"] = 0

View File

@ -227,10 +227,20 @@ class OnchainPayment(models.Model):
)
# fee in sats/vbyte with mSats decimals fee_msat
suggested_mining_fee_rate = models.DecimalField(
max_digits=6, decimal_places=3, default=1.05, null=False, blank=False
max_digits=6,
decimal_places=3,
default=2.05,
null=False,
blank=False,
validators=[MinValueValidator(1), MaxValueValidator(999)],
)
mining_fee_rate = models.DecimalField(
max_digits=6, decimal_places=3, default=1.05, null=False, blank=False
max_digits=6,
decimal_places=3,
default=2.05,
null=False,
blank=False,
validators=[MinValueValidator(1), MaxValueValidator(999)],
)
mining_fee_sats = models.PositiveBigIntegerField(default=0, null=False, blank=False)

View File

@ -2,7 +2,6 @@ import React, { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { Grid, Typography, TextField, List, Divider, ListItemText, ListItem } from '@mui/material';
import { Order } from '../../../models';
import WalletsButton from '../WalletsButton';
import { LoadingButton } from '@mui/lab';
import { pn } from '../../../utils';
@ -35,8 +34,15 @@ export const OnchainPayoutForm = ({
}: OnchainPayoutFormProps): JSX.Element => {
const { t } = useTranslation();
const invalidFee = onchain.miningFee < 1 || onchain.miningFee > 50;
const costPerVByte = 141;
const minMiningFee = 2;
const maxMiningFee = 100;
const invalidFee = onchain.miningFee < minMiningFee || onchain.miningFee > maxMiningFee;
const costPerVByte = 200;
const handleMiningFeeChange = (e) => {
const miningFee = Number(e.target.value);
setOnchain({ ...onchain, miningFee });
};
useEffect(() => {
setOnchain({ ...onchain, miningFee: order.suggested_mining_fee_rate });
@ -76,9 +82,9 @@ export const OnchainPayoutForm = ({
<ListItem>
<ListItemText
primary={
pn(Math.floor(Math.max(1, onchain.miningFee) * costPerVByte)) +
pn(Math.floor(Math.max(minMiningFee, onchain.miningFee) * costPerVByte)) +
' Sats (' +
Math.max(1, onchain.miningFee) +
Math.max(minMiningFee, onchain.miningFee) +
' Sats/vByte)'
}
secondary={t('Mining fee')}
@ -94,7 +100,7 @@ export const OnchainPayoutForm = ({
{pn(
Math.floor(
order.invoice_amount -
Math.max(1, onchain.miningFee) * costPerVByte -
Math.max(minMiningFee, onchain.miningFee) * costPerVByte -
(order.invoice_amount * order.swap_fee_rate) / 100,
),
) + ' Sats'}
@ -131,11 +137,11 @@ export const OnchainPayoutForm = ({
value={onchain.miningFee}
type='number'
inputProps={{
max: 50,
min: 1,
max: maxMiningFee,
min: minMiningFee,
style: { textAlign: 'center' },
}}
onChange={(e) => setOnchain({ ...onchain, miningFee: Number(e.target.value) })}
onChange={handleMiningFeeChange}
/>
</Grid>
</Grid>