Skip to content

Commit

Permalink
Update drop reference and fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
albertandrejev committed Aug 7, 2024
1 parent df76590 commit e987bdd
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 31 deletions.
17 changes: 12 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ cw-utils = "1.0.3"
cw-multi-test = "0.20.0"
ibc-proto = { version = "0.32.1", default-features = false }
lido-satellite = { git = "https://github.com/hadronlabs-org/lido-satellite", branch = "main", features = ["library"] }
drop-factory = { git = "https://github.com/hadronlabs-org/drop-contracts.git", branch = "main", features = ["library"] }
drop-staking-base = { git = "https://github.com/hadronlabs-org/drop-contracts.git", branch = "main", features = ["library"] }
drop-factory = { git = "https://github.com/hadronlabs-org/drop-contracts.git", branch = "feat/audit-fixes", features = ["library"] }
drop-staking-base = { git = "https://github.com/hadronlabs-org/drop-contracts.git", branch = "feat/audit-fixes", features = ["library"] }
neutron-proto = { version = "0.1.1", default-features = false, features = ["cosmwasm"] }
neutron-sdk = "0.10.0"
osmosis-std = "0.15.3"
Expand Down
46 changes: 31 additions & 15 deletions contracts/adapters/swap/drop/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::{
error::{ContractError, ContractResult},
state::{BONDED_DENOM, DROP_CORE_CONTRACT_ADDRESS, ENTRY_POINT_CONTRACT_ADDRESS, REMOTE_DENOM},
state::{
DROP_CORE_CONTRACT_ADDRESS, DROP_TOKEN_CONTRACT_ADDRESS, ENTRY_POINT_CONTRACT_ADDRESS,
FACTORY_BONDED_DENOM, IBC_REMOTE_DENOM,
},
};
use cosmwasm_std::{
entry_point, to_json_binary, Binary, Coin, Decimal, Deps, DepsMut, Env, MessageInfo, Response,
Expand Down Expand Up @@ -66,17 +69,27 @@ pub fn instantiate(
&deps.api.addr_validate(&drop_factory_state.core_contract)?,
)?;

DROP_TOKEN_CONTRACT_ADDRESS.save(
deps.storage,
&deps.api.addr_validate(&drop_factory_state.token_contract)?,
)?;

let drop_token_config: drop_staking_base::msg::token::ConfigResponse =
deps.querier.query_wasm_smart(
&drop_factory_state.token_contract,
&drop_staking_base::msg::token::QueryMsg::Config {},
)?;

let bonded_denom = drop_token_config.denom;

FACTORY_BONDED_DENOM.save(deps.storage, &bonded_denom)?;

let drop_core_config: drop_staking_base::state::core::Config = deps.querier.query_wasm_smart(
&checked_drop_factory_contract_address,
&drop_factory_state.core_contract,
&drop_staking_base::msg::core::QueryMsg::Config {},
)?;

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

BONDED_DENOM.save(deps.storage, &bonded_denom)?;
REMOTE_DENOM.save(deps.storage, &drop_core_config.remote_denom)?;
IBC_REMOTE_DENOM.save(deps.storage, &drop_core_config.base_denom)?;

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

///////////////
Expand Down Expand Up @@ -142,13 +155,16 @@ 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 remote_denom = REMOTE_DENOM.load(deps.storage)?;
let bonded_denom = BONDED_DENOM.load(deps.storage)?;
let remote_denom = IBC_REMOTE_DENOM.load(deps.storage)?;
let bonded_denom = FACTORY_BONDED_DENOM.load(deps.storage)?;

// Decide which message to Core contract should be emitted
let (drop_core_msg, return_denom) = if coin_in.denom == remote_denom {
(
drop_staking_base::msg::core::ExecuteMsg::Bond { receiver: None },
drop_staking_base::msg::core::ExecuteMsg::Bond {
r#ref: None,
receiver: None,
},
bonded_denom,
)
} else {
Expand Down Expand Up @@ -185,8 +201,8 @@ fn execute_swap(

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

match msg {
QueryMsg::SimulateSwapExactAssetIn { asset_in, .. } => {
Expand Down
5 changes: 3 additions & 2 deletions contracts/adapters/swap/drop/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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 DROP_TOKEN_CONTRACT_ADDRESS: Item<Addr> = Item::new("drop_token_contract_address");

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

Expand Down Expand Up @@ -44,7 +47,7 @@ struct Params {
id: 0,
msg: WasmMsg::Execute {
contract_addr: "drop_core_contract".to_string(),
msg: to_json_binary(&drop_staking_base::msg::core::ExecuteMsg::Bond{ receiver: None })?,
msg: to_json_binary(&drop_staking_base::msg::core::ExecuteMsg::Bond{ r#ref: None, receiver: None })?,
funds: vec![Coin::new(100, "ibc/uatom")],
}
.into(),
Expand Down Expand Up @@ -131,8 +134,8 @@ fn test_execute_swap(params: Params) -> ContractResult<()> {
)?;

// Store Lido Satellite denoms
REMOTE_DENOM.save(deps.as_mut().storage, &String::from("ibc/uatom"))?;
BONDED_DENOM.save(deps.as_mut().storage, &String::from("factory/uatom"))?;
IBC_REMOTE_DENOM.save(deps.as_mut().storage, &String::from("ibc/uatom"))?;
FACTORY_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::{BONDED_DENOM, DROP_CORE_CONTRACT_ADDRESS, REMOTE_DENOM},
state::{DROP_CORE_CONTRACT_ADDRESS, FACTORY_BONDED_DENOM, IBC_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
REMOTE_DENOM.save(deps.as_mut().storage, &String::from("ibc/uatom"))?;
BONDED_DENOM.save(deps.as_mut().storage, &String::from("factory/uatom"))?;
IBC_REMOTE_DENOM.save(deps.as_mut().storage, &String::from("ibc/uatom"))?;
FACTORY_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 e987bdd

Please sign in to comment.