Skip to content

Commit

Permalink
Rename state variables
Browse files Browse the repository at this point in the history
  • Loading branch information
albertandrejev committed Jul 28, 2024
1 parent 9be74f9 commit df76590
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 36 deletions.
46 changes: 22 additions & 24 deletions contracts/adapters/swap/drop/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::{
error::{ContractError, ContractResult},
state::{
BRIDGED_DENOM, CANONICAL_DENOM, DROP_CORE_CONTRACT_ADDRESS, ENTRY_POINT_CONTRACT_ADDRESS,
},
state::{BONDED_DENOM, DROP_CORE_CONTRACT_ADDRESS, ENTRY_POINT_CONTRACT_ADDRESS, REMOTE_DENOM},
};
use cosmwasm_std::{
entry_point, to_json_binary, Binary, Coin, Decimal, Deps, DepsMut, Env, MessageInfo, Response,
Expand Down Expand Up @@ -73,12 +71,12 @@ pub fn instantiate(
&drop_staking_base::msg::core::QueryMsg::Config {},
)?;

let canonical_denom = drop_core_config
let bonded_denom = drop_core_config
.ld_denom
.ok_or(ContractError::CanonicalDenomNotSet {})?;
.ok_or(ContractError::BondedDenomNotSet {})?;

CANONICAL_DENOM.save(deps.storage, &canonical_denom)?;
BRIDGED_DENOM.save(deps.storage, &drop_core_config.remote_denom)?;
BONDED_DENOM.save(deps.storage, &bonded_denom)?;
REMOTE_DENOM.save(deps.storage, &drop_core_config.remote_denom)?;

Ok(Response::new()
.add_attribute("action", "instantiate")
Expand All @@ -94,8 +92,8 @@ pub fn instantiate(
"drop_core_contract_address",
drop_factory_state.core_contract,
)
.add_attribute("canonical_denom", canonical_denom)
.add_attribute("bridged_denom", drop_core_config.remote_denom))
.add_attribute("bonded_denom", bonded_denom)
.add_attribute("remote_denom", drop_core_config.remote_denom))
}

///////////////
Expand Down Expand Up @@ -144,14 +142,14 @@ fn execute_swap(
// Get coin in from the message info, error if there is not exactly one coin sent
let coin_in = one_coin(&info)?;

let bridged_denom = BRIDGED_DENOM.load(deps.storage)?;
let canonical_denom = CANONICAL_DENOM.load(deps.storage)?;
let remote_denom = REMOTE_DENOM.load(deps.storage)?;
let bonded_denom = BONDED_DENOM.load(deps.storage)?;

// Decide which message to Core contract should be emitted
let (drop_core_msg, return_denom) = if coin_in.denom == bridged_denom {
let (drop_core_msg, return_denom) = if coin_in.denom == remote_denom {
(
drop_staking_base::msg::core::ExecuteMsg::Bond { receiver: None },
canonical_denom,
bonded_denom,
)
} else {
return Err(ContractError::UnsupportedDenom);
Expand Down Expand Up @@ -187,13 +185,13 @@ fn execute_swap(

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> ContractResult<Binary> {
let bridged_denom = BRIDGED_DENOM.load(deps.storage)?;
let canonical_denom = CANONICAL_DENOM.load(deps.storage)?;
let remote_denom = REMOTE_DENOM.load(deps.storage)?;
let bonded_denom = BONDED_DENOM.load(deps.storage)?;

match msg {
QueryMsg::SimulateSwapExactAssetIn { asset_in, .. } => {
let asset_out_denom =
get_opposite_denom(asset_in.denom(), &bridged_denom, &canonical_denom);
get_opposite_denom(asset_in.denom(), &remote_denom, &bonded_denom);

let exchange_rate = get_exchange_rate(deps)?;

Expand All @@ -204,7 +202,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> ContractResult<Binary> {
}
QueryMsg::SimulateSwapExactAssetOut { asset_out, .. } => {
let asset_in_denom =
get_opposite_denom(asset_out.denom(), &bridged_denom, &canonical_denom);
get_opposite_denom(asset_out.denom(), &remote_denom, &bonded_denom);

let exchange_rate = get_exchange_rate(deps)?;

Expand All @@ -219,7 +217,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> ContractResult<Binary> {
..
} => {
let asset_out_denom =
get_opposite_denom(asset_in.denom(), &bridged_denom, &canonical_denom);
get_opposite_denom(asset_in.denom(), &remote_denom, &bonded_denom);

let exchange_rate = get_exchange_rate(deps)?;

Expand All @@ -243,7 +241,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> ContractResult<Binary> {
..
} => {
let asset_in_denom =
get_opposite_denom(asset_out.denom(), &bridged_denom, &canonical_denom);
get_opposite_denom(asset_out.denom(), &remote_denom, &bonded_denom);

let exchange_rate = get_exchange_rate(deps)?;

Expand All @@ -263,7 +261,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> ContractResult<Binary> {
}
QueryMsg::SimulateSmartSwapExactAssetIn { asset_in, .. } => {
let asset_out_denom =
get_opposite_denom(asset_in.denom(), &bridged_denom, &canonical_denom);
get_opposite_denom(asset_in.denom(), &remote_denom, &bonded_denom);

let exchange_rate = get_exchange_rate(deps)?;

Expand All @@ -278,7 +276,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> ContractResult<Binary> {
..
} => {
let asset_out_denom =
get_opposite_denom(asset_in.denom(), &bridged_denom, &canonical_denom);
get_opposite_denom(asset_in.denom(), &remote_denom, &bonded_denom);

let exchange_rate = get_exchange_rate(deps)?;

Expand All @@ -300,10 +298,10 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> ContractResult<Binary> {
.map_err(From::from)
}

fn get_opposite_denom(denom: &str, bridged_denom: &str, canonical_denom: &str) -> String {
fn get_opposite_denom(denom: &str, remote_denom: &str, bonded_denom: &str) -> String {
match denom {
denom if denom == bridged_denom => canonical_denom.to_string(),
denom if denom == canonical_denom => bridged_denom.to_string(),
denom if denom == remote_denom => bonded_denom.to_string(),
denom if denom == bonded_denom => remote_denom.to_string(),
_ => unimplemented!(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/adapters/swap/drop/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ pub enum ContractError {
#[error("this denom is not supported by Drop")]
UnsupportedDenom,

#[error("canonical denom was not set")]
CanonicalDenomNotSet,
#[error("bonded denom was not set")]
BondedDenomNotSet,
}
4 changes: 2 additions & 2 deletions contracts/adapters/swap/drop/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ use cw_storage_plus::Item;
pub const ENTRY_POINT_CONTRACT_ADDRESS: Item<Addr> = Item::new("entry_point_contract_address");
pub const DROP_CORE_CONTRACT_ADDRESS: Item<Addr> = Item::new("drop_core_contract_address");

pub const CANONICAL_DENOM: Item<String> = Item::new("canonical_denom");
pub const BRIDGED_DENOM: Item<String> = Item::new("bridged_denom");
pub const BONDED_DENOM: Item<String> = Item::new("bonded_denom");
pub const REMOTE_DENOM: Item<String> = Item::new("remote_denom");
8 changes: 3 additions & 5 deletions contracts/adapters/swap/drop/tests/test_execute_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use cosmwasm_std::{
use skip::swap::ExecuteMsg;
use skip_api_swap_adapter_drop::{
error::{ContractError, ContractResult},
state::{
BRIDGED_DENOM, CANONICAL_DENOM, DROP_CORE_CONTRACT_ADDRESS, ENTRY_POINT_CONTRACT_ADDRESS,
},
state::{BONDED_DENOM, DROP_CORE_CONTRACT_ADDRESS, ENTRY_POINT_CONTRACT_ADDRESS, REMOTE_DENOM},
};
use test_case::test_case;

Expand Down Expand Up @@ -133,8 +131,8 @@ fn test_execute_swap(params: Params) -> ContractResult<()> {
)?;

// Store Lido Satellite denoms
BRIDGED_DENOM.save(deps.as_mut().storage, &String::from("ibc/uatom"))?;
CANONICAL_DENOM.save(deps.as_mut().storage, &String::from("factory/uatom"))?;
REMOTE_DENOM.save(deps.as_mut().storage, &String::from("ibc/uatom"))?;
BONDED_DENOM.save(deps.as_mut().storage, &String::from("factory/uatom"))?;

// Call execute_swap with the given test parameters
let res = skip_api_swap_adapter_drop::contract::execute(
Expand Down
6 changes: 3 additions & 3 deletions contracts/adapters/swap/drop/tests/test_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cosmwasm_std::{
use skip::{asset::Asset, swap::QueryMsg};
use skip_api_swap_adapter_drop::{
error::ContractResult,
state::{BRIDGED_DENOM, CANONICAL_DENOM, DROP_CORE_CONTRACT_ADDRESS},
state::{BONDED_DENOM, DROP_CORE_CONTRACT_ADDRESS, REMOTE_DENOM},
};
use test_case::test_case;

Expand Down Expand Up @@ -176,8 +176,8 @@ fn test_queries(params: Params) -> ContractResult<()> {
)?;

// Store Lido Satellite denoms
BRIDGED_DENOM.save(deps.as_mut().storage, &String::from("ibc/uatom"))?;
CANONICAL_DENOM.save(deps.as_mut().storage, &String::from("factory/uatom"))?;
REMOTE_DENOM.save(deps.as_mut().storage, &String::from("ibc/uatom"))?;
BONDED_DENOM.save(deps.as_mut().storage, &String::from("factory/uatom"))?;

// Call execute_swap with the given test parameters
let res = skip_api_swap_adapter_drop::contract::query(deps.as_ref(), env, params.query.clone())
Expand Down

0 comments on commit df76590

Please sign in to comment.