diff --git a/contracts/cw20-adapter/src/common.rs b/contracts/cw20-adapter/src/common.rs index 082f2ac..e15d88e 100644 --- a/contracts/cw20-adapter/src/common.rs +++ b/contracts/cw20-adapter/src/common.rs @@ -13,6 +13,8 @@ pub struct AdapterDenom { pub cw20_addr: String, } +const FACTORY_PREFIX: &str = "factory/"; + impl AdapterDenom { pub fn new(denom: S) -> Result where @@ -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::, ContractError>(AdapterDenom::from_components(adapter_part, cw20_part))? } @@ -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) -> StdResult> { diff --git a/contracts/cw20-adapter/src/execute_register.rs b/contracts/cw20-adapter/src/execute_register.rs index d299f93..c1c8b18 100644 --- a/contracts/cw20-adapter/src/execute_register.rs +++ b/contracts/cw20-adapter/src/execute_register.rs @@ -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 })