Skip to content

Commit

Permalink
OCT-2335: Handle users with expired stamps but on Allow List && OCT-2…
Browse files Browse the repository at this point in the history
…338 Update the timeout list for E6 (#637)
  • Loading branch information
aziolek authored Jan 24, 2025
2 parents 332eb17 + ac70c31 commit e67d03c
Show file tree
Hide file tree
Showing 5 changed files with 967 additions and 12 deletions.
2 changes: 1 addition & 1 deletion backend/app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@
"0x8bfcf8cb383149d4ef37e7a609cec195cdcbe099",
"0xa515f7fb260095eebc860425493b8761b4fc9abd",
"0xaa95ca26c92b0634df7a1a1504f579f13bfb7f9d",
"0x90c32e6b29794fd7f5bba2bbee74e924078b3f9b",
}

TIMEOUT_LIST = {
Expand Down Expand Up @@ -929,7 +930,6 @@
"0x86e6b55bb954e1cfab567f9582e0fa580bb0290d",
"0xfef75b27d4ae3d5228bcc2912f9cdceafe5f82e3",
"0xc4f91cdd498a30f8ed1dea3883cba314a7a2a022",
"0x90c32e6b29794fd7f5bba2bbee74e924078b3f9b",
"0x051010142a0b9de7f0fd8fb31d085407287f6381",
"0xd1825dd9a5e49791fb7961ac3c4170deed5710b4",
"0xbea26de685ef828b60ca53b40ecc9bab35645fdf",
Expand Down
35 changes: 26 additions & 9 deletions backend/app/modules/user/antisybil/core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime, timezone
import json
from typing import Optional

Expand All @@ -22,14 +23,15 @@ def determine_antisybil_score(
if score is None:
return None

potential_score = _apply_gtc_staking_stamp_nullification(score.score, score)
now = datetime.now(timezone.utc)
potential_score = _apply_gtc_staking_stamp_nullification(score.score, score, now)

if user_address.lower() in timeout_list:
return AntisybilStatusDTO(
score=0.0, expires_at=score.expires_at, is_on_timeout_list=True
)
elif user_address.lower() in GUEST_LIST and not _has_guest_stamp_applied_by_gp(
score
score, now
):
return AntisybilStatusDTO(
score=potential_score + 21.0,
Expand All @@ -46,23 +48,38 @@ def _get_provider(stamp) -> str:
return stamp["credential"]["credentialSubject"]["provider"]


def _has_guest_stamp_applied_by_gp(score: GPStamps) -> bool:
def _is_not_expired(stamp, now: datetime) -> bool:
expiration_date = datetime.fromisoformat(stamp["credential"]["expirationDate"])
return expiration_date > now


def _has_guest_stamp_applied_by_gp(score: GPStamps, now: datetime) -> bool:
all_stamps = json.loads(score.stamps)
stamps = [
stamp
for stamp in all_stamps
if _get_provider(stamp) in GUEST_LIST_STAMP_PROVIDERS
and _is_not_expired(stamp, now)
]
return len(stamps) > 0


def _apply_gtc_staking_stamp_nullification(score: int, stamps: GPStamps) -> int:
def _apply_gtc_staking_stamp_nullification(
score: int, stamps: GPStamps, now: datetime
) -> int:
"""Take score and stamps as returned by Passport and remove score associated with GTC staking"""

delta = 0
all_stamps = json.loads(stamps.stamps)
providers = [_get_provider(stamp) for stamp in all_stamps]
for provider in providers:
if provider in GTC_STAKING_STAMP_PROVIDERS_AND_SCORES.keys():
delta = delta + GTC_STAKING_STAMP_PROVIDERS_AND_SCORES[provider]
delta = 0

# Consider only stamps that are not expired
for stamp in all_stamps:
expiration_date = datetime.fromisoformat(stamp["credential"]["expirationDate"])

if expiration_date < now:
continue

provider = stamp["credential"]["credentialSubject"]["provider"]
delta += GTC_STAKING_STAMP_PROVIDERS_AND_SCORES.get(provider, 0)

return score - delta
Loading

0 comments on commit e67d03c

Please sign in to comment.