From 93be5387ccc09d4940e6db269fb5b8766fbd68bd Mon Sep 17 00:00:00 2001 From: Timofey <5527315+epanchee@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:34:05 +0300 Subject: [PATCH] feat(em. controller): add bulk whitelist check --- Cargo.lock | 2 +- contracts/emissions_controller/Cargo.toml | 2 +- .../emissions_controller/src/migration.rs | 2 +- contracts/emissions_controller/src/query.rs | 11 +++++ .../tests/common/helper.rs | 7 +++ .../tests/emissions_controller_integration.rs | 19 ++++++++ .../src/emissions_controller/hub.rs | 4 ++ .../astroport-emissions-controller.json | 45 ++++++++++++++++++- .../raw/query.json | 25 +++++++++++ 9 files changed, 113 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b17969b..ec03f2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -136,7 +136,7 @@ dependencies = [ [[package]] name = "astroport-emissions-controller" -version = "1.1.1" +version = "1.1.2" dependencies = [ "anyhow", "astro-assembly", diff --git a/contracts/emissions_controller/Cargo.toml b/contracts/emissions_controller/Cargo.toml index a5a8f72..2aeb38a 100644 --- a/contracts/emissions_controller/Cargo.toml +++ b/contracts/emissions_controller/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "astroport-emissions-controller" -version = "1.1.1" +version = "1.1.2" authors = ["Astroport"] edition = "2021" description = "Astroport vxASTRO Emissions Voting Contract" diff --git a/contracts/emissions_controller/src/migration.rs b/contracts/emissions_controller/src/migration.rs index ae61a57..75bf93f 100644 --- a/contracts/emissions_controller/src/migration.rs +++ b/contracts/emissions_controller/src/migration.rs @@ -12,7 +12,7 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result match contract_version.version.as_ref() { - "1.1.0" => Ok(()), + "1.1.0" | "1.1.1" => Ok(()), _ => Err(ContractError::MigrationError {}), }, _ => Err(ContractError::MigrationError {}), diff --git a/contracts/emissions_controller/src/query.rs b/contracts/emissions_controller/src/query.rs index bb01b76..f2f5eec 100644 --- a/contracts/emissions_controller/src/query.rs +++ b/contracts/emissions_controller/src/query.rs @@ -122,6 +122,17 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result { + let whitelist = POOLS_WHITELIST.load(deps.storage)?; + let is_whitelisted = lp_tokens + .into_iter() + .map(|lp_token| { + let is_whitelisted = whitelist.contains(&lp_token); + (lp_token, is_whitelisted) + }) + .collect_vec(); + Ok(to_json_binary(&is_whitelisted)?) + } QueryMsg::SimulateTune {} => { let deps = deps.into_empty(); diff --git a/contracts/emissions_controller/tests/common/helper.rs b/contracts/emissions_controller/tests/common/helper.rs index 47e7bab..81674be 100644 --- a/contracts/emissions_controller/tests/common/helper.rs +++ b/contracts/emissions_controller/tests/common/helper.rs @@ -573,6 +573,13 @@ impl ControllerHelper { ) } + pub fn check_whitelist(&self, lp_tokens: Vec) -> StdResult> { + self.app.wrap().query_wasm_smart( + &self.emission_controller, + &emissions_controller::hub::QueryMsg::CheckWhitelist { lp_tokens }, + ) + } + pub fn query_pools_vp(&self, limit: Option) -> StdResult> { self.query_voted_pools(limit).map(|res| { res.into_iter() diff --git a/contracts/emissions_controller/tests/emissions_controller_integration.rs b/contracts/emissions_controller/tests/emissions_controller_integration.rs index f7f672e..279abe0 100644 --- a/contracts/emissions_controller/tests/emissions_controller_integration.rs +++ b/contracts/emissions_controller/tests/emissions_controller_integration.rs @@ -225,6 +225,25 @@ fn test_whitelist() { let whitelist = helper.query_whitelist().unwrap(); assert_eq!(whitelist, vec![lp_token.to_string()]); + + let check_result = helper + .check_whitelist(vec![ + lp_token.to_string(), + "random_lp".to_string(), + "factory/neutron1invalidaddr/astroport/share".to_string(), + ]) + .unwrap(); + assert_eq!( + check_result, + vec![ + (lp_token.to_string(), true), + ("random_lp".to_string(), false), + ( + "factory/neutron1invalidaddr/astroport/share".to_string(), + false + ) + ] + ); } #[test] diff --git a/packages/astroport-governance/src/emissions_controller/hub.rs b/packages/astroport-governance/src/emissions_controller/hub.rs index ba7f262..9105c43 100644 --- a/packages/astroport-governance/src/emissions_controller/hub.rs +++ b/packages/astroport-governance/src/emissions_controller/hub.rs @@ -132,6 +132,10 @@ pub enum QueryMsg { limit: Option, start_after: Option, }, + /// CheckWhitelist checks all the pools in the list and returns whether they are whitelisted. + /// Returns array of tuples (LP token, is_whitelisted). + #[returns(Vec<(String, bool)>)] + CheckWhitelist { lp_tokens: Vec }, /// SimulateTune simulates the ASTRO amount that will be emitted in the next epoch per pool /// considering if the next epoch starts right now. /// This query is useful for the UI to show the expected ASTRO emissions diff --git a/schemas/astroport-emissions-controller/astroport-emissions-controller.json b/schemas/astroport-emissions-controller/astroport-emissions-controller.json index 2b6399a..712bbc2 100644 --- a/schemas/astroport-emissions-controller/astroport-emissions-controller.json +++ b/schemas/astroport-emissions-controller/astroport-emissions-controller.json @@ -1,6 +1,6 @@ { "contract_name": "astroport-emissions-controller", - "contract_version": "1.1.1", + "contract_version": "1.1.2", "idl_version": "1.0.0", "instantiate": { "$schema": "http://json-schema.org/draft-07/schema#", @@ -882,6 +882,31 @@ }, "additionalProperties": false }, + { + "description": "CheckWhitelist checks all the pools in the list and returns whether they are whitelisted. Returns array of tuples (LP token, is_whitelisted).", + "type": "object", + "required": [ + "check_whitelist" + ], + "properties": { + "check_whitelist": { + "type": "object", + "required": [ + "lp_tokens" + ], + "properties": { + "lp_tokens": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, { "description": "SimulateTune simulates the ASTRO amount that will be emitted in the next epoch per pool considering if the next epoch starts right now. This query is useful for the UI to show the expected ASTRO emissions as well as might be useful for integrator estimations. It filters out pools which don't belong to any of outposts and invalid Hub-based LP tokens. Returns TuneResultResponse object which contains emissions state and next pools grouped by outpost prefix.", "type": "object", @@ -901,6 +926,24 @@ "migrate": null, "sudo": null, "responses": { + "check_whitelist": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Array_of_Tuple_of_String_and_Boolean", + "type": "array", + "items": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "boolean" + } + ], + "maxItems": 2, + "minItems": 2 + } + }, "config": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Config", diff --git a/schemas/astroport-emissions-controller/raw/query.json b/schemas/astroport-emissions-controller/raw/query.json index 86bda0f..e5d3b1e 100644 --- a/schemas/astroport-emissions-controller/raw/query.json +++ b/schemas/astroport-emissions-controller/raw/query.json @@ -175,6 +175,31 @@ }, "additionalProperties": false }, + { + "description": "CheckWhitelist checks all the pools in the list and returns whether they are whitelisted. Returns array of tuples (LP token, is_whitelisted).", + "type": "object", + "required": [ + "check_whitelist" + ], + "properties": { + "check_whitelist": { + "type": "object", + "required": [ + "lp_tokens" + ], + "properties": { + "lp_tokens": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, { "description": "SimulateTune simulates the ASTRO amount that will be emitted in the next epoch per pool considering if the next epoch starts right now. This query is useful for the UI to show the expected ASTRO emissions as well as might be useful for integrator estimations. It filters out pools which don't belong to any of outposts and invalid Hub-based LP tokens. Returns TuneResultResponse object which contains emissions state and next pools grouped by outpost prefix.", "type": "object",