Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanglen committed Jul 31, 2024
2 parents 8f00c7d + 738b618 commit c5d69df
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [✅ Get donations sent for account: `GET /accounts/{ACCOUNT_ID}/donations_sent` (paginated)](#-get-donations-sent-for-account-get-accountsaccount_iddonations_sent-paginated)
- [✅ Get pots for account: `GET /accounts/{ACCOUNT_ID}/active_pots` (paginated)](#-get-pots-for-account-get-accountsaccount_idactive_pots-paginated)
- [✅ Get applications for account: `GET /accounts/{ACCOUNT_ID}/pot_applications` (paginated)](#-get-applications-for-account-get-accountsaccount_idpot_applications-paginated)
- [✅ Get registrations to lists by account: `GET /accounts/{ACCOUNT_ID}/list-registrations` (paginated)](#-get-registrations-to-lists-by-account-get-accountsaccount_idlist-registrations-paginated)
- [`List` endpoints](#list-endpoints)
- [✅ Get all lists: `GET /lists` (paginated)](#-get-all-lists-get-lists-paginated)
- [✅ Get list by ID: `GET /lists/{LIST_ID}` (paginated)](#-get-list-by-id-get-listslist_id-paginated)
Expand Down
3 changes: 2 additions & 1 deletion indexer_app/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from pots.utils import match_pot_factory_pattern, match_pot_subaccount_pattern

from .logging import log_memory_usage, logger
from .utils import handle_add_nadabot_admin, handle_set_factory_configs # handle_batch_donations,
from .utils import (
handle_add_nadabot_admin, # handle_batch_donations,
handle_add_stamp,
handle_default_list_status_change,
handle_list_admin_removal,
Expand All @@ -35,6 +35,7 @@
handle_pot_config_update,
handle_registry_blacklist_action,
handle_registry_unblacklist_action,
handle_set_factory_configs,
handle_set_payouts,
handle_social_profile_update,
handle_transfer_payout,
Expand Down
2 changes: 1 addition & 1 deletion indexer_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ class BlockHeight(models.Model):
updated_at = models.DateTimeField(
_("updated at"),
help_text=_("block height last update at."),
)
)
5 changes: 1 addition & 4 deletions indexer_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ async def handle_new_pot(
pot_config_update = sync_to_async(pot.update_configs)
await pot_config_update()
return


logger.info("upsert chef")
if data.get("chef"):
Expand Down Expand Up @@ -195,9 +194,7 @@ async def handle_new_pot(
"all_paid_out": False,
"protocol_config_provider": data["protocol_config_provider"],
}
pot = await Pot.objects.acreate(
account=receiver, **pot_defaults
)
pot = await Pot.objects.acreate(account=receiver, **pot_defaults)

# Add admins to the Pot
if data.get("admins"):
Expand Down
85 changes: 63 additions & 22 deletions pots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,35 +68,43 @@ class PotFactory(models.Model):

class Meta:
verbose_name_plural = "Pot Factories"


def update_configs(self):
try:

url = f"{settings.FASTNEAR_RPC_URL}/account/{self.account.id}/view/get_config"
url = (
f"{settings.FASTNEAR_RPC_URL}/account/{self.account.id}/view/get_config"
)
response = requests.get(url)
if response.status_code != 200:
logger.error(f"Failed to get config for pot {self.account}: {response.text}")
logger.error(
f"Failed to get config for pot {self.account}: {response.text}"
)
else:
config = response.json()
print(config)
self.protocol_fee_basis_points = config.get("protocol_fee_basis_points")
acct, created = Account.objects.get_or_create(id=config.get("protocol_fee_recipient_account"))
acct, created = Account.objects.get_or_create(
id=config.get("protocol_fee_recipient_account")
)
self.protocol_fee_recipient = acct
self.require_whitelist = config.get("require_whitelist")
self.owner, created = Account.objects.get_or_create(id=config.get("owner"))
self.owner, created = Account.objects.get_or_create(
id=config.get("owner")
)
self.admins.clear()
for admin_id in config.get("admins"):
self.admins.add(Account.objects.get_or_create(id=admin_id)[0])
self.whitelisted_deployers.clear()
for deployer_id in config.get("whitelisted_deployers"):
self.whitelisted_deployers.add(Account.objects.get_or_create(id=deployer_id)[0])
self.whitelisted_deployers.add(
Account.objects.get_or_create(id=deployer_id)[0]
)
self.save()
except Exception as e:
logger.error(f"Failed to update factory config, Error: {e}")



class Pot(models.Model):
account = models.OneToOneField(
Account,
Expand Down Expand Up @@ -313,39 +321,65 @@ class Meta:
name="idx_matching_period",
),
]

def update_configs(self):
try:
url = f"{settings.FASTNEAR_RPC_URL}/account/{self.account.id}/view/get_config"
url = (
f"{settings.FASTNEAR_RPC_URL}/account/{self.account.id}/view/get_config"
)
response = requests.get(url)
if response.status_code != 200:
logger.error(f"Failed to get config for pot {self.account}: {response.text}")
logger.error(
f"Failed to get config for pot {self.account}: {response.text}"
)
else:
config = response.json()
print(config)
self.owner, created = Account.objects.get_or_create(id=config.get("owner"))
self.owner, created = Account.objects.get_or_create(
id=config.get("owner")
)
self.admins.clear()
for admin_id in config.get("admins", []):
self.admins.add(Account.objects.get_or_create(id=admin_id)[0])
self.chef, created = Account.objects.get_or_create(id=config.get("chef"))
self.chef, created = Account.objects.get_or_create(
id=config.get("chef")
)
self.name = config.get("pot_name")
self.description = config.get("pot_description")
self.max_approved_applicants = config.get("max_projects")
self.base_currency = config.get("base_currency")
self.application_start = datetime.fromtimestamp(config.get("application_start_ms") / 1000)
self.application_end = datetime.fromtimestamp(config.get("application_end_ms") / 1000)
self.matching_round_start = datetime.fromtimestamp(config.get("public_round_start_ms") / 1000)
self.matching_round_end = datetime.fromtimestamp(config.get("public_round_end_ms") / 1000)
self.application_start = datetime.fromtimestamp(
config.get("application_start_ms") / 1000
)
self.application_end = datetime.fromtimestamp(
config.get("application_end_ms") / 1000
)
self.matching_round_start = datetime.fromtimestamp(
config.get("public_round_start_ms") / 1000
)
self.matching_round_end = datetime.fromtimestamp(
config.get("public_round_end_ms") / 1000
)
self.registry_provider = config.get("registry_provider")
self.min_matching_pool_donation_amount = config.get("min_matching_pool_donation_amount")
self.min_matching_pool_donation_amount = config.get(
"min_matching_pool_donation_amount"
)
self.sybil_wrapper_provider = config.get("sybil_wrapper_provider")
self.custom_sybil_checks = config.get("custom_sybil_checks")
self.custom_min_threshold_score = config.get("custom_min_threshold_score")
self.referral_fee_matching_pool_basis_points = config.get("referral_fee_matching_pool_basis_points")
self.referral_fee_public_round_basis_points = config.get("referral_fee_public_round_basis_points")
self.custom_min_threshold_score = config.get(
"custom_min_threshold_score"
)
self.referral_fee_matching_pool_basis_points = config.get(
"referral_fee_matching_pool_basis_points"
)
self.referral_fee_public_round_basis_points = config.get(
"referral_fee_public_round_basis_points"
)
self.chef_fee_basis_points = config.get("chef_fee_basis_points")
if config.get("cooldown_end_ms"):
self.cooldown_end = datetime.fromtimestamp(config.get("cooldown_end_ms") / 1000)
self.cooldown_end = datetime.fromtimestamp(
config.get("cooldown_end_ms") / 1000
)
self.all_paid_out = config.get("all_paid_out")
self.protocol_config_provider = config.get("protocol_config_provider")
self.save()
Expand Down Expand Up @@ -545,7 +579,9 @@ def fetch_usd_prices(self):
return
self.amount_paid_usd = token.format_price(self.amount) * price_usd
self.save()
logger.info(f"Saved USD prices for pot payout for pot id: {self.pot.account}")
logger.info(
f"Saved USD prices for pot payout for pot id: {self.pot.account}"
)
except Exception as e:
logger.error(f"Failed to calculate and save USD prices: {e}")

Expand Down Expand Up @@ -593,6 +629,11 @@ class Meta:

unique_together = (("challenger", "pot"),)

class Meta:
verbose_name_plural = "Payout Challenges"

unique_together = (("challenger", "pot"),)


class PotPayoutChallengeAdminResponse(models.Model):
id = models.AutoField(
Expand Down

0 comments on commit c5d69df

Please sign in to comment.