Skip to content

Commit

Permalink
oh
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Nov 28, 2023
1 parent eca2c92 commit ad280f5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@ neutron-sdk = { version = "^0.7.0", default-features = false }
osmosis-std = { version = "^0.20.1", default-features = false }

astroport-router = { version = "^1.2.0", default-features = false }

2 changes: 2 additions & 0 deletions contracts/cosmwasm/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ cvm-runtime = { path = "../../../crates/cvm-runtime", features = [
ibc-apps-more = { workspace = true, default-features = false, features = [
"cosmwasm",
] }
osmosis-std = { workspace = true, default-features = false }

astroport-router = { workspace = true, default-features = false }
16 changes: 8 additions & 8 deletions contracts/cosmwasm/executor/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ use cosmwasm_std::{
use cvm_runtime::{
apply_bindings,
gateway::{AssetReference, BridgeExecuteProgramMsg, BridgeForwardMsg},
service::dex::{
osmosis_std::types::osmosis::poolmanager::v1beta1::SwapAmountInRoute, ExchangeId,
},
service::dex::ExchangeId,
shared, Amount, BindingValue, Destination, Funds, Instruction, NetworkId, Register,
};
use cw2::{ensure_from_older_version, set_contract_version};
Expand Down Expand Up @@ -224,9 +222,7 @@ fn interpret_exchange(
.get_exchange_by_id(deps.querier, exchange_id)
.map_err(ContractError::ExchangeNotFound)?;

use cvm_runtime::service::dex::{
osmosis_std::types::osmosis::poolmanager::v1beta1::MsgSwapExactAmountIn, ExchangeType::*,
};
use cvm_runtime::service::dex::ExchangeType::*;
use prost::Message;
ensure_eq!(
give.0.len(),
Expand Down Expand Up @@ -275,20 +271,24 @@ fn interpret_exchange(
};

let response = match exchange.exchange {
OsmosisCrossChainSwap { pool_id, .. } => {
OsmosisPoolManagerModuleV1Beta1 { pool_id, .. } => {
use cvm_runtime::service::dex::osmosis_std::types::osmosis::poolmanager::v1beta1::*;
use prost::Message;
let msg = MsgSwapExactAmountIn {
routes: vec![SwapAmountInRoute {
pool_id,
token_out_denom: want.denom,
}],

sender: sender.to_string(),
token_in: Some(give),
token_out_min_amount: want.amount,
};

deps.api
.debug(&format!("cvm::executor::execute::exchange {:?}", &msg));
let msg = CosmosMsg::Stargate {
type_url: MsgSwapExactAmountIn::PROTO_MESSAGE_URL.to_string(),
type_url: MsgSwapExactAmountIn::TYPE_URL.to_string(),
value: Binary::from(msg.encode_to_vec()),
};
let msg = SubMsg::reply_always(msg, EXCHANGE_ID);
Expand Down
4 changes: 2 additions & 2 deletions crates/cvm-runtime/src/service/dex/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::{prelude::*, NetworkId};

pub mod osmosis_std;

pub type ExchangeId = crate::shared::Displayed<u128>;

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "snake_case")]
pub enum ExchangeType {
OsmosisCrossChainSwap {
#[cfg(feature = "cosmwasm")]
OsmosisPoolManagerModuleV1Beta1 {
pool_id: u64,
token_a: String,
token_b: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct MsgSwapExactAmountIn {
}

impl MsgSwapExactAmountIn {
pub const PROTO_MESSAGE_URL: &'static str = "/osmosis.poolmanager.v1beta1.MsgSwapExactAmountIn";
pub const TYPE_URL: &'static str = "/osmosis.poolmanager.v1beta1.MsgSwapExactAmountIn";
}

#[allow(clippy::derive_partial_eq_without_eq)]
Expand All @@ -30,5 +30,5 @@ pub struct SwapAmountInRoute {
}

impl SwapAmountInRoute {
pub const PROTO_MESSAGE_URL: &'static str = "/osmosis.poolmanager.v1beta1.SwapAmountInRoute";
pub const TYPE_URL: &'static str = "/osmosis.poolmanager.v1beta1.SwapAmountInRoute";
}

0 comments on commit ad280f5

Please sign in to comment.