Add MAX_SWAP_AMOUNT envvar (#389)

This commit is contained in:
Reckless_Satoshi 2023-03-14 19:54:31 +00:00 committed by GitHub
parent 42f208fad4
commit 82c8f2280b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 5 deletions

View File

@ -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)

View File

@ -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(

View File

@ -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