Skip to content

Commit c458bf0

Browse files
Add query validators info on Hydro contract (#312)
* added round validators query to hydro contract
1 parent 7252d00 commit c458bf0

File tree

13 files changed

+233
-5
lines changed

13 files changed

+233
-5
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-Added round validators query.
2+
([\#312](https://github.com/informalsystems/hydro/pull/312))

artifacts/checksums.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
2b7af3fbd04c597f105f11335d259f228a4ecdba4698e8b1ed2e1b0d02952b53 d_token_info_provider.wasm
22
3bc9a1602da2ed04e98185ec495c500c63601c377f06f05694fb5a7e924bfd0a dao_voting_adapter.wasm
33
aec3f829e9767921fcf5e30954591b9797272500c89f048263603d8ed6cc4c9a gatekeeper.wasm
4-
8c7da0a128b0e0bad4db2183ee0ece77790e007a78f61eb73efe5906f5a77c0d hydro.wasm
4+
d5d3acf06f82dce297f7eaf420db13e453d590379704858ae63db6489d84504e hydro.wasm
55
991b7c7ec18364783d6a9ac352dcecdb978e746ebb4a82c465e3a4b3a1b16e53 inflow.wasm
66
572bc0796f94574d7e4986314274e5ce5b8c6ee813a780276cdc24b4097f39e4 liquid_collateral.wasm
7-
82c4f04193f828538c4a6c6902a95639feb24207818f33446e23c6ca8f64769d marketplace.wasm
7+
6b9adda11af72e8dc2d99435ad8972447873b584e18dc4da562b7cfccde7c62b marketplace.wasm
88
4479c8f755a22069e08da2f920c83383b9ca0ab437b75d4e65f7c14dc83aa283 st_token_info_provider.wasm
9-
272ed02a9084f595f1d9e11ee98fe03eb7e31172b2de5dd008df4bf70b49649f tribute.wasm
9+
46f7a1435410448fd54269f35299a26dda925df9ee33dbd79660fb6f730539b1 tribute.wasm

artifacts/hydro.wasm

5.31 KB
Binary file not shown.

artifacts/marketplace.wasm

213 Bytes
Binary file not shown.

artifacts/tribute.wasm

213 Bytes
Binary file not shown.

contracts/hydro/schema/hydro.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,6 +2371,29 @@
23712371
},
23722372
"additionalProperties": false
23732373
},
2374+
{
2375+
"type": "object",
2376+
"required": [
2377+
"validators_info"
2378+
],
2379+
"properties": {
2380+
"validators_info": {
2381+
"type": "object",
2382+
"required": [
2383+
"round_id"
2384+
],
2385+
"properties": {
2386+
"round_id": {
2387+
"type": "integer",
2388+
"format": "uint64",
2389+
"minimum": 0.0
2390+
}
2391+
},
2392+
"additionalProperties": false
2393+
}
2394+
},
2395+
"additionalProperties": false
2396+
},
23742397
{
23752398
"type": "object",
23762399
"required": [
@@ -5891,6 +5914,57 @@
58915914
},
58925915
"additionalProperties": false
58935916
},
5917+
"validators_info": {
5918+
"$schema": "http://json-schema.org/draft-07/schema#",
5919+
"title": "ValidatorsInfoResponse",
5920+
"type": "object",
5921+
"required": [
5922+
"round_id",
5923+
"validators"
5924+
],
5925+
"properties": {
5926+
"round_id": {
5927+
"type": "integer",
5928+
"format": "uint64",
5929+
"minimum": 0.0
5930+
},
5931+
"validators": {
5932+
"type": "object",
5933+
"additionalProperties": false
5934+
}
5935+
},
5936+
"additionalProperties": false,
5937+
"definitions": {
5938+
"Decimal": {
5939+
"description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)",
5940+
"type": "string"
5941+
},
5942+
"Uint128": {
5943+
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
5944+
"type": "string"
5945+
},
5946+
"ValidatorInfo": {
5947+
"type": "object",
5948+
"required": [
5949+
"address",
5950+
"delegated_tokens",
5951+
"power_ratio"
5952+
],
5953+
"properties": {
5954+
"address": {
5955+
"type": "string"
5956+
},
5957+
"delegated_tokens": {
5958+
"$ref": "#/definitions/Uint128"
5959+
},
5960+
"power_ratio": {
5961+
"$ref": "#/definitions/Decimal"
5962+
}
5963+
},
5964+
"additionalProperties": false
5965+
}
5966+
}
5967+
},
58945968
"voting_power_at_height": {
58955969
"$schema": "http://json-schema.org/draft-07/schema#",
58965970
"title": "VotingPowerAtHeightResponse",

contracts/hydro/schema/raw/query.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,29 @@
673673
},
674674
"additionalProperties": false
675675
},
676+
{
677+
"type": "object",
678+
"required": [
679+
"validators_info"
680+
],
681+
"properties": {
682+
"validators_info": {
683+
"type": "object",
684+
"required": [
685+
"round_id"
686+
],
687+
"properties": {
688+
"round_id": {
689+
"type": "integer",
690+
"format": "uint64",
691+
"minimum": 0.0
692+
}
693+
},
694+
"additionalProperties": false
695+
}
696+
},
697+
"additionalProperties": false
698+
},
676699
{
677700
"type": "object",
678701
"required": [
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "ValidatorsInfoResponse",
4+
"type": "object",
5+
"required": [
6+
"round_id",
7+
"validators"
8+
],
9+
"properties": {
10+
"round_id": {
11+
"type": "integer",
12+
"format": "uint64",
13+
"minimum": 0.0
14+
},
15+
"validators": {
16+
"type": "object",
17+
"additionalProperties": false
18+
}
19+
},
20+
"additionalProperties": false,
21+
"definitions": {
22+
"Decimal": {
23+
"description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)",
24+
"type": "string"
25+
},
26+
"Uint128": {
27+
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
28+
"type": "string"
29+
},
30+
"ValidatorInfo": {
31+
"type": "object",
32+
"required": [
33+
"address",
34+
"delegated_tokens",
35+
"power_ratio"
36+
],
37+
"properties": {
38+
"address": {
39+
"type": "string"
40+
},
41+
"delegated_tokens": {
42+
"$ref": "#/definitions/Uint128"
43+
},
44+
"power_ratio": {
45+
"$ref": "#/definitions/Decimal"
46+
}
47+
},
48+
"additionalProperties": false
49+
}
50+
}
51+
}

contracts/hydro/src/contract.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ use cosmwasm_std::{
1212
use cw2::set_contract_version;
1313
use cw_utils::must_pay;
1414
use interface::drop_puppeteer::{DelegationsResponse, PuppeteerQueryMsg, QueryExtMsg};
15+
use interface::token_info_provider::{
16+
ValidatorInfo as ValidatorInfoInterface, ValidatorsInfoResponse,
17+
};
1518
use neutron_sdk::bindings::msg::NeutronMsg;
1619
use neutron_sdk::bindings::query::NeutronQuery;
1720
use neutron_sdk::interchain_queries::v047::register_queries::new_register_staking_validators_query_msg;
@@ -3282,6 +3285,9 @@ pub fn query(deps: Deps<NeutronQuery>, env: Env, msg: QueryMsg) -> Result<Binary
32823285
QueryMsg::Whitelist {} => to_json_binary(&query_whitelist(deps)?),
32833286
QueryMsg::WhitelistAdmins {} => to_json_binary(&query_whitelist_admins(deps)?),
32843287
QueryMsg::TotalLockedTokens {} => to_json_binary(&query_total_locked_tokens(deps)?),
3288+
QueryMsg::ValidatorsInfo { round_id } => {
3289+
to_json_binary(&query_round_validators_info(deps, round_id)?)
3290+
}
32853291
QueryMsg::RegisteredValidatorQueries {} => {
32863292
to_json_binary(&query_registered_validator_queries(deps)?)
32873293
}
@@ -4136,6 +4142,31 @@ pub fn query_validators_per_round(
41364142
.collect())
41374143
}
41384144

4145+
pub fn query_round_validators_info(
4146+
deps: Deps<NeutronQuery>,
4147+
round_id: u64,
4148+
) -> StdResult<ValidatorsInfoResponse> {
4149+
Ok(ValidatorsInfoResponse {
4150+
round_id,
4151+
validators: VALIDATORS_INFO
4152+
.prefix(round_id)
4153+
.range(deps.storage, None, None, Order::Ascending)
4154+
.filter_map(|val_info| {
4155+
val_info.ok().map(|val_info| {
4156+
(
4157+
val_info.0,
4158+
ValidatorInfoInterface {
4159+
address: val_info.1.address,
4160+
delegated_tokens: val_info.1.delegated_tokens,
4161+
power_ratio: val_info.1.power_ratio,
4162+
},
4163+
)
4164+
})
4165+
})
4166+
.collect(),
4167+
})
4168+
}
4169+
41394170
// Checks whether the token with the given denom can be locked in Hydro. Denom can be locked if it belongs to
41404171
// a known token group that has power ratio to base denom greater than zero.
41414172
pub fn query_can_lock_denom(

contracts/hydro/src/query.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use crate::{
55
};
66
use cosmwasm_schema::{cw_serde, QueryResponses};
77
use cosmwasm_std::{Addr, Decimal, Timestamp, Uint128};
8+
#[allow(unused_imports)]
9+
use interface::token_info_provider::ValidatorsInfoResponse;
810

911
#[cw_serde]
1012
#[derive(QueryResponses, cw_orch::QueryFns)]
@@ -133,6 +135,9 @@ pub enum QueryMsg {
133135
#[returns(TotalLockedTokensResponse)]
134136
TotalLockedTokens {},
135137

138+
#[returns(ValidatorsInfoResponse)]
139+
ValidatorsInfo { round_id: u64 },
140+
136141
#[returns(RegisteredValidatorQueriesResponse)]
137142
RegisteredValidatorQueries {},
138143

0 commit comments

Comments
 (0)