diff --git a/contracts/strategy/src/contract.rs b/contracts/strategy/src/contract.rs index 119dc7a8..3f372c32 100644 --- a/contracts/strategy/src/contract.rs +++ b/contracts/strategy/src/contract.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use cosmwasm_std::{attr, entry_point, to_json_binary, Attribute, Deps, Uint128}; use cosmwasm_std::{Binary, DepsMut, Env, MessageInfo, Response, StdResult}; use cw2::set_contract_version; @@ -130,15 +132,17 @@ fn prepare_delegation_data( )?; let mut delegations: Vec = Vec::new(); + let delegation_validator_map: HashMap<_, _> = account_delegations + .delegations + .iter() + .filter(|delegation| delegation.amount.denom == denom) + .map(|delegation| (delegation.validator.clone(), delegation.amount.amount)) + .collect(); + for validator in validator_set.iter() { - let validator_denom_delegation = account_delegations - .delegations - .iter() - .find(|delegation| { - delegation.validator == validator.valoper_address - && delegation.amount.denom == denom - }) - .map(|delegation| delegation.amount.amount) + let validator_denom_delegation = delegation_validator_map + .get(&validator.valoper_address) + .copied() .unwrap_or_default(); let delegation = lido_staking_base::msg::distribution::Delegation { diff --git a/contracts/validators-stats/src/bin/lido-validators-stats-schema.rs b/contracts/validators-stats/src/bin/lido-validators-stats-schema.rs index 5ee016cd..f65cce3e 100644 --- a/contracts/validators-stats/src/bin/lido-validators-stats-schema.rs +++ b/contracts/validators-stats/src/bin/lido-validators-stats-schema.rs @@ -1,9 +1,6 @@ use cosmwasm_schema::write_api; -use lido_staking_base::{ - msg::validatorsstats::{ExecuteMsg, InstantiateMsg, MigrateMsg}, - state::validatorsstats::QueryMsg, -}; +use lido_staking_base::msg::validatorsstats::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; fn main() { write_api! { diff --git a/contracts/validators-stats/src/contract.rs b/contracts/validators-stats/src/contract.rs index 12366a64..99e4703a 100644 --- a/contracts/validators-stats/src/contract.rs +++ b/contracts/validators-stats/src/contract.rs @@ -4,10 +4,10 @@ use cosmwasm_std::{ }; use cosmwasm_std::{Binary, DepsMut, Env, MessageInfo, Response, StdResult}; use cw2::set_contract_version; -use lido_staking_base::msg::validatorsstats::{ExecuteMsg, InstantiateMsg, MigrateMsg}; +use lido_staking_base::msg::validatorsstats::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; use lido_staking_base::state::validatorsstats::{ - Config, MissedBlocks, QueryMsg, ValidatorMissedBlocksForPeriod, ValidatorState, CONFIG, - MISSED_BLOCKS, SIGNING_INFO_QUERY_ID, SIGNING_INFO_REPLY_ID, STATE_MAP, VALCONS_TO_VALOPER, + Config, MissedBlocks, ValidatorMissedBlocksForPeriod, ValidatorState, CONFIG, MISSED_BLOCKS, + SIGNING_INFO_QUERY_ID, SIGNING_INFO_REPLY_ID, STATE_MAP, VALCONS_TO_VALOPER, VALIDATOR_PROFILE_QUERY_ID, VALIDATOR_PROFILE_REPLY_ID, }; use neutron_sdk::bindings::msg::MsgRegisterInterchainQueryResponse; diff --git a/packages/base/src/msg/validatorsstats.rs b/packages/base/src/msg/validatorsstats.rs index 1eb9ab49..e3f2d026 100644 --- a/packages/base/src/msg/validatorsstats.rs +++ b/packages/base/src/msg/validatorsstats.rs @@ -1,4 +1,6 @@ -use cosmwasm_schema::cw_serde; +use cosmwasm_schema::{cw_serde, QueryResponses}; + +use crate::state::validatorsstats::{Config, ValidatorState}; #[cw_serde] pub struct InstantiateMsg { @@ -15,5 +17,14 @@ pub enum ExecuteMsg { RegisterStatsQueries { validators: Vec }, } +#[cw_serde] +#[derive(QueryResponses)] +pub enum QueryMsg { + #[returns(Config)] + Config {}, + #[returns(Vec)] + State {}, +} + #[cw_serde] pub struct MigrateMsg {} diff --git a/packages/base/src/state/validatorsstats.rs b/packages/base/src/state/validatorsstats.rs index df861c4e..5b05d313 100644 --- a/packages/base/src/state/validatorsstats.rs +++ b/packages/base/src/state/validatorsstats.rs @@ -1,4 +1,4 @@ -use cosmwasm_schema::{cw_serde, QueryResponses}; +use cosmwasm_schema::cw_serde; use cosmwasm_std::{Addr, Decimal}; use cw_storage_plus::{Item, Map}; @@ -32,15 +32,6 @@ pub struct State { pub validators: Vec, } -#[cw_serde] -#[derive(QueryResponses)] -pub enum QueryMsg { - #[returns(Config)] - Config {}, - #[returns(Vec)] - State {}, -} - #[cw_serde] pub struct ValidatorMissedBlocksForPeriod { pub address: String,