strideutils 0.4.2__tar.gz → 0.4.4__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.
Files changed (33) hide show
  1. {strideutils-0.4.2 → strideutils-0.4.4}/PKG-INFO +1 -1
  2. {strideutils-0.4.2 → strideutils-0.4.4}/pyproject.toml +1 -1
  3. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/stride_config.py +1 -0
  4. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/stride_requests.py +53 -36
  5. {strideutils-0.4.2 → strideutils-0.4.4}/README.md +0 -0
  6. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/Makefile +0 -0
  7. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/__init__.py +0 -0
  8. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/coingecko.py +0 -0
  9. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/config_examples/strideutils_config.yaml.example +0 -0
  10. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/config_examples/strideutils_secrets.yaml.example +0 -0
  11. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/cryptography.py +0 -0
  12. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/exec_tx.py +0 -0
  13. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/invariant_helpers.py +0 -0
  14. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/run_safely.py +0 -0
  15. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/sheets_connector.py +0 -0
  16. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/slack_connector.py +0 -0
  17. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/stride_alerts.py +0 -0
  18. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/stride_upstash.py +0 -0
  19. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/twilio_connector.py +0 -0
  20. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils/types.py +0 -0
  21. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils-stubs/__init__.pyi +0 -0
  22. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils-stubs/coingecko.pyi +0 -0
  23. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils-stubs/cryptography.pyi +0 -0
  24. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils-stubs/exec_tx.pyi +0 -0
  25. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils-stubs/invariant_helpers.pyi +0 -0
  26. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils-stubs/run_safely.pyi +0 -0
  27. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils-stubs/sheets_connector.pyi +0 -0
  28. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils-stubs/slack_connector.pyi +0 -0
  29. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils-stubs/stride_alerts.pyi +0 -0
  30. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils-stubs/stride_config.pyi +0 -0
  31. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils-stubs/stride_requests.pyi +0 -0
  32. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils-stubs/stride_upstash.pyi +0 -0
  33. {strideutils-0.4.2 → strideutils-0.4.4}/strideutils-stubs/twilio_connector.pyi +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: strideutils
3
- Version: 0.4.2
3
+ Version: 0.4.4
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.4.2"
3
+ version = "0.4.4"
4
4
  description = ""
5
5
  authors = ["Your Name <you@example.com>"]
6
6
  readme = "README.md"
@@ -129,6 +129,7 @@ class HostChainsConfig(ConfigObj):
129
129
  saga: HostChainConfig = field(default_factory=HostChainConfig)
130
130
  celestia: HostChainConfig = field(default_factory=HostChainConfig)
131
131
  dymension: HostChainConfig = field(default_factory=HostChainConfig)
132
+ haqq: HostChainConfig = field(default_factory=HostChainConfig)
132
133
 
133
134
 
134
135
  @dataclass(repr=False)
@@ -23,6 +23,7 @@ MODULE_ACCOUNTS_QUERY = "cosmos/auth/v1beta1/module_accounts"
23
23
  SUPPLY_QUERY = "cosmos/bank/v1beta1/supply/by_denom"
24
24
  VALIDATORS_QUERY = "cosmos/staking/v1beta1/validators"
25
25
  VALIDATOR_SLASHES_QUERY = "cosmos/distribution/v1beta1/validators/{validator_address}/slashes"
26
+ DELEGATIONS_QUERY = "cosmos/staking/v1beta1/delegations/{delegator_address}"
26
27
 
27
28
  CONNECTION_QUERY = "ibc/core/connection/v1/connections/{connection_id}"
28
29
  CHANNELS_QUERY = "ibc/core/channel/v1/connections/{connection_id}/channels"
@@ -317,7 +318,6 @@ def get_unbonding_records(
317
318
  for epoch_unbonding in epoch_unbondings:
318
319
  epoch_number = epoch_unbonding["epoch_number"]
319
320
  for host_zone_unbonding in epoch_unbonding["host_zone_unbondings"]:
320
-
321
321
  chain_id_match = host_zone_unbonding["host_zone_id"] == chain_id
322
322
  status_match = not status or host_zone_unbonding["status"] == status
323
323
 
@@ -588,7 +588,6 @@ def get_callback_data(
588
588
 
589
589
  filtered_callback_data = []
590
590
  for data in callback_data:
591
-
592
591
  chain_id_match = not chain_id or chain_id in data["port_id"]
593
592
  channel_id_match = not channel_id or data["channel_id"] == channel_id
594
593
  port_id_match = not port_id or data["port_id"] == port_id
@@ -623,7 +622,10 @@ def get_redemption_rate(token: str) -> float:
623
622
  """
624
623
  Queries the redemption rate for a particular token
625
624
  """
626
- host_zone = get_host_zone(config.get_chain(ticker=token).id)
625
+ chain_config_id = config.get_chain(ticker=token).id
626
+ if token == 'TIA':
627
+ chain_config_id = config.get_chain(name='celestia').id
628
+ host_zone = get_host_zone(chain_config_id)
627
629
  return float(host_zone["redemption_rate"])
628
630
 
629
631
 
@@ -984,15 +986,30 @@ def get_unbonding_tokens_on_address(
984
986
  return unbonding_amounts
985
987
 
986
988
 
987
- def get_host_zone_delegations(host_zone_id: str, ground_truth_included: bool = True) -> pd.DataFrame:
989
+ def get_delegations(delegator_address: str, api_endpoint: str = config.stride.api_endpoint) -> dict[str, int]:
990
+ """
991
+ Queries all the delegations for a given delegator
992
+ Returned as a mapping of validator addresss to delegation amount
993
+ """
994
+ url = f"{api_endpoint}/{DELEGATIONS_QUERY.format(delegator_address=delegator_address)}"
995
+ delegations = query_list_with_pagination(url, rel_key="delegation_responses")
996
+
997
+ delegations_by_validator = {}
998
+ for delegation in delegations:
999
+ validator_address = delegation["delegation"]["validator_address"]
1000
+ amount = int(delegation["balance"]["amount"])
1001
+ delegations_by_validator[validator_address] = amount
1002
+
1003
+ return delegations_by_validator
1004
+
1005
+
1006
+ def get_host_zone_delegations(host_zone_id: str, include_ground_truth: bool = True) -> pd.DataFrame:
988
1007
  """
989
1008
  Given a host zone id, returns a Dataframe of validator delegations.
990
1009
 
991
- If `ground_truth_included=True`, then will also return the "true" delegations
1010
+ If `include_ground_truth=True`, then will also return the "true" delegations
992
1011
  on the host zone delegaiton account.
993
1012
  """
994
- host_zone = get_host_zone(host_zone_id)
995
- vdf = pd.DataFrame(host_zone["validators"])
996
1013
  int_cols = [
997
1014
  "weight",
998
1015
  "delegation",
@@ -1000,36 +1017,36 @@ def get_host_zone_delegations(host_zone_id: str, ground_truth_included: bool = T
1000
1017
  "slash_query_checkpoint",
1001
1018
  "shares_to_tokens_rate",
1002
1019
  ]
1003
- for c in int_cols:
1004
- vdf[c] = vdf[c].astype(float)
1005
- vdf = vdf[
1006
- [
1007
- "name",
1008
- "address",
1009
- "weight",
1010
- "delegation",
1011
- "slash_query_in_progress",
1012
- "slash_query_progress_tracker",
1013
- "shares_to_tokens_rate",
1014
- ]
1020
+ output_cols = [
1021
+ "name",
1022
+ "address",
1023
+ "weight",
1024
+ "delegation",
1025
+ "slash_query_in_progress",
1026
+ "slash_query_progress_tracker",
1027
+ "shares_to_tokens_rate",
1015
1028
  ]
1016
- # get delegation on the host zone, if relevant
1017
- if ground_truth_included:
1018
- host_zone_delegation_account = host_zone["delegation_ica_address"]
1019
- lcd_endpoint = config.get_chain(id=host_zone_id).api_endpoint
1020
- stake_endpoint = f"{lcd_endpoint}/cosmos/staking/v1beta1/delegations/{host_zone_delegation_account}"
1021
- host_zone_balance = request(stake_endpoint)["delegation_responses"]
1022
- stake_amounts = {}
1023
- for hzb in host_zone_balance:
1024
- stake_amounts[hzb["delegation"]["validator_address"]] = float(hzb["balance"]["amount"])
1025
- stake_amounts = pd.Series(stake_amounts)
1026
- vdf["ground_delegation"] = (vdf["address"].map(stake_amounts)).fillna(0)
1027
- float_cols = ["weight", "delegation", "ground_delegation"]
1028
- for c in float_cols:
1029
- vdf[c] = vdf[c].astype(float)
1030
- filtered_vdf = vdf[(vdf["ground_delegation"] > 0) | (vdf["delegation"] > 0) | (vdf["weight"] > 0)]
1031
- vdf = filtered_vdf
1032
- return vdf
1029
+
1030
+ # Query the validator delegations on the host zone
1031
+ host_zone = get_host_zone(host_zone_id)
1032
+ validator_df = pd.DataFrame(host_zone["validators"])
1033
+ validator_df[int_cols] = validator_df[int_cols].map(lambda i: int(float(i))) # type: ignore
1034
+ validator_df = validator_df[output_cols]
1035
+
1036
+ # If the ground truth isn't requested, return as is
1037
+ if not include_ground_truth:
1038
+ return validator_df
1039
+
1040
+ # Otherwise, query the ground truth delegations from the actual host chain
1041
+ delegation_ica_account = host_zone["delegation_ica_address"]
1042
+ api_endpoint = config.get_chain(id=host_zone_id).api_endpoint
1043
+ delegations_by_validator = get_delegations(delegation_ica_account, api_endpoint=api_endpoint)
1044
+
1045
+ validator_df["ground_delegation"] = (validator_df["address"].map(delegations_by_validator)).fillna(0)
1046
+ validator_df["ground_delegation"] = validator_df["ground_delegation"].apply(int)
1047
+ validator_df["delegation_difference"] = validator_df["ground_delegation"] - validator_df["delegation"]
1048
+
1049
+ return validator_df
1033
1050
 
1034
1051
 
1035
1052
  def get_epochs() -> List[Dict]:
File without changes