From 82fbc623b6ff44504cd5ceda0463d5e249ec986c Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Sun, 19 Nov 2023 14:45:23 +0000 Subject: [PATCH 1/3] doing --- mantis/node/src/bin/mantis.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mantis/node/src/bin/mantis.rs b/mantis/node/src/bin/mantis.rs index 925cdd0d..53025b57 100644 --- a/mantis/node/src/bin/mantis.rs +++ b/mantis/node/src/bin/mantis.rs @@ -20,6 +20,7 @@ async fn main() { + let mut write_client = create_wasm_write_client(&args.centauri).await; loop { @@ -40,11 +41,11 @@ async fn main() { /// timeout is also randomized starting from 10 to 100 blocks /// /// Also calls `timeout` so old orders are cleaned. -async fn simulate_order(write_client: &mut CosmWasmWriteClient, order_contract: String, _assets: String) { - if std::time::Instant::now().elapsed().as_millis() % 10 == 0 { +async fn simulate_order(write_client: &mut CosmWasmWriteClient, order_contract: String, asset: String, key : cosmrs::crypto::secp256k1::SigningKey) { + if std::time::Instant::now().elapsed().as_millis() % 100 == 0 { let msg = MsgExecuteContract { - sender: todo!(), + sender: key.public_key(), contract: todo!(), msg: todo!(), funds: todo!(), From 71eca8a733373ff5496da66ab657ff4543320967 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Sun, 19 Nov 2023 17:38:01 +0000 Subject: [PATCH 2/3] oh my god --- Cargo.lock | 1 + mantis/node/Cargo.toml | 1 + mantis/node/src/bin/mantis.rs | 88 ++++++++++++++++++++++++++++------- 3 files changed, 74 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b91c9dcd..87bf4c1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1377,6 +1377,7 @@ dependencies = [ "clap", "cosmos-sdk-proto", "cosmrs", + "cosmwasm-std", "cw-mantis-order", "derive_more", "itertools 0.12.0", diff --git a/mantis/node/Cargo.toml b/mantis/node/Cargo.toml index 8212775a..3e3714e9 100644 --- a/mantis/node/Cargo.toml +++ b/mantis/node/Cargo.toml @@ -26,3 +26,4 @@ itertools = { workspace = true } derive_more = { workspace = true } serde-json-wasm = { workspace = true } tuples = { workspace = true } +cosmwasm-std = {workspace = true} \ No newline at end of file diff --git a/mantis/node/src/bin/mantis.rs b/mantis/node/src/bin/mantis.rs index 53025b57..f7f70205 100644 --- a/mantis/node/src/bin/mantis.rs +++ b/mantis/node/src/bin/mantis.rs @@ -1,7 +1,17 @@ -use cosmos_sdk_proto::cosmwasm::wasm::v1::QuerySmartContractStateRequest; +use cosmos_sdk_proto::{ + cosmos::base::v1beta1::Coin, + cosmwasm::{self, wasm::v1::QuerySmartContractStateRequest}, +}; +use cosmrs::tx::Msg; +use cosmos_sdk_proto::{traits::Message, Any}; -use cosmrs::{cosmwasm::MsgExecuteContract, rpc::Client}; -use cw_mantis_order::OrderItem; +use cosmrs::{ + cosmwasm::MsgExecuteContract, + rpc::Client, + tx::{Fee, SignerInfo, self}, + AccountId, +}; +use cw_mantis_order::{OrderItem, OrderSubMsg}; use mantis_node::{ mantis::{args::*, cosmos::*}, prelude::*, @@ -10,7 +20,8 @@ use mantis_node::{ #[tokio::main] async fn main() { let args = MantisArgs::parsed(); - let read_client = create_wasm_query_client(&args.centauri).await; + let wasm_read_client = create_wasm_query_client(&args.centauri).await; + let mut cosmos_query_client = create_cosmos_query_client(&args.centauri).await; let signer = mantis_node::mantis::beaker::cli::support::signer::from_mnemonic( args.wallet.as_str(), @@ -18,14 +29,27 @@ async fn main() { ) .expect("mnemonic"); - - - let mut write_client = create_wasm_write_client(&args.centauri).await; - loop { + let account = query_cosmos_account( + &args.centauri, + signer + .public_key() + .account_id("centauri") + .expect("key") + .to_string(), + ) + .await; if let Some(assets) = args.simulate.clone() { - simulate_order(&mut write_client, args.order_contract.clone(), assets).await; + simulate_order( + &mut write_client, + &mut cosmos_query_client, + args.order_contract.clone(), + assets, + &signer, + account.sequence, + ) + .await; }; } } @@ -41,16 +65,48 @@ async fn main() { /// timeout is also randomized starting from 10 to 100 blocks /// /// Also calls `timeout` so old orders are cleaned. -async fn simulate_order(write_client: &mut CosmWasmWriteClient, order_contract: String, asset: String, key : cosmrs::crypto::secp256k1::SigningKey) { +async fn simulate_order( + write_client: &mut CosmWasmWriteClient, + cosmos_query_client: &mut CosmosQueryClient, + order_contract: String, + asset: String, + signing_key: &cosmrs::crypto::secp256k1::SigningKey, + sequence: u64, +) { if std::time::Instant::now().elapsed().as_millis() % 100 == 0 { - + let auth_info = SignerInfo::single_direct(Some(signing_key.public_key()), sequence) + .auth_info(Fee { + amount: vec![], + gas_limit: 100_000_000, + payer: None, + granter: None, + }); + let msg = MsgExecuteContract { - sender: key.public_key(), - contract: todo!(), - msg: todo!(), - funds: todo!(), + sender: signing_key + .public_key() + .account_id("centauri") + .expect("account"), + contract: AccountId::from_str(&order_contract).expect("contract"), + msg: serde_json_wasm::to_vec(&cw_mantis_order::ExecMsg::Order { + msg: OrderSubMsg { + wants: cosmwasm_std::Coin { + amount: 1000u128.into(), + denom: asset.to_string(), + }, + transfer: None, + timeout: todo!(), + min_fill: None, + }, + }) + .expect("json"), + funds: vec![cosmrs::Coin { + amount: 1000u128.into(), + denom: cosmrs::Denom::from_str("ppica").expect("denom"), + }], }; - + let msg = msg.to_any().expect("proto"); + let tx_body = tx::Body::new(vec![msg], "mantis-solver", 14); //let result = write_client.execute_contract(request).await.expect("executed"); } } From 2ad53e8b4c9205265ad8e3d659224ca18a4ef44a Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Sun, 19 Nov 2023 20:14:22 +0000 Subject: [PATCH 3/3] end to end call --- README.md | 7 ++++- mantis/node/src/bin/mantis.rs | 54 ++++++++++++++++++++++++++------ mantis/node/src/mantis/cosmos.rs | 1 + 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 768c589a..e26fa81a 100644 --- a/README.md +++ b/README.md @@ -14,4 +14,9 @@ For `issues` and `high level docs` go to `ComposableFi/composable` repo 7. Converts to Input and output back 8. TX solution. 6. Run for a while. -7. Deploy \ No newline at end of file +7. Deploy + + +# CFMM + +- query \ No newline at end of file diff --git a/mantis/node/src/bin/mantis.rs b/mantis/node/src/bin/mantis.rs index f7f70205..ec0caeef 100644 --- a/mantis/node/src/bin/mantis.rs +++ b/mantis/node/src/bin/mantis.rs @@ -1,14 +1,17 @@ use cosmos_sdk_proto::{ - cosmos::base::v1beta1::Coin, + cosmos::{auth::v1beta1::BaseAccount, base::v1beta1::Coin}, cosmwasm::{self, wasm::v1::QuerySmartContractStateRequest}, }; -use cosmrs::tx::Msg; use cosmos_sdk_proto::{traits::Message, Any}; +use cosmrs::{ + tendermint::chain, + tx::{Msg, SignDoc}, +}; use cosmrs::{ cosmwasm::MsgExecuteContract, rpc::Client, - tx::{Fee, SignerInfo, self}, + tx::{self, Fee, SignerInfo}, AccountId, }; use cw_mantis_order::{OrderItem, OrderSubMsg}; @@ -31,7 +34,7 @@ async fn main() { let mut write_client = create_wasm_write_client(&args.centauri).await; loop { - let account = query_cosmos_account( + let acc = query_cosmos_account( &args.centauri, signer .public_key() @@ -47,7 +50,8 @@ async fn main() { args.order_contract.clone(), assets, &signer, - account.sequence, + acc, + &args.centauri, ) .await; }; @@ -71,10 +75,11 @@ async fn simulate_order( order_contract: String, asset: String, signing_key: &cosmrs::crypto::secp256k1::SigningKey, - sequence: u64, + acc: BaseAccount, + rpc: &str, ) { if std::time::Instant::now().elapsed().as_millis() % 100 == 0 { - let auth_info = SignerInfo::single_direct(Some(signing_key.public_key()), sequence) + let auth_info = SignerInfo::single_direct(Some(signing_key.public_key()), acc.sequence) .auth_info(Fee { amount: vec![], gas_limit: 100_000_000, @@ -82,6 +87,15 @@ async fn simulate_order( granter: None, }); + use cosmrs::tendermint::block::Height; + let rpc_client: cosmrs::rpc::HttpClient = cosmrs::rpc::HttpClient::new(rpc).unwrap(); + let status = rpc_client + .status() + .await + .expect("status") + .sync_info + .latest_block_height; + let msg = MsgExecuteContract { sender: signing_key .public_key() @@ -95,7 +109,7 @@ async fn simulate_order( denom: asset.to_string(), }, transfer: None, - timeout: todo!(), + timeout: status.value() + 100, min_fill: None, }, }) @@ -106,7 +120,29 @@ async fn simulate_order( }], }; let msg = msg.to_any().expect("proto"); - let tx_body = tx::Body::new(vec![msg], "mantis-solver", 14); + + let tx_body = tx::Body::new( + vec![msg], + "mantis-solver", + Height::try_from(status.value() + 100).unwrap(), + ); + + let sign_doc = SignDoc::new( + &tx_body, + &auth_info, + &chain::Id::try_from("centauri-1").expect("id"), + acc.account_number, + ) + .unwrap(); + + let tx_raw = sign_doc.sign(&signing_key).unwrap(); + let result = tx_raw + .broadcast_commit(&rpc_client) + .await + .expect("broadcasted"); + assert!(!result.check_tx.code.is_err(), "err"); + assert!(!result.tx_result.code.is_err(), "err"); + //let result = write_client.execute_contract(request).await.expect("executed"); } } diff --git a/mantis/node/src/mantis/cosmos.rs b/mantis/node/src/mantis/cosmos.rs index 08f511a9..f18916c6 100644 --- a/mantis/node/src/mantis/cosmos.rs +++ b/mantis/node/src/mantis/cosmos.rs @@ -27,6 +27,7 @@ pub async fn query_cosmos_account(rpc: &str, address : String) -> cosmos_sdk_pro BaseAccount::decode(account.account.expect("some").value.as_slice()).expect("decode") } + pub async fn create_wasm_query_client(rpc: &str) -> CosmWasmReadClient { let url = tonic::transport::Endpoint::from_str(rpc).expect("url"); cosmos_sdk_proto::cosmwasm::wasm::v1::query_client::QueryClient::connect(url)