Delete coordinator referral program functionality

This commit is contained in:
Reckless_Satoshi 2023-05-05 05:30:25 -07:00
parent a10f7f2e21
commit 4d62ea1549
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
8 changed files with 6 additions and 112 deletions

View File

@ -149,8 +149,6 @@ SPEND_UNCONFIRMED = False
SUGGESTED_TARGET_CONF = 4 SUGGESTED_TARGET_CONF = 4
MINIMUM_TARGET_CONF = 24 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. # 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. # 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 SLASHED_BOND_REWARD_SPLIT = 0.5

View File

@ -337,10 +337,8 @@ class UserRobotAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
"avatar_tag", "avatar_tag",
"id", "id",
"user_link", "user_link",
"is_referred",
"telegram_enabled", "telegram_enabled",
"total_contracts", "total_contracts",
"pending_rewards",
"earned_rewards", "earned_rewards",
"claimed_rewards", "claimed_rewards",
"platform_rating", "platform_rating",
@ -349,11 +347,8 @@ class UserRobotAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
"num_disputes", "num_disputes",
"lost_disputes", "lost_disputes",
) )
raw_id_fields = ( raw_id_fields = ("user",)
"user", list_editable = ["earned_rewards"]
"referred_by",
)
list_editable = ["pending_rewards", "earned_rewards"]
list_display_links = ("avatar_tag", "id") list_display_links = ("avatar_tag", "id")
change_links = ["user"] change_links = ["user"]
readonly_fields = ["avatar_tag"] readonly_fields = ["avatar_tag"]

View File

@ -618,12 +618,10 @@ class Logics:
fee_sats = order.last_satoshis * fee_fraction fee_sats = order.last_satoshis * fee_fraction
reward_tip = int(config("REWARD_TIP")) if user.robot.is_referred else 0
context = {} context = {}
# context necessary for the user to submit a LN invoice # context necessary for the user to submit a LN invoice
context["invoice_amount"] = round( context["invoice_amount"] = round(
order.last_satoshis - fee_sats - reward_tip order.last_satoshis - fee_sats
) # 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
@ -678,11 +676,9 @@ class Logics:
fee_sats = order.last_satoshis * fee_fraction 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): if cls.is_seller(order, user):
escrow_amount = round( escrow_amount = round(
order.last_satoshis + fee_sats + reward_tip order.last_satoshis + fee_sats
) # Trading fee to seller is charged here. ) # Trading fee to seller is charged here.
return True, {"escrow_amount": escrow_amount} return True, {"escrow_amount": escrow_amount}
@ -1523,12 +1519,6 @@ class Logics:
# !!! KEY LINE - PAYS THE BUYER INVOICE !!! # !!! KEY LINE - PAYS THE BUYER INVOICE !!!
cls.pay_buyer(order) cls.pay_buyer(order)
# Add referral rewards (safe)
try:
cls.add_rewards(order)
except Exception:
pass
return True, None return True, None
else: else:
@ -1614,25 +1604,6 @@ class Logics:
user.robot.save() user.robot.save()
return True, None 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 @classmethod
def add_slashed_rewards(cls, slashed_bond, staked_bond): def add_slashed_rewards(cls, slashed_bond, staked_bond):
""" """

View File

@ -58,19 +58,6 @@ class Robot(models.Model):
telegram_lang_code = models.CharField(max_length=10, null=True, blank=True) telegram_lang_code = models.CharField(max_length=10, null=True, blank=True)
telegram_welcomed = models.BooleanField(default=False, null=False) 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 # Claimable rewards
earned_rewards = models.PositiveIntegerField(null=False, default=0) earned_rewards = models.PositiveIntegerField(null=False, default=0)
# Total claimed rewards # Total claimed rewards

View File

@ -427,10 +427,6 @@ class UserViewSchema:
"type": "string", "type": "string",
"description": "Armored ASCII PGP public key block", "description": "Armored ASCII PGP public key block",
}, },
"referral_code": {
"type": "string",
"description": "User's referral code",
},
"token_bits_entropy": {"type": "integer"}, "token_bits_entropy": {"type": "integer"},
"token_shannon_entropy": {"type": "integer"}, "token_shannon_entropy": {"type": "integer"},
"wants_stealth": { "wants_stealth": {
@ -455,10 +451,6 @@ class UserViewSchema:
"type": "string", "type": "string",
"description": "Armored ASCII PGP public key block", "description": "Armored ASCII PGP public key block",
}, },
"referral_code": {
"type": "string",
"description": "User's referral code",
},
"token_bits_entropy": {"type": "integer"}, "token_bits_entropy": {"type": "integer"},
"token_shannon_entropy": {"type": "integer"}, "token_shannon_entropy": {"type": "integer"},
"wants_stealth": { "wants_stealth": {
@ -548,7 +540,6 @@ class UserViewSchema:
"token_shannon_entropy": 0.7714559798089662, "token_shannon_entropy": 0.7714559798089662,
"token_bits_entropy": 169.21582985307933, "token_bits_entropy": 169.21582985307933,
"nickname": "StackerMan420", "nickname": "StackerMan420",
"referral_code": "lfvv4-ppNi1",
"public_key": "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n......\n......", "public_key": "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n......\n......",
"encrypted_private_key": "-----BEGIN PGP PRIVATE KEY BLOCK-----\n\n......\n......", "encrypted_private_key": "-----BEGIN PGP PRIVATE KEY BLOCK-----\n\n......\n......",
"wants_stealth": False, "wants_stealth": False,
@ -771,10 +762,6 @@ class InfoViewSchema:
- Fees - Fees
- maker and taker fees - maker and taker fees
- on-chain swap fees - on-chain swap fees
- Robot (If autheticated)
- nickname
- referral code
- earned rewards
""" """
), ),
} }

View File

@ -37,11 +37,6 @@ class InfoSerializer(serializers.Serializer):
current_swap_fee_rate = serializers.FloatField( current_swap_fee_rate = serializers.FloatField(
help_text="Swap fees to perform on-chain transaction (percent)" 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): class ListOrderSerializer(serializers.ModelSerializer):

View File

@ -25,8 +25,7 @@ def users_cleansing():
# Try an except, due to unknown cause for users lacking robots. # Try an except, due to unknown cause for users lacking robots.
try: try:
if ( if (
user.robot.pending_rewards > 0 user.robot.earned_rewards > 0
or user.robot.earned_rewards > 0
or user.robot.claimed_rewards > 0 or user.robot.claimed_rewards > 0
or user.robot.telegram_enabled is True or user.robot.telegram_enabled is True
): ):
@ -47,33 +46,6 @@ def users_cleansing():
return results 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) @shared_task(name="follow_send_payment", time_limit=180)
def follow_send_payment(hash): def follow_send_payment(hash):
"""Sends sats to buyer, continuous update""" """Sends sats to buyer, continuous update"""

View File

@ -2,7 +2,6 @@ import hashlib
from datetime import datetime, timedelta from datetime import datetime, timedelta
from math import log2 from math import log2
from pathlib import Path from pathlib import Path
from secrets import token_urlsafe
from decouple import config from decouple import config
from django.conf import settings from django.conf import settings
@ -24,7 +23,7 @@ from robohash import Robohash
from scipy.stats import entropy from scipy.stats import entropy
from api.logics import Logics 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.notifications import Telegram
from api.oas_schemas import ( from api.oas_schemas import (
BookViewSchema, BookViewSchema,
@ -705,7 +704,6 @@ class UserView(APIView):
token_sha256 = serializer.data.get("token_sha256") token_sha256 = serializer.data.get("token_sha256")
public_key = serializer.data.get("public_key") public_key = serializer.data.get("public_key")
encrypted_private_key = serializer.data.get("encrypted_private_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 # 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 # 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) user = authenticate(request, username=nickname, password=token_sha256)
login(request, user) login(request, user)
context["referral_code"] = token_urlsafe(8)
user.robot.referral_code = context["referral_code"]
user.robot.avatar = "static/assets/avatars/" + nickname + ".webp" user.robot.avatar = "static/assets/avatars/" + nickname + ".webp"
# Noticed some PGP keys replaced at re-login. Should not happen. # 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: if not user.robot.encrypted_private_key:
user.robot.encrypted_private_key = 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() user.robot.save()
context = {**context, **Telegram.get_context(user)} context = {**context, **Telegram.get_context(user)}
@ -816,7 +806,6 @@ class UserView(APIView):
context["public_key"] = user.robot.public_key context["public_key"] = user.robot.public_key
context["encrypted_private_key"] = user.robot.encrypted_private_key context["encrypted_private_key"] = user.robot.encrypted_private_key
context["earned_rewards"] = user.robot.earned_rewards context["earned_rewards"] = user.robot.earned_rewards
context["referral_code"] = str(user.robot.referral_code)
context["wants_stealth"] = user.robot.wants_stealth context["wants_stealth"] = user.robot.wants_stealth
# Adds/generate telegram token and whether it is enabled # Adds/generate telegram token and whether it is enabled