mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-13 02:46:28 +00:00
Add MAX_SWAP_AMOUNT envvar (#389)
This commit is contained in:
parent
42f208fad4
commit
82c8f2280b
@ -119,6 +119,7 @@ PAYOUT_TIMEOUT_SECONDS = 90
|
|||||||
# REVERSE SUBMARINE SWAP PAYOUTS
|
# REVERSE SUBMARINE SWAP PAYOUTS
|
||||||
# Disable on-the-fly swaps feature
|
# Disable on-the-fly swaps feature
|
||||||
DISABLE_ONCHAIN = False
|
DISABLE_ONCHAIN = False
|
||||||
|
MAX_SWAP_ALLOWED = 500000
|
||||||
# Shape of fee to available liquidity curve. Either "linear" or "exponential"
|
# Shape of fee to available liquidity curve. Either "linear" or "exponential"
|
||||||
SWAP_FEE_SHAPE = 'exponential'
|
SWAP_FEE_SHAPE = 'exponential'
|
||||||
# EXPONENTIAL. fee (%) = MIN_SWAP_FEE + (MAX_SWAP_FEE - MIN_SWAP_FEE) * e ^ (-LAMBDA * onchain_liquidity_fraction)
|
# EXPONENTIAL. fee (%) = MIN_SWAP_FEE + (MAX_SWAP_FEE - MIN_SWAP_FEE) * e ^ (-LAMBDA * onchain_liquidity_fraction)
|
||||||
|
@ -18,7 +18,7 @@ from . import router_pb2 as routerrpc
|
|||||||
from . import router_pb2_grpc as routerstub
|
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
|
# Read tls.cert from file or .env variable string encoded as base64
|
||||||
@ -36,6 +36,8 @@ except Exception:
|
|||||||
MACAROON = b64decode(config("LND_MACAROON_BASE64"))
|
MACAROON = b64decode(config("LND_MACAROON_BASE64"))
|
||||||
|
|
||||||
LND_GRPC_HOST = config("LND_GRPC_HOST")
|
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:
|
class LNNode:
|
||||||
@ -131,7 +133,7 @@ class LNNode:
|
|||||||
def pay_onchain(cls, onchainpayment, queue_code=5, on_mempool_code=2):
|
def pay_onchain(cls, onchainpayment, queue_code=5, on_mempool_code=2):
|
||||||
"""Send onchain transaction for buyer payouts"""
|
"""Send onchain transaction for buyer payouts"""
|
||||||
|
|
||||||
if config("DISABLE_ONCHAIN", cast=bool):
|
if DISABLE_ONCHAIN or onchainpayment.sent_satoshis > MAX_SWAP_AMOUNT:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
request = lnrpc.SendCoinsRequest(
|
request = lnrpc.SendCoinsRequest(
|
||||||
|
@ -611,16 +611,23 @@ class Logics:
|
|||||||
) # Trading fee to buyer is charged here.
|
) # Trading fee to buyer is charged here.
|
||||||
|
|
||||||
# context necessary for the user to submit an onchain address
|
# 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:
|
if context["invoice_amount"] < MIN_SWAP_AMOUNT:
|
||||||
context["swap_allowed"] = False
|
context["swap_allowed"] = False
|
||||||
context[
|
context[
|
||||||
"swap_failure_reason"
|
"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
|
return True, context
|
||||||
|
|
||||||
if config("DISABLE_ONCHAIN", cast=bool):
|
if config("DISABLE_ONCHAIN", cast=bool, default=True):
|
||||||
context["swap_allowed"] = False
|
context["swap_allowed"] = False
|
||||||
context["swap_failure_reason"] = "On-the-fly submarine swaps are dissabled"
|
context["swap_failure_reason"] = "On-the-fly submarine swaps are dissabled"
|
||||||
return True, context
|
return True, context
|
||||||
|
Loading…
Reference in New Issue
Block a user