From cbb6f73da05eb3fb93acc8e3646e93439964aa7b Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Wed, 4 Oct 2023 15:19:47 -0700 Subject: [PATCH] Remove lnpayment, tick, onchain model contraints based on .env --- api/logics.py | 4 ++-- api/models/ln_payment.py | 4 ++-- api/models/market_tick.py | 8 ++++++-- api/models/onchain_payment.py | 17 ++++------------- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/api/logics.py b/api/logics.py index d01a5c166..c37a7f996 100644 --- a/api/logics.py +++ b/api/logics.py @@ -587,7 +587,7 @@ def compute_swap_fee_rate(balance): shape = str(config("SWAP_FEE_SHAPE")) if shape == "linear": - MIN_SWAP_FEE = float(config("MIN_SWAP_FEE")) + MIN_SWAP_FEE = config("MIN_SWAP_FEE", cast=float, default=0.01) MIN_POINT = float(config("MIN_POINT")) MAX_SWAP_FEE = float(config("MAX_SWAP_FEE")) MAX_POINT = float(config("MAX_POINT")) @@ -600,7 +600,7 @@ def compute_swap_fee_rate(balance): ) elif shape == "exponential": - MIN_SWAP_FEE = float(config("MIN_SWAP_FEE")) + MIN_SWAP_FEE = config("MIN_SWAP_FEE", cast=float, default=0.01) MAX_SWAP_FEE = float(config("MAX_SWAP_FEE")) SWAP_LAMBDA = float(config("SWAP_LAMBDA")) swap_fee_rate = MIN_SWAP_FEE + (MAX_SWAP_FEE - MIN_SWAP_FEE) * math.exp( diff --git a/api/models/ln_payment.py b/api/models/ln_payment.py index 949b1e214..76a73be3a 100644 --- a/api/models/ln_payment.py +++ b/api/models/ln_payment.py @@ -1,4 +1,4 @@ -from decouple import config +from django.conf import settings from django.contrib.auth.models import User from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models @@ -78,7 +78,7 @@ class FailureReason(models.IntegerChoices): num_satoshis = models.PositiveBigIntegerField( validators=[ MinValueValidator(100), - MaxValueValidator(1.5 * config("MAX_TRADE", cast=int, default=1_000_000)), + MaxValueValidator(1.5 * settings.MAX_TRADE), ] ) # Routing budget in PPM diff --git a/api/models/market_tick.py b/api/models/market_tick.py index 662080a62..ac09d3608 100644 --- a/api/models/market_tick.py +++ b/api/models/market_tick.py @@ -51,7 +51,7 @@ class MarketTick(models.Model): fee = models.DecimalField( max_digits=4, decimal_places=4, - default=config("FEE", cast=float, default=0), + default=0, validators=[MinValueValidator(0), MaxValueValidator(1)], ) @@ -71,7 +71,11 @@ def log_a_tick(order): premium = 100 * (price / market_exchange_rate - 1) market_tick = MarketTick.objects.create( - price=price, volume=volume, premium=premium, currency=order.currency + price=price, + volume=volume, + premium=premium, + currency=order.currency, + fee=config("FEE", cast=float, default=0), ) return market_tick diff --git a/api/models/onchain_payment.py b/api/models/onchain_payment.py index f3efc9477..c69599730 100644 --- a/api/models/onchain_payment.py +++ b/api/models/onchain_payment.py @@ -1,4 +1,4 @@ -from decouple import config +from django.conf import settings from django.contrib.auth.models import User from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models @@ -7,9 +7,6 @@ from control.models import BalanceLog -MAX_TRADE = config("MAX_TRADE", cast=int, default=1_000_000) -MIN_SWAP_AMOUNT = config("MIN_SWAP_AMOUNT", cast=int, default=1_000_000) - class OnchainPayment(models.Model): class Concepts(models.IntegerChoices): @@ -48,17 +45,11 @@ def get_balance(): num_satoshis = models.PositiveBigIntegerField( null=True, - validators=[ - MinValueValidator(0.5 * MIN_SWAP_AMOUNT), - MaxValueValidator(1.5 * MAX_TRADE), - ], + validators=[MinValueValidator(0), MaxValueValidator(1.5 * settings.MAX_TRADE)], ) sent_satoshis = models.PositiveBigIntegerField( null=True, - validators=[ - MinValueValidator(0.5 * MIN_SWAP_AMOUNT), - MaxValueValidator(1.5 * MAX_TRADE), - ], + validators=[MinValueValidator(0), MaxValueValidator(1.5 * settings.MAX_TRADE)], ) # fee in sats/vbyte with mSats decimals fee_msat suggested_mining_fee_rate = models.DecimalField( @@ -91,7 +82,7 @@ def get_balance(): swap_fee_rate = models.DecimalField( max_digits=4, decimal_places=2, - default=config("MIN_SWAP_FEE", cast=float, default=0.01) * 100, + default=1, null=False, blank=False, )