diff --git a/.env-sample b/.env-sample index c66d28f6..67cab08e 100644 --- a/.env-sample +++ b/.env-sample @@ -119,6 +119,7 @@ PAYOUT_TIMEOUT_SECONDS = 90 # REVERSE SUBMARINE SWAP PAYOUTS # Disable on-the-fly swaps feature DISABLE_ONCHAIN = False +MAX_SWAP_ALLOWED = 500000 # Shape of fee to available liquidity curve. Either "linear" or "exponential" SWAP_FEE_SHAPE = 'exponential' # EXPONENTIAL. fee (%) = MIN_SWAP_FEE + (MAX_SWAP_FEE - MIN_SWAP_FEE) * e ^ (-LAMBDA * onchain_liquidity_fraction) diff --git a/api/lightning/node.py b/api/lightning/node.py index b21a565e..31cecdf0 100644 --- a/api/lightning/node.py +++ b/api/lightning/node.py @@ -18,7 +18,7 @@ from . import router_pb2 as routerrpc from . import router_pb2_grpc as routerstub ####### -# Should work with LND (c-lightning in the future if there are features that deserve the work) +# Works with LND (c-lightning in the future for multi-vendor resiliance) ####### # Read tls.cert from file or .env variable string encoded as base64 @@ -36,6 +36,8 @@ except Exception: MACAROON = b64decode(config("LND_MACAROON_BASE64")) LND_GRPC_HOST = config("LND_GRPC_HOST") +DISABLE_ONCHAIN = config("DISABLE_ONCHAIN", cast=bool, default=True) +MAX_SWAP_AMOUNT = config("MAX_SWAP_AMOUNT", cast=int, default=500000) class LNNode: @@ -131,7 +133,7 @@ class LNNode: def pay_onchain(cls, onchainpayment, queue_code=5, on_mempool_code=2): """Send onchain transaction for buyer payouts""" - if config("DISABLE_ONCHAIN", cast=bool): + if DISABLE_ONCHAIN or onchainpayment.sent_satoshis > MAX_SWAP_AMOUNT: return False request = lnrpc.SendCoinsRequest( diff --git a/api/logics.py b/api/logics.py index a85aaea9..b128bccb 100644 --- a/api/logics.py +++ b/api/logics.py @@ -611,16 +611,23 @@ class Logics: ) # Trading fee to buyer is charged here. # context necessary for the user to submit an onchain address - MIN_SWAP_AMOUNT = int(config("MIN_SWAP_AMOUNT")) + MIN_SWAP_AMOUNT = config("MIN_SWAP_AMOUNT", cast=int, default=20000) + MAX_SWAP_AMOUNT = config("MAX_SWAP_AMOUNT", cast=int, default=500000) if context["invoice_amount"] < MIN_SWAP_AMOUNT: context["swap_allowed"] = False context[ "swap_failure_reason" - ] = "Order amount is too small to be eligible for a swap" + ] = f"Order amount is smaller than the minimum swap available of {MIN_SWAP_AMOUNT} Sats" + return True, context + elif context["invoice_amount"] > MAX_SWAP_AMOUNT: + context["swap_allowed"] = False + context[ + "swap_failure_reason" + ] = f"Order amount is bigger than the maximum swap available of {MAX_SWAP_AMOUNT} Sats" return True, context - if config("DISABLE_ONCHAIN", cast=bool): + if config("DISABLE_ONCHAIN", cast=bool, default=True): context["swap_allowed"] = False context["swap_failure_reason"] = "On-the-fly submarine swaps are dissabled" return True, context