Skip to content

Commit

Permalink
feat(em. controller): add bulk whitelist check
Browse files Browse the repository at this point in the history
  • Loading branch information
epanchee committed Nov 5, 2024
1 parent c4a954d commit 93be538
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/emissions_controller/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion contracts/emissions_controller/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, Contra

match contract_version.contract.as_ref() {
CONTRACT_NAME => match contract_version.version.as_ref() {
"1.1.0" => Ok(()),
"1.1.0" | "1.1.1" => Ok(()),
_ => Err(ContractError::MigrationError {}),
},
_ => Err(ContractError::MigrationError {}),
Expand Down
11 changes: 11 additions & 0 deletions contracts/emissions_controller/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ pub fn query(deps: Deps<NeutronQuery>, env: Env, msg: QueryMsg) -> Result<Binary

Ok(to_json_binary(pools_whitelist)?)
}
QueryMsg::CheckWhitelist { lp_tokens } => {
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();

Expand Down
7 changes: 7 additions & 0 deletions contracts/emissions_controller/tests/common/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,13 @@ impl ControllerHelper {
)
}

pub fn check_whitelist(&self, lp_tokens: Vec<String>) -> StdResult<Vec<(String, bool)>> {
self.app.wrap().query_wasm_smart(
&self.emission_controller,
&emissions_controller::hub::QueryMsg::CheckWhitelist { lp_tokens },
)
}

pub fn query_pools_vp(&self, limit: Option<u8>) -> StdResult<Vec<(String, Uint128)>> {
self.query_voted_pools(limit).map(|res| {
res.into_iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions packages/astroport-governance/src/emissions_controller/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ pub enum QueryMsg {
limit: Option<u8>,
start_after: Option<String>,
},
/// 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<String> },
/// 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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#",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
25 changes: 25 additions & 0 deletions schemas/astroport-emissions-controller/raw/query.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 93be538

Please sign in to comment.