diff --git a/.env-sample b/.env-sample index 34b6927a..28d77782 100644 --- a/.env-sample +++ b/.env-sample @@ -149,8 +149,6 @@ SPEND_UNCONFIRMED = False SUGGESTED_TARGET_CONF = 4 MINIMUM_TARGET_CONF = 24 -# Reward tip. Reward for every finished trade in the referral program (Satoshis) -REWARD_TIP = 100 # Fraction rewarded to user from the slashed bond of a counterpart. # It should not be close to 1, or could be exploited by an attacker trading with himself to DDOS the LN node. SLASHED_BOND_REWARD_SPLIT = 0.5 diff --git a/api/admin.py b/api/admin.py index 258d4881..2cb7ee21 100644 --- a/api/admin.py +++ b/api/admin.py @@ -337,10 +337,8 @@ class UserRobotAdmin(AdminChangeLinksMixin, admin.ModelAdmin): "avatar_tag", "id", "user_link", - "is_referred", "telegram_enabled", "total_contracts", - "pending_rewards", "earned_rewards", "claimed_rewards", "platform_rating", @@ -349,11 +347,8 @@ class UserRobotAdmin(AdminChangeLinksMixin, admin.ModelAdmin): "num_disputes", "lost_disputes", ) - raw_id_fields = ( - "user", - "referred_by", - ) - list_editable = ["pending_rewards", "earned_rewards"] + raw_id_fields = ("user",) + list_editable = ["earned_rewards"] list_display_links = ("avatar_tag", "id") change_links = ["user"] readonly_fields = ["avatar_tag"] diff --git a/api/logics.py b/api/logics.py index 71016a6a..6c2bfb31 100644 --- a/api/logics.py +++ b/api/logics.py @@ -618,12 +618,10 @@ class Logics: fee_sats = order.last_satoshis * fee_fraction - reward_tip = int(config("REWARD_TIP")) if user.robot.is_referred else 0 - context = {} # context necessary for the user to submit a LN invoice context["invoice_amount"] = round( - order.last_satoshis - fee_sats - reward_tip + order.last_satoshis - fee_sats ) # Trading fee to buyer is charged here. # context necessary for the user to submit an onchain address @@ -678,11 +676,9 @@ class Logics: fee_sats = order.last_satoshis * fee_fraction - reward_tip = int(config("REWARD_TIP")) if user.robot.is_referred else 0 - if cls.is_seller(order, user): escrow_amount = round( - order.last_satoshis + fee_sats + reward_tip + order.last_satoshis + fee_sats ) # Trading fee to seller is charged here. return True, {"escrow_amount": escrow_amount} @@ -1523,12 +1519,6 @@ class Logics: # !!! KEY LINE - PAYS THE BUYER INVOICE !!! cls.pay_buyer(order) - # Add referral rewards (safe) - try: - cls.add_rewards(order) - except Exception: - pass - return True, None else: @@ -1614,25 +1604,6 @@ class Logics: user.robot.save() return True, None - @classmethod - def add_rewards(cls, order): - """ - This function is called when a trade is finished. - If participants of the order were referred, the reward is given to the referees. - """ - - if order.maker.robot.is_referred: - robot = order.maker.robot.referred_by - robot.pending_rewards += int(config("REWARD_TIP")) - robot.save() - - if order.taker.robot.is_referred: - robot = order.taker.robot.referred_by - robot.pending_rewards += int(config("REWARD_TIP")) - robot.save() - - return - @classmethod def add_slashed_rewards(cls, slashed_bond, staked_bond): """ diff --git a/api/models/robot.py b/api/models/robot.py index fe718be1..9795dfa6 100644 --- a/api/models/robot.py +++ b/api/models/robot.py @@ -58,19 +58,6 @@ class Robot(models.Model): telegram_lang_code = models.CharField(max_length=10, null=True, blank=True) telegram_welcomed = models.BooleanField(default=False, null=False) - # Referral program - is_referred = models.BooleanField(default=False, null=False) - referred_by = models.ForeignKey( - "self", - related_name="referee", - on_delete=models.SET_NULL, - null=True, - default=None, - blank=True, - ) - referral_code = models.CharField(max_length=15, null=True, blank=True) - # Recent rewards from referred trades that will be "earned" at a later point to difficult espionage. - pending_rewards = models.PositiveIntegerField(null=False, default=0) # Claimable rewards earned_rewards = models.PositiveIntegerField(null=False, default=0) # Total claimed rewards diff --git a/api/oas_schemas.py b/api/oas_schemas.py index 4e8648b6..45db6874 100644 --- a/api/oas_schemas.py +++ b/api/oas_schemas.py @@ -427,10 +427,6 @@ class UserViewSchema: "type": "string", "description": "Armored ASCII PGP public key block", }, - "referral_code": { - "type": "string", - "description": "User's referral code", - }, "token_bits_entropy": {"type": "integer"}, "token_shannon_entropy": {"type": "integer"}, "wants_stealth": { @@ -455,10 +451,6 @@ class UserViewSchema: "type": "string", "description": "Armored ASCII PGP public key block", }, - "referral_code": { - "type": "string", - "description": "User's referral code", - }, "token_bits_entropy": {"type": "integer"}, "token_shannon_entropy": {"type": "integer"}, "wants_stealth": { @@ -548,7 +540,6 @@ class UserViewSchema: "token_shannon_entropy": 0.7714559798089662, "token_bits_entropy": 169.21582985307933, "nickname": "StackerMan420", - "referral_code": "lfvv4-ppNi1", "public_key": "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n......\n......", "encrypted_private_key": "-----BEGIN PGP PRIVATE KEY BLOCK-----\n\n......\n......", "wants_stealth": False, @@ -771,10 +762,6 @@ class InfoViewSchema: - Fees - maker and taker fees - on-chain swap fees - - Robot (If autheticated) - - nickname - - referral code - - earned rewards """ ), } diff --git a/api/serializers.py b/api/serializers.py index d539cde4..d3db1fac 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -37,11 +37,6 @@ class InfoSerializer(serializers.Serializer): current_swap_fee_rate = serializers.FloatField( help_text="Swap fees to perform on-chain transaction (percent)" ) - nickname = serializers.CharField(help_text="Currenlty logged in Robot name") - referral_code = serializers.CharField(help_text="Logged in users's referral code") - earned_rewards = serializers.IntegerField( - help_text="Logged in user's earned rewards in satoshis" - ) class ListOrderSerializer(serializers.ModelSerializer): diff --git a/api/tasks.py b/api/tasks.py index b9fba25c..078d1ddf 100644 --- a/api/tasks.py +++ b/api/tasks.py @@ -25,8 +25,7 @@ def users_cleansing(): # Try an except, due to unknown cause for users lacking robots. try: if ( - user.robot.pending_rewards > 0 - or user.robot.earned_rewards > 0 + user.robot.earned_rewards > 0 or user.robot.claimed_rewards > 0 or user.robot.telegram_enabled is True ): @@ -47,33 +46,6 @@ def users_cleansing(): return results -@shared_task(name="give_rewards", time_limit=180) -def give_rewards(): - """ - Referral rewards go from pending to earned. - Happens asynchronously so the referral program cannot be easily used to spy. - """ - from api.models import Robot - - # Users who's last login has not been in the last 6 hours - queryset = Robot.objects.filter(pending_rewards__gt=0) - - # And do not have an active trade, any past contract or any reward. - results = {} - for robot in queryset: - given_reward = robot.pending_rewards - robot.earned_rewards += given_reward - robot.pending_rewards = 0 - robot.save() - - results[robot.user.username] = { - "given_reward": given_reward, - "earned_rewards": robot.earned_rewards, - } - - return results - - @shared_task(name="follow_send_payment", time_limit=180) def follow_send_payment(hash): """Sends sats to buyer, continuous update""" diff --git a/api/views.py b/api/views.py index 839ac69e..c69421d7 100644 --- a/api/views.py +++ b/api/views.py @@ -2,7 +2,6 @@ import hashlib from datetime import datetime, timedelta from math import log2 from pathlib import Path -from secrets import token_urlsafe from decouple import config from django.conf import settings @@ -24,7 +23,7 @@ from robohash import Robohash from scipy.stats import entropy from api.logics import Logics -from api.models import Currency, LNPayment, MarketTick, OnchainPayment, Order, Robot +from api.models import Currency, LNPayment, MarketTick, OnchainPayment, Order from api.notifications import Telegram from api.oas_schemas import ( BookViewSchema, @@ -705,7 +704,6 @@ class UserView(APIView): token_sha256 = serializer.data.get("token_sha256") public_key = serializer.data.get("public_key") encrypted_private_key = serializer.data.get("encrypted_private_key") - ref_code = serializer.data.get("ref_code") # Now the server only receives a hash of the token. So server trusts the client # with computing length, counts and unique_values to confirm the high entropy of the token @@ -783,8 +781,6 @@ class UserView(APIView): user = authenticate(request, username=nickname, password=token_sha256) login(request, user) - context["referral_code"] = token_urlsafe(8) - user.robot.referral_code = context["referral_code"] user.robot.avatar = "static/assets/avatars/" + nickname + ".webp" # Noticed some PGP keys replaced at re-login. Should not happen. @@ -794,12 +790,6 @@ class UserView(APIView): if not user.robot.encrypted_private_key: user.robot.encrypted_private_key = encrypted_private_key - # If the ref_code was created by another robot, this robot was referred. - queryset = Robot.objects.filter(referral_code=ref_code) - if len(queryset) == 1: - user.robot.is_referred = True - user.robot.referred_by = queryset[0] - user.robot.save() context = {**context, **Telegram.get_context(user)} @@ -816,7 +806,6 @@ class UserView(APIView): context["public_key"] = user.robot.public_key context["encrypted_private_key"] = user.robot.encrypted_private_key context["earned_rewards"] = user.robot.earned_rewards - context["referral_code"] = str(user.robot.referral_code) context["wants_stealth"] = user.robot.wants_stealth # Adds/generate telegram token and whether it is enabled