strideutils 0.1.7__tar.gz → 0.1.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: strideutils
3
- Version: 0.1.7
3
+ Version: 0.1.8
4
4
  Summary:
5
5
  Author: Your Name
6
6
  Author-email: you@example.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "strideutils"
3
- version = "0.1.7"
3
+ version = "0.1.8"
4
4
  description = ""
5
5
  authors = ["Your Name <you@example.com>"]
6
6
  readme = "README.md"
@@ -15,6 +15,9 @@ from strideutils import stride_upstash
15
15
  from strideutils.stride_config import config
16
16
 
17
17
  ACCOUNT_QUERY = "cosmos/auth/v1beta1/accounts/{address}"
18
+ ACCOUNT_BALANCE_QUERY = 'cosmos/bank/v1beta1/balances/{address}'
19
+ ACCOUNT_DELEGATIONS_QUERY = 'cosmos/staking/v1beta1/delegations/{delegator_address}'
20
+ ACCOUNT_UNBONDINGS_QUERY = "cosmos/staking/v1beta1/delegators/{delegator_address}/unbonding_delegations"
18
21
  TX_QUERY = "cosmos/tx/v1beta1/txs?events=tx.acc_seq%3D%27{address}/{sequence}%27"
19
22
 
20
23
  HOST_ZONE_QUERY = "Stride-Labs/stride/stakeibc/host_zone"
@@ -287,10 +290,10 @@ def get_celestia_redemption_records(
287
290
  Queries the celestia redemption records from staketia
288
291
  Optionally include archive records
289
292
  """
290
- params = {}
293
+ params: Dict[str, Any] = {}
291
294
  if address:
292
295
  params["address"] = address
293
- if unbonding_record_id:
296
+ if unbonding_record_id is not None:
294
297
  params["unbonding_record_id"] = unbonding_record_id
295
298
 
296
299
  url = f"{config.stride.api_endpoint}/{STAKETIA_REDEMPTION_RECORDS_QUERY}"
@@ -370,7 +373,7 @@ def get_balance(address: str, block_height: int = 0, api_endpoint: str = config.
370
373
  Returns the balance of the given address across all tokens,
371
374
  returned as a dictionary of token -> balance
372
375
  """
373
- url = f"{api_endpoint}/cosmos/bank/v1beta1/balances/{address}"
376
+ url = f"{api_endpoint}/{ACCOUNT_BALANCE_QUERY.format(address=address)}"
374
377
  balance_list = request(url, block_height=block_height)['balances']
375
378
  out = {x['denom']: int(x['amount']) for x in balance_list}
376
379
  return out
@@ -565,18 +568,73 @@ def get_sttoken_apr(token: str) -> Optional[float]:
565
568
  def get_delegated_tokens_on_address(
566
569
  delegator_address: str,
567
570
  api_endpoint: str = config.stride.api_endpoint,
568
- ) -> Dict[str, float]:
571
+ ) -> Dict[str, int]:
569
572
  """
570
573
  Returns a dict mapping from "validator_address" to "num tokens delegated", given a delegator address
574
+
575
+ Raw response example (stake_endpoint)
576
+ {
577
+ "delegation_responses": [
578
+ {"delegation": {
579
+ "delegator_address": "cosmos10...28",
580
+ "validator_address": "cosmosvaloper1p..r2qs",
581
+ "shares":"1.180957009445999997"},
582
+ "balance":{"denom":"uatom","amount":"1"}
583
+ }, ...],
584
+ "pagination": {...}
585
+ }
586
+
587
+ Returns
588
+ e.g. {'valoper1': 10, 'valoper2': 20}
571
589
  """
572
- stake_endpoint = f'{api_endpoint}/cosmos/staking/v1beta1/delegations/{delegator_address}'
573
- host_zone_balance = request(stake_endpoint)['delegation_responses']
574
- stake_amounts = {}
590
+ stake_endpoint = f'{api_endpoint}/{ACCOUNT_DELEGATIONS_QUERY.format(delegator_address=delegator_address)}'
591
+ host_zone_balance = query_list_with_pagination(stake_endpoint, rel_key='delegation_responses')
592
+ stake_amounts: Dict[str, int] = {}
575
593
  for hzb in host_zone_balance:
576
- stake_amounts[hzb['delegation']['validator_address']] = float(hzb['balance']['amount'])
594
+ stake_amounts[hzb['delegation']['validator_address']] = int(hzb['balance']['amount'])
577
595
  return stake_amounts
578
596
 
579
597
 
598
+ def get_unbonding_tokens_on_address(
599
+ delegator_address: str,
600
+ api_endpoint: str = config.stride.api_endpoint,
601
+ ) -> Dict[str, int]:
602
+ """
603
+ Returns a dict mapping from "validator_address" to "num tokens delegated", given a delegator address
604
+
605
+ Raw response example (unbonding_endpoint)
606
+ {
607
+ "unbonding_responses": [
608
+ {
609
+ "delegator_address": "cosmos10...28",
610
+ "validator_address": "cosmosvaloper1d...h9",
611
+ "entries": [
612
+ {
613
+ "creation_height": "18749801",
614
+ "completion_time": "2024-02-06T19:00:28.676639972Z",
615
+ "initial_balance": "3727000742",
616
+ "balance": "3727000742",
617
+ "unbonding_id": "334505",
618
+ "unbonding_on_hold_ref_count": "1"
619
+ }
620
+ ]
621
+ }, ...],
622
+ "pagination": {...}
623
+ }
624
+
625
+ Returns
626
+ e.g. {'valoper1': 10, 'valoper2': 20}
627
+ """
628
+ unbonding_endpoint = f'{api_endpoint}/{ACCOUNT_UNBONDINGS_QUERY.format(delegator_address=delegator_address)}'
629
+ unbondings = query_list_with_pagination(unbonding_endpoint, rel_key='unbonding_responses')
630
+ unbonding_amounts: Dict[str, int] = {}
631
+ for unbonding in unbondings:
632
+ unbonding_amounts[unbonding['validator_address']] = sum(
633
+ int(entry['initial_balance']) for entry in unbonding['entries']
634
+ )
635
+ return unbonding_amounts
636
+
637
+
580
638
  def get_host_zone_delegations(host_zone_id: str, ground_truth_included: bool = True) -> pd.DataFrame:
581
639
  """
582
640
  Given a host zone id, returns a Dataframe of validator delegations.
File without changes