Skip to content

Commit

Permalink
chore: minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
albertchon committed Nov 25, 2022
1 parent eba90d4 commit 873e13f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions contracts/cw20-adapter/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub struct AdapterDenom {
pub cw20_addr: String,
}

const FACTORY_PREFIX: &str = "factory/";

impl AdapterDenom {
pub fn new<S>(denom: S) -> Result<Self, ContractError>
where
Expand All @@ -23,10 +25,13 @@ impl AdapterDenom {
if denom.len() != 93 {
return Err(ContractError::NotCw20Address);
}
if !denom.starts_with("factory/") {
if !denom.starts_with(FACTORY_PREFIX) {
return Err(ContractError::NotCw20Address);
}
// adapter address starts from index 8 and ends at 50 since "factory/" is 8 characters
// and inj addresses have 42 characters
let adapter_part = &denom[8..50];
// remaining portion is the cw20 address
let cw20_part = &denom[51..];
Ok::<Result<AdapterDenom, ContractError>, ContractError>(AdapterDenom::from_components(adapter_part, cw20_part))?
}
Expand Down Expand Up @@ -67,7 +72,7 @@ pub fn get_denom(adapter_address: &Addr, cw20addr: &Addr) -> String {
}

fn get_denom_from_str(adapter_address: &str, cw20addr: &str) -> String {
format!("factory/{}/{}", adapter_address, cw20addr)
format!("{}{}/{}", FACTORY_PREFIX, adapter_address, cw20addr)
}

pub fn query_denom_creation_fee(querier_wrapper: &QuerierWrapper<InjectiveQueryWrapper>) -> StdResult<Vec<Coin>> {
Expand Down
1 change: 1 addition & 0 deletions contracts/cw20-adapter/src/execute_register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn handle_register_msg(
}

let mut provided_funds = info.funds.iter();

for required_coin in &required_funds {
let pf = provided_funds
.find(|c| -> bool { c.denom == required_coin.denom })
Expand Down

0 comments on commit 873e13f

Please sign in to comment.