Skip to content

Commit

Permalink
feat: sybil data input endpoint for round (#9371)
Browse files Browse the repository at this point in the history
* feat: sybil data input endpoint for round

* stale nav (#9382)

Co-authored-by: Kevin Owocki <ksowocki@gmail.com>
  • Loading branch information
thelostone-mc and owocki authored Aug 31, 2021
1 parent 891b1c9 commit 5382e91
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 11 deletions.
6 changes: 3 additions & 3 deletions app/dashboard/templates/shared/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
</div>
</a>

<a class="dropdown-item text-grey-500 px-3 py-0" href="{% url "quadraticlands:quadraticlands" %}">
<a class="dropdown-item text-grey-500 px-3 py-0" href="http://gitcoindao.com">
<div class="row">
<div class="col align-self-center" style="max-width: 3.25rem;">
<svg height="39" viewBox="0 0 56 57" fill="none" xmlns="http://www.w3.org/2000/svg">
Expand All @@ -149,8 +149,8 @@
</svg>
</div>
<div class="col py-3 text-wrap">
<b class="gc-megamenu-title d-block">{% trans "Govern" %}</b>
<span>{% trans "Decide the future of the open web" %}</span>
<b class="gc-megamenu-title d-block">{% trans "DAO" %}</b>
<span>{% trans "Get involved in the decentralized GitcoinDAO community." %}</span>
</div>
</div>
</a>
Expand Down
2 changes: 1 addition & 1 deletion app/grants/router.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime, timedelta

from django.core.paginator import Paginator
from django.core.paginator import EmptyPage, Paginator

import django_filters.rest_framework
from ratelimit.decorators import ratelimit
Expand Down
12 changes: 7 additions & 5 deletions app/grants/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
collection_thumbnail, contribute_to_grants_v1, contribution_addr_from_all_as_json,
contribution_addr_from_grant_as_json, contribution_addr_from_grant_during_round_as_json,
contribution_addr_from_round_as_json, contribution_info_from_grant_during_round_as_json, create_matching_pledge_v1,
flag, get_collection, get_collections_list, get_ethereum_cart_data, get_grant_payload, get_grants,
get_interrupted_contributions, get_replaced_tx, get_trust_bonus, grant_activity, grant_categories, grant_details,
grant_details_api, grant_details_contributions, grant_details_contributors, grant_edit, grant_fund, grant_new,
grants, grants_addr_as_json, grants_bulk_add, grants_by_grant_type, grants_cart_view, grants_info, grants_landing,
grants_type_redirect, ingest_contributions, ingest_contributions_view, invoice, leaderboard,
flag, get_clr_sybil_input, get_collection, get_collections_list, get_ethereum_cart_data, get_grant_payload,
get_grants, get_interrupted_contributions, get_replaced_tx, get_trust_bonus, grant_activity, grant_categories,
grant_details, grant_details_api, grant_details_contributions, grant_details_contributors, grant_edit, grant_fund,
grant_new, grants, grants_addr_as_json, grants_bulk_add, grants_by_grant_type, grants_cart_view, grants_info,
grants_landing, grants_type_redirect, ingest_contributions, ingest_contributions_view, invoice, leaderboard,
manage_ethereum_cart_data, new_matching_partner, profile, quickstart, remove_grant_from_collection, save_collection,
toggle_grant_favorite, verify_grant,
)
Expand Down Expand Up @@ -114,5 +114,7 @@
path('v1/api/export_addresses/grant<int:grant_id>_round<int:round_id>.json', contribution_addr_from_grant_during_round_as_json, name='contribution_addr_from_grant_during_round_as_json'),
path('v1/api/export_info/grant<int:grant_id>_round<int:round_id>.json', contribution_info_from_grant_during_round_as_json, name='contribution_addr_from_grant_during_round_as_json'),

# custom API
path('v1/api/get-clr-data/<int:round_id>', get_clr_sybil_input, name='get_clr_sybil_input')

]
72 changes: 70 additions & 2 deletions app/grants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import logging
import math
import re
import time
import uuid
from datetime import datetime
from urllib.parse import urlencode
Expand All @@ -38,6 +37,7 @@
from django.db import connection, transaction
from django.db.models import Q, Subquery
from django.http import Http404, HttpResponse, JsonResponse
from django.http.response import HttpResponseBadRequest, HttpResponseServerError
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.templatetags.static import static
Expand Down Expand Up @@ -67,6 +67,7 @@
from economy.models import Token as FTokens
from economy.utils import convert_token_to_usdt
from eth_account.messages import defunct_hash_message
from grants.clr import fetch_data
from grants.models import (
CartActivity, Contribution, Flag, Grant, GrantAPIKey, GrantBrandingRoutingPolicy, GrantCategory, GrantCLR,
GrantCollection, GrantType, MatchPledge, Subscription,
Expand All @@ -81,7 +82,7 @@
from kudos.models import BulkTransferCoupon, Token
from marketing.mails import grant_cancellation, new_grant_flag_admin
from marketing.models import Keyword, Stat
from perftools.models import JSONStore
from perftools.models import JSONStore, StaticJsonEnv
from ratelimit.decorators import ratelimit
from retail.helpers import get_ip
from townsquare.models import Announcement, Favorite, PinnedPost
Expand Down Expand Up @@ -3496,6 +3497,73 @@ def handle_ingestion(profile, network, identifier, do_write):
return JsonResponse({ 'success': True, 'ingestion_types': ingestion_types })



def get_clr_sybil_input(request, round_id):
'''
This returns a paginated JSON response to return contributions
which are considered while calculating the QF match for a given CLR
'''
token = request.headers['token']
page = request.GET.get('page', 1)

data = StaticJsonEnv.objects.get(key='BSCI_SYBIL_TOKEN').data

if not round_id or not token or not data['token']:
return HttpResponseBadRequest("error: missing arguments")

if token != data['token']:
return HttpResponseBadRequest("error: invalid token")

clr = GrantCLR.objects.filter(pk=round_id).first()
if not clr:
return HttpResponseBadRequest("error: round not found")

try:
limit = data['limit'] if data['limit'] else 100

# fetch grant contributions needed for round
__, all_clr_contributions = fetch_data(clr)
total_count = all_clr_contributions.count()

# extract only needed fields
all_clr_contributions = list(all_clr_contributions.values(
'created_on', 'profile_for_clr__handle', 'profile_for_clr_id',
'match', 'normalized_data'
))

# paginate contributions
contributions = Paginator(all_clr_contributions, limit)
try:
contributions_queryset = contributions.page(page)
except EmptyPage:
response = {
'metadata': {
'count': 0,
'current_page': 0,
'num_pages': 0,
'has_next': False
},
'contributions': []
}
return HttpResponse(response)

response = {
'metadata': {
'count': total_count,
'current_page': page,
'total_pages': contributions.num_pages,
'has_next': contributions_queryset.has_next()
},
'contributions': contributions_queryset.object_list
}

except Exception as e:
print(e)
return HttpResponseServerError()

return JsonResponse(response)


@csrf_exempt
def get_trust_bonus(request):
'''
Expand Down

0 comments on commit 5382e91

Please sign in to comment.