Skip to content

Commit

Permalink
types
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Apr 17, 2024
1 parent 2cb8578 commit c38dd93
Show file tree
Hide file tree
Showing 26 changed files with 2,580 additions and 3,466 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ sha2 = { version = "^0.10.8", default-features = false }

thiserror = { version = "^1.0.50", default-features = false, package = "thiserror-core" }
# no XCM until it has decent support for cosmwasm and wasm32 std https://github.com/paritytech/polkadot-sdk/pull/1454
# xcm = { version = "^5.0.0", default-features = false, package = "staging-xcm" }
# xcm = { version = "11.0.0", default-features = false, package = "staging-xcm" }
cw-utils = { version = "^1.0.3", default-features = false }
cw2 = { version = "^1.1.2", default-features = false }

Expand All @@ -148,9 +148,11 @@ ibc-core-host-types = { git = "https://github.com/dzmitry-lahoda-forks/ibc-rs.gi
ibc-primitives = { git = "https://github.com/dzmitry-lahoda-forks/ibc-rs.git", branch = "dz/14", default-features = false, features = [
"serde",
] }
primitive-types = { git = "https://github.com/dzmitry-lahoda-forks/parity-common.git", branch = "dz/3", default-features = false, features = [

primitive-types = { version = "*", default-features = false, features = [
"serde_no_std",
] }

neutron-sdk = { version = "^0.10.0", default-features = false }

osmosis-std = { version = "^0.22.0", default-features = false }
Expand All @@ -166,7 +168,6 @@ cw-mantis-order = { path = "./contracts/cosmwasm/order", features = [
"std",
] }


cw-cvm-executor = { path = "./contracts/cosmwasm/executor", features = [
"json-schema",
"std",
Expand Down
43 changes: 31 additions & 12 deletions contracts/cosmwasm/executor/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use alloc::borrow::Cow;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
ensure, to_json_binary, wasm_execute, Addr, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo, QueryRequest, Reply, Response, StdError, StdResult, SubMsg, SubMsgResult, Uint128, WasmQuery
ensure, to_json_binary, wasm_execute, Addr, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut,
Env, MessageInfo, QueryRequest, Reply, Response, StdError, StdResult, SubMsg, SubMsgResult,
Uint128, WasmQuery,
};
use cvm_route::{asset::AssetReference, exchange::ExchangeItem};
use cvm_runtime::{
Expand Down Expand Up @@ -60,7 +62,8 @@ pub fn execute(
msg: cvm_runtime::executor::ExecuteMsg,
) -> Result {
let token = ensure_owner(deps.as_ref(), &env.contract.address, info.sender.clone())?;
deps.api.debug(&format!("cvm::executor::execute::coins {:?}", &info.funds));
deps.api
.debug(&format!("cvm::executor::execute::coins {:?}", &info.funds));
use cvm_runtime::executor::*;
match msg {
ExecuteMsg::Execute { tip, program } => initiate_execution(token, deps, env, tip, program),
Expand Down Expand Up @@ -340,7 +343,7 @@ impl<'a> BindingResolver<'a> {
let value = match reference.local {
AssetReference::Cw20 { contract } => contract.into_string(),
AssetReference::Native { denom } => denom,
// AssetReference::Erc20 { contract } => contract.to_string(),
_ => todo!("implement other asset types"),
};
Ok(Cow::Owned(value.into()))
}
Expand All @@ -366,7 +369,9 @@ impl<'a> BindingResolver<'a> {
balance
.apply(coin.amount.into())
.map_err(|_| ContractError::ArithmeticError)?
} // AssetReference::Erc20 { .. } => Err(ContractError::AssetUnsupportedOnThisNetwork)?,
}
AssetReference::Erc20 { .. } => Err(ContractError::AssetUnsupportedOnThisNetwork)?,
_ => todo!("implement other asset types"),
};
Ok(Cow::Owned(amount.to_string().into_bytes()))
}
Expand All @@ -392,13 +397,19 @@ pub fn execute_spawn(
response = response.add_event(events::CvmExecutorInstructionSpawning::new(network_id));
for (asset_id, balance) in assets.0 {
let reference = outpost_address.get_asset_by_id(deps.querier, asset_id)?;
deps.api.debug(&format!("cvm::executor::execute::spawn::asset {:?}", reference));
deps.api.debug(&format!(
"cvm::executor::execute::spawn::asset {:?}",
reference
));
let transfer_amount = match &reference.local {
AssetReference::Native { denom } => {
let coin = deps
.querier
.query_balance(env.contract.address.clone(), denom.clone())?;
deps.api.debug(&format!("cvm::executor::execute::spawn::filter {:?} {:?} {:?}", balance, coin, asset_id));
.querier
.query_balance(env.contract.address.clone(), denom.clone())?;
deps.api.debug(&format!(
"cvm::executor::execute::spawn::filter {:?} {:?} {:?}",
balance, coin, asset_id
));
balance
.apply(coin.amount.into())
.map_err(|_| ContractError::ArithmeticError)
Expand All @@ -409,9 +420,13 @@ pub fn execute_spawn(
contract,
&env.contract.address,
),
// AssetReference::Erc20 { .. } => Err(ContractError::AssetUnsupportedOnThisNetwork)?,
AssetReference::Erc20 { .. } => Err(ContractError::AssetUnsupportedOnThisNetwork)?,
_ => todo!("implement other asset types"),
}?;
deps.api.debug(&format!("cvm::executor::execute::spawn::transfer_amount {:?}", transfer_amount));
deps.api.debug(&format!(
"cvm::executor::execute::spawn::transfer_amount {:?}",
transfer_amount
));

if !transfer_amount.is_zero() {
let asset_id: u128 = asset_id.into();
Expand All @@ -431,7 +446,9 @@ pub fn execute_spawn(
recipient: outpost_address.address().into(),
amount: transfer_amount.into(),
})?)
} // AssetReference::Erc20 { .. } => Err(ContractError::AssetUnsupportedOnThisNetwork)?,
}
AssetReference::Erc20 { .. } => Err(ContractError::AssetUnsupportedOnThisNetwork)?,
_ => todo!("implement other asset types"),
};
}
}
Expand Down Expand Up @@ -507,7 +524,9 @@ pub fn interpret_transfer(
recipient: recipient.clone(),
amount: transfer_amount.into(),
})?)
} // AssetReference::Erc20 { .. } => Err(ContractError::AssetUnsupportedOnThisNetwork)?,
}
AssetReference::Erc20 { .. } => Err(ContractError::AssetUnsupportedOnThisNetwork)?,
_ => todo!("implement other asset types"),
};
}

Expand Down
4 changes: 3 additions & 1 deletion contracts/cosmwasm/order/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ impl OrderContract<'_> {
.into_iter()
.filter(|x| x.amount.u128() > 0)
.collect();
ctx.deps.api.debug(&format!("mantis::order::route::funds {:?}", funds));
ctx.deps
.api
.debug(&format!("mantis::order::route::funds {:?}", funds));
ensure!(
!funds.is_empty(),
crate::errors::expected_some_funds_in_route()
Expand Down
37 changes: 26 additions & 11 deletions contracts/cosmwasm/outpost/src/contract/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use crate::{
};

use cosmwasm_std::{
ensure, ensure_eq, entry_point, wasm_execute, Addr, BankMsg, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdError
ensure, ensure_eq, entry_point, wasm_execute, Addr, BankMsg, Coin, CosmosMsg, Deps, DepsMut,
Env, MessageInfo, Response, StdError,
};
use cvm_route::asset::{AssetReference, NetworkAssetItem};
use cw20::{Cw20Contract, Cw20ExecuteMsg};
Expand Down Expand Up @@ -172,9 +173,11 @@ fn transfer_from_user(
recipient: self_address.to_string(),
amount: (*program_amount).into(),
})?)
} // cvm_route::asset::AssetReference::Erc20 { .. } => {
// Err(ContractError::RuntimeUnsupportedOnNetwork)?
// }
}
cvm_route::asset::AssetReference::Erc20 { .. } => {
Err(ContractError::RuntimeUnsupportedOnNetwork)?
}
_ => todo!("implement other asset types"),
}
}
Ok((transfers, program_funds))
Expand All @@ -188,7 +191,10 @@ fn transfer_from_user(

program_funds.0.push((asset.asset_id, coin.amount.into()));
}
deps.api.debug(&format!("cvm::outpost::funds obtained from msg {:?}", program_funds));
deps.api.debug(&format!(
"cvm::outpost::funds obtained from msg {:?}",
program_funds
));
// we cannot do same trick with CW20 as need to know CW20 address (and it has to support
// Allowance query).
// so it is implement CW20 receiver interface like Michal did for wallet
Expand Down Expand Up @@ -300,7 +306,7 @@ pub(crate) fn handle_execute_program_privilleged(
)?;

// Secondly, call itself again with the same parameters, so that this functions goes
// into `Ok` state and properly executes the executor
// into `Ok` state and properly executes the executor
let execute_program = cvm_runtime::outpost::BridgeExecuteProgramMsg {
salt: executor_origin.salt,
program,
Expand Down Expand Up @@ -328,9 +334,13 @@ fn send_funds_to_executor(
) -> Result {
let mut response = Response::new();
let executor_address = executor_address.into_string();
deps.api.debug(&format!("cvm::outpost::funds:: sending funds {:?}", funds));
for (asset_id, amount) in funds.0 {
ensure!(amount >= <_>::default(), ContractError::DoNotAddFundsInsteadOfSendingZero);
deps.api
.debug(&format!("cvm::outpost::funds:: sending funds {:?}", funds));
for (asset_id, amount) in funds.0 {
ensure!(
amount >= <_>::default(),
ContractError::DoNotAddFundsInsteadOfSendingZero
);
let msg = match assets::get_asset_by_id(deps, asset_id)?.local {
cvm_route::asset::AssetReference::Native { denom } => BankMsg::Send {
to_address: executor_address.clone(),
Expand All @@ -343,9 +353,14 @@ fn send_funds_to_executor(
recipient: executor_address.clone(),
amount: amount.into(),
})?
} //cvm_route::asset::AssetReference::Erc20 { .. } => Err(ContractError::RuntimeUnsupportedOnNetwork)?,
}
cvm_route::asset::AssetReference::Erc20 { .. } => {
Err(ContractError::RuntimeUnsupportedOnNetwork)?
}
_ => todo!("implement other asset types"),
};
deps.api.debug(&format!("cvm::outpost::funds::msg {:?}", msg));
deps.api
.debug(&format!("cvm::outpost::funds::msg {:?}", msg));
response = response.add_message(msg);
}
Ok(response)
Expand Down
2 changes: 1 addition & 1 deletion contracts/cosmwasm/outpost/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
state::{self, network::load_this},
};
use cosmwasm_std::{
ensure, to_json_binary, Deps, DepsMut, Reply, Response, StdError, StdResult, SubMsg, WasmMsg
ensure, to_json_binary, Deps, DepsMut, Reply, Response, StdError, StdResult, SubMsg, WasmMsg,
};

use cvm_runtime::{executor::CvmExecutorInstantiated, CallOrigin, ExecutorOrigin};
Expand Down
Loading

0 comments on commit c38dd93

Please sign in to comment.