Skip to content

Commit

Permalink
feat(vxASTRO): jail remote outpost in case of malicious activity (#113)
Browse files Browse the repository at this point in the history
* feat(vxASTRO): jail remote outpost in case of malicious activity

* add schemas; bump deps and minor refactoring
  • Loading branch information
epanchee authored Oct 1, 2024
1 parent da888fc commit d79c58e
Show file tree
Hide file tree
Showing 24 changed files with 495 additions and 74 deletions.
12 changes: 11 additions & 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
Expand Up @@ -23,7 +23,7 @@ cw-storage-plus.workspace = true
cosmwasm-schema.workspace = true
thiserror.workspace = true
itertools.workspace = true
astroport-governance = { path = "../../packages/astroport-governance", version = "4.0.0" }
astroport-governance = { path = "../../packages/astroport-governance", version = "4.2" }
astroport.workspace = true
neutron-sdk = "0.10.0"
serde_json = "1"
Expand Down
77 changes: 34 additions & 43 deletions contracts/emissions_controller/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ use neutron_sdk::bindings::query::NeutronQuery;

use astroport_governance::emissions_controller::consts::{EPOCH_LENGTH, IBC_TIMEOUT};
use astroport_governance::emissions_controller::hub::{
AstroPoolConfig, HubMsg, OutpostInfo, OutpostParams, OutpostStatus, TuneInfo, UserInfo,
VotedPoolInfo,
AstroPoolConfig, HubMsg, InputOutpostParams, OutpostInfo, OutpostParams, OutpostStatus,
TuneInfo, UserInfo, VotedPoolInfo,
};
use astroport_governance::emissions_controller::msg::{ExecuteMsg, VxAstroIbcMsg};
use astroport_governance::emissions_controller::utils::{check_lp_token, get_voting_power};
use astroport_governance::utils::check_contract_supports_channel;
use astroport_governance::utils::{
check_contract_supports_channel, determine_ics20_escrow_address,
};
use astroport_governance::{assembly, voting_escrow};

use crate::error::ContractError;
Expand All @@ -31,9 +33,8 @@ use crate::state::{
USER_INFO, VOTED_POOLS,
};
use crate::utils::{
build_emission_ibc_msg, determine_outpost_prefix, get_epoch_start, get_outpost_prefix,
min_ntrn_ibc_fee, raw_emissions_to_schedules, simulate_tune, validate_outpost_prefix,
TuneResult,
build_emission_ibc_msg, get_epoch_start, get_outpost_prefix, jail_outpost, min_ntrn_ibc_fee,
raw_emissions_to_schedules, simulate_tune, validate_outpost_prefix, TuneResult,
};

/// Exposes all the execute functions available in the contract.
Expand Down Expand Up @@ -149,7 +150,7 @@ pub fn execute(
outpost_params,
astro_pool_config,
),
HubMsg::JailOutpost { prefix } => jail_outpost(deps, env, info, prefix),
HubMsg::JailOutpost { prefix } => jail_outpost_endpoint(deps, env, info, prefix),
HubMsg::UnjailOutpost { prefix } => unjail_outpost(deps, info, prefix),
HubMsg::TunePools {} => tune_pools(deps, env),
HubMsg::RetryFailedOutposts {} => retry_failed_outposts(deps, info, env),
Expand Down Expand Up @@ -251,7 +252,7 @@ pub fn update_outpost(
info: MessageInfo,
prefix: String,
astro_denom: String,
outpost_params: Option<OutpostParams>,
outpost_params: Option<InputOutpostParams>,
astro_pool_config: Option<AstroPoolConfig>,
) -> Result<Response<NeutronMsg>, ContractError> {
nonpayable(&info)?;
Expand Down Expand Up @@ -308,20 +309,37 @@ pub fn update_outpost(
Some(OutpostInfo { jailed: true, .. }) => Err(ContractError::JailedOutpost {
prefix: prefix.clone(),
}),
_ => Ok(OutpostInfo {
params: outpost_params,
astro_denom,
astro_pool_config,
jailed: false,
}),
_ => {
let params = outpost_params
.map(|params| -> StdResult<_> {
Ok(OutpostParams {
emissions_controller: params.emissions_controller,
voting_channel: params.voting_channel,
escrow_address: determine_ics20_escrow_address(
deps.api,
"transfer",
&params.ics20_channel,
)?,
ics20_channel: params.ics20_channel,
})
})
.transpose()?;

Ok(OutpostInfo {
params,
astro_denom,
astro_pool_config,
jailed: false,
})
}
})?;

Ok(Response::default().add_attributes([("action", "update_outpost"), ("prefix", &prefix)]))
}

/// Jails outpost as well as removes all whitelisted
/// and being voted pools related to this outpost.
pub fn jail_outpost(
pub fn jail_outpost_endpoint(
deps: DepsMut<NeutronQuery>,
env: Env,
info: MessageInfo,
Expand All @@ -331,34 +349,7 @@ pub fn jail_outpost(
let config = CONFIG.load(deps.storage)?;
ensure!(info.sender == config.owner, ContractError::Unauthorized {});

// Remove all votable pools related to this outpost
let voted_pools = VOTED_POOLS
.keys(deps.storage, None, None, Order::Ascending)
.collect::<StdResult<Vec<_>>>()?;
let prefix_some = Some(prefix.clone());
voted_pools
.iter()
.filter(|pool| determine_outpost_prefix(pool) == prefix_some)
.try_for_each(|pool| VOTED_POOLS.remove(deps.storage, pool, env.block.time.seconds()))?;

// And clear whitelist
POOLS_WHITELIST.update::<_, StdError>(deps.storage, |mut whitelist| {
whitelist.retain(|pool| determine_outpost_prefix(pool) != prefix_some);
Ok(whitelist)
})?;

OUTPOSTS.update(deps.storage, &prefix, |outpost| {
if let Some(outpost) = outpost {
Ok(OutpostInfo {
jailed: true,
..outpost
})
} else {
Err(ContractError::OutpostNotFound {
prefix: prefix.clone(),
})
}
})?;
jail_outpost(deps.storage, &prefix, env)?;

Ok(Response::default().add_attributes([("action", "jail_outpost"), ("prefix", &prefix)]))
}
Expand Down
Loading

0 comments on commit d79c58e

Please sign in to comment.