Skip to content

Commit

Permalink
mint fix fee reserve msat
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Jan 16, 2024
1 parent a518274 commit 12e16f4
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 30 deletions.
24 changes: 12 additions & 12 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ MINT_PORT=3338
# use builtin tor, this overrides SOCKS_PROXY, HTTP_PROXY
TOR=TRUE

# use custom proxy, this will only work with TOR=false
#SOCKS_PROXY=socks5://localhost:9050
#HTTP_PROXY=http://localhost:8088
# Use custom proxy, this will only work with TOR=false
# SOCKS_PROXY=socks5://localhost:9050
# HTTP_PROXY=http://localhost:8088

# NOSTR
# nostr private key to which to receive tokens to
# Nostr
# Nostr private key to which to receive tokens to
# NOSTR_PRIVATE_KEY=nostr_privatekey_here_hex_or_bech32_nsec
# nostr relays (comma separated list)
# Nostr relays (comma separated list)
NOSTR_RELAYS=["wss://nostr-pub.wellorder.net"]

# Wallet API port
Expand All @@ -34,7 +34,7 @@ MINT_LISTEN_PORT=3338
MINT_INFO_NAME="My Cashu mint"
MINT_INFO_DESCRIPTION="The short mint description"
MINT_INFO_DESCRIPTION_LONG="A long mint description that can be a long piece of text."
MINT_INFO_CONTACT=[["email","contact@me.com"], ["twitter","@me"], ["nostr", "npub..."]]
MINT_INFO_CONTACT=[["email","contact@me.com"],["twitter","@me"],["nostr","npub..."]]
MINT_INFO_MOTD="Message to users"

MINT_PRIVATE_KEY=supersecretprivatekey
Expand All @@ -58,13 +58,13 @@ MINT_LND_REST_MACAROON="/home/lnd/.lnd/data/chain/bitcoin/regtest/admin.macaroon

# CoreLightningRestWallet
MINT_CORELIGHTNING_REST_URL=https://localhost:3001
MINT_CORELIGHTNING_REST_MACAROON="./clightning-rest/access.macaroon"
MINT_CORELIGHTNING_REST_CERT="./clightning-2-rest/certificate.pem"
MINT_CORELIGHTNING_REST_MACAROON="/home/cln/cln-rest/access.macaroon"
MINT_CORELIGHTNING_REST_CERT="/home/cln/cln-rest/certificate.pem"

# fee to reserve in percent of the amount
# Fee to reserve in percent of the amount
LIGHTNING_FEE_PERCENT=1.0
# minimum fee to reserve
LIGHTNING_RESERVE_FEE_MIN=2000
# minimum Lightning fee to reserve in msat
LIGHTNING_RESERVE_FEE_MIN_MSAT=2000

# Management
# max peg-in amount in satoshis
Expand Down
6 changes: 3 additions & 3 deletions cashu/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ async def run_and_capture_result():
return async_response[0]


def fee_reserve(amount_msat: int) -> int:
"""Function for calculating the Lightning fee reserve"""
def fee_reserve_msat(amount_msat: int) -> int:
"""Function for calculating the Lightning fee reserve in millisatoshis"""
return max(
int(settings.lightning_reserve_fee_min),
int(settings.lightning_reserve_fee_min_msat),
int(amount_msat * settings.lightning_fee_percent / 100.0),
)

Expand Down
5 changes: 3 additions & 2 deletions cashu/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def find_env_file():
class CashuSettings(BaseSettings):
env_file: str = Field(default=None)
lightning_fee_percent: float = Field(default=1.0)
lightning_reserve_fee_min: int = Field(default=2000)
lightning_reserve_fee_min_msat: int = Field(default=2000)
max_order: int = Field(default=64)

class Config(BaseSettings.Config):
Expand Down Expand Up @@ -55,6 +55,8 @@ class MintSettings(CashuSettings):
mint_listen_port: int = Field(default=3338)
mint_lightning_backend: str = Field(default="LNbitsWallet")
mint_database: str = Field(default="data/mint")
mint_cache_secrets: bool = Field(default=True)

mint_peg_out_only: bool = Field(default=False)
mint_max_peg_in: int = Field(default=None)
mint_max_peg_out: int = Field(default=None)
Expand All @@ -71,7 +73,6 @@ class FakeWalletSettings(MintSettings):
fakewallet_brr: bool = Field(default=True)
fakewallet_delay_payment: bool = Field(default=False)
fakewallet_stochastic_invoice: bool = Field(default=False)
mint_cache_secrets: bool = Field(default=True)


class MintInformation(CashuSettings):
Expand Down
4 changes: 2 additions & 2 deletions cashu/lightning/corelightningrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from loguru import logger

from ..core.base import Amount, MeltQuote, Unit
from ..core.helpers import fee_reserve
from ..core.helpers import fee_reserve_msat
from ..core.settings import settings
from .base import (
InvoiceResponse,
Expand Down Expand Up @@ -313,7 +313,7 @@ async def get_payment_quote(self, bolt11: str) -> PaymentQuoteResponse:
invoice_obj = decode(bolt11)
assert invoice_obj.amount_msat, "invoice has no amount."
amount_msat = int(invoice_obj.amount_msat)
fees_msat = fee_reserve(amount_msat)
fees_msat = fee_reserve_msat(amount_msat)
fees = Amount(unit=Unit.msat, amount=fees_msat)
amount = Amount(unit=Unit.msat, amount=amount_msat)
return PaymentQuoteResponse(
Expand Down
4 changes: 2 additions & 2 deletions cashu/lightning/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)

from ..core.base import Amount, MeltQuote, Unit
from ..core.helpers import fee_reserve
from ..core.helpers import fee_reserve_msat
from ..core.settings import settings
from .base import (
InvoiceResponse,
Expand Down Expand Up @@ -139,7 +139,7 @@ async def get_payment_quote(self, bolt11: str) -> PaymentQuoteResponse:
invoice_obj = decode(bolt11)
assert invoice_obj.amount_msat, "invoice has no amount."
amount_msat = int(invoice_obj.amount_msat)
fees_msat = fee_reserve(amount_msat)
fees_msat = fee_reserve_msat(amount_msat)
fees = Amount(unit=Unit.msat, amount=fees_msat)
amount = Amount(unit=Unit.msat, amount=amount_msat)
return PaymentQuoteResponse(
Expand Down
4 changes: 2 additions & 2 deletions cashu/lightning/lnbits.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
)

from ..core.base import Amount, MeltQuote, Unit
from ..core.helpers import fee_reserve
from ..core.helpers import fee_reserve_msat
from ..core.settings import settings
from .base import (
InvoiceResponse,
Expand Down Expand Up @@ -158,7 +158,7 @@ async def get_payment_quote(self, bolt11: str) -> PaymentQuoteResponse:
invoice_obj = decode(bolt11)
assert invoice_obj.amount_msat, "invoice has no amount."
amount_msat = int(invoice_obj.amount_msat)
fees_msat = fee_reserve(amount_msat)
fees_msat = fee_reserve_msat(amount_msat)
fees = Amount(unit=Unit.msat, amount=fees_msat)
amount = Amount(unit=Unit.msat, amount=amount_msat)
return PaymentQuoteResponse(
Expand Down
8 changes: 3 additions & 5 deletions cashu/lightning/lndrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from loguru import logger

from ..core.base import Amount, MeltQuote, Unit
from ..core.helpers import fee_reserve
from ..core.helpers import fee_reserve_msat
from ..core.settings import settings
from .base import (
InvoiceResponse,
Expand Down Expand Up @@ -58,9 +58,7 @@ def __init__(self):
self.endpoint = endpoint
self.macaroon = load_macaroon(macaroon)

# if no cert provided it should be public so we set verify to True
# and it will still check for validity of certificate and fail if its not valid
# even on startup
# if no cert provided, we expect it to be public so we set verify to True
self.cert = cert or True

self.auth = {"Grpc-Metadata-macaroon": self.macaroon}
Expand Down Expand Up @@ -265,7 +263,7 @@ async def get_payment_quote(self, bolt11: str) -> PaymentQuoteResponse:
invoice_obj = decode(bolt11)
assert invoice_obj.amount_msat, "invoice has no amount."
amount_msat = int(invoice_obj.amount_msat)
fees_msat = fee_reserve(amount_msat)
fees_msat = fee_reserve_msat(amount_msat)
fees = Amount(unit=Unit.msat, amount=fees_msat)
amount = Amount(unit=Unit.msat, amount=amount_msat)
return PaymentQuoteResponse(
Expand Down
2 changes: 0 additions & 2 deletions cashu/lightning/strike.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@


class StrikeUSDWallet(LightningBackend):
"""https://github.com/lnbits/lnbits"""

units = [Unit.usd]

def __init__(self):
Expand Down

0 comments on commit 12e16f4

Please sign in to comment.