Skip to content

Commit

Permalink
fix: remove pair message fix on pool factory
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x committed Nov 22, 2022
1 parent 1fad89a commit 9a22d65
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 33 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.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "terraswap-factory"
version = "1.1.0"
version = "1.1.1"
authors = [
"Terraform Labs, PTE.",
"DELIGHT LABS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
"additionalProperties": false
},
{
"description": "Removes pair",
"description": "Removes pair contract given asset infos",
"type": "object",
"required": [
"remove_pair"
Expand All @@ -231,11 +231,16 @@
"remove_pair": {
"type": "object",
"required": [
"pair_address"
"asset_infos"
],
"properties": {
"pair_address": {
"type": "string"
"asset_infos": {
"type": "array",
"items": {
"$ref": "#/definitions/AssetInfo"
},
"maxItems": 2,
"minItems": 2
}
},
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,28 @@ pub fn create_pair(
pub fn remove_pair(
deps: DepsMut,
_env: Env,
pair_address: String,
asset_infos: [AssetInfo; 2],
) -> Result<Response, ContractError> {
let pair_key_bytes = pair_address.as_bytes();
if let Ok(None) = PAIRS.may_load(deps.storage, pair_key_bytes) {
let raw_infos = [
asset_infos[0].to_raw(deps.api)?,
asset_infos[1].to_raw(deps.api)?,
];

let pair_key = pair_key(&raw_infos);
let pair = PAIRS.may_load(deps.storage, &pair_key)?;

let Some(pair) = pair else {
return Err(ContractError::UnExistingPair {});
}
};

PAIRS.remove(deps.storage, pair_key_bytes);
PAIRS.remove(deps.storage, &pair_key);

Ok(Response::new().add_attributes(vec![
("action", "remove_pair"),
("pair_contract_addr", &pair_address),
(
"pair_contract_addr",
deps.api.addr_humanize(&pair.contract_addr)?.as_ref(),
),
]))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn execute(
asset_infos,
pool_fees,
} => commands::create_pair(deps, env, asset_infos, pool_fees),
ExecuteMsg::RemovePair { pair_address } => commands::remove_pair(deps, env, pair_address),
ExecuteMsg::RemovePair { asset_infos } => commands::remove_pair(deps, env, asset_infos),
ExecuteMsg::AddNativeTokenDecimals { denom, decimals } => {
commands::add_native_token_decimals(deps, env, denom, decimals)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ fn delete_pair() {
&pair_key_vec,
&PairInfoRaw {
liquidity_token: CanonicalAddr(cosmwasm_std::Binary(vec![])),
contract_addr: CanonicalAddr(cosmwasm_std::Binary(vec![])),
contract_addr: deps.api.addr_canonicalize("pair0000").unwrap(),
asset_infos: raw_infos,
asset_decimals: [6, 6],
},
Expand All @@ -1130,9 +1130,7 @@ fn delete_pair() {

assert!(pair.is_ok(), "pair key should exist");

let msg = ExecuteMsg::RemovePair {
pair_address: String::from_utf8(pair_key_vec.clone()).unwrap(),
};
let msg = ExecuteMsg::RemovePair { asset_infos };
let env = mock_env();
let info = mock_info("addr0000", &[]);
let res = execute(deps.as_mut(), env, info, msg).unwrap();
Expand All @@ -1141,10 +1139,7 @@ fn delete_pair() {
res.attributes,
vec![
attr("action", "remove_pair"),
attr(
"pair_contract_addr",
String::from_utf8(pair_key_vec.clone()).unwrap(),
),
attr("pair_contract_addr", "pair0000",),
]
);

Expand All @@ -1168,16 +1163,7 @@ fn delete_pair_failed_if_not_found() {
},
];

let raw_infos = [
asset_infos[0].to_raw(&deps.api).unwrap(),
asset_infos[1].to_raw(&deps.api).unwrap(),
];

let pair_key_vec = pair_key(&raw_infos);

let msg = ExecuteMsg::RemovePair {
pair_address: String::from_utf8(pair_key_vec.clone()).unwrap(),
};
let msg = ExecuteMsg::RemovePair { asset_infos };
let env = mock_env();
let info = mock_info("addr0000", &[]);
let res = execute(deps.as_mut(), env, info, msg);
Expand Down
4 changes: 2 additions & 2 deletions packages/terraswap/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub enum ExecuteMsg {
contract: String,
code_id: Option<u64>,
},
/// Removes pair
RemovePair { pair_address: String },
/// Removes pair contract given asset infos
RemovePair { asset_infos: [AssetInfo; 2] },
}

#[cw_serde]
Expand Down

0 comments on commit 9a22d65

Please sign in to comment.