diff --git a/Cargo.lock b/Cargo.lock index c31e5f06..b91c9dcd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -229,6 +229,8 @@ dependencies = [ "bs58", "hmac", "k256", + "once_cell", + "pbkdf2", "rand_core 0.6.4", "ripemd", "sha2 0.10.8", @@ -501,6 +503,7 @@ dependencies = [ "tendermint", "tendermint-rpc", "thiserror", + "tokio", ] [[package]] @@ -1370,6 +1373,7 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" name = "mantis-node" version = "0.1.0" dependencies = [ + "bip32", "clap", "cosmos-sdk-proto", "cosmrs", @@ -1585,6 +1589,16 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "pbkdf2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" +dependencies = [ + "digest 0.10.7", + "hmac", +] + [[package]] name = "peg" version = "0.7.0" @@ -2477,9 +2491,9 @@ dependencies = [ [[package]] name = "subtle" -version = "2.5.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "subtle-encoding" diff --git a/Cargo.toml b/Cargo.toml index d418fbba..74482360 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,7 @@ num-integer = { version = "^0.1.45", default-features = false } serde-json-wasm = { version = "^1.0.0", default-features = false } clap = { version = "^4.4.8", features = ["derive"] } -cosmrs = { version = "^0.15.0", features = ["cosmwasm", "rpc", "grpc"] } +cosmrs = { version = "^0.15.0", features = ["cosmwasm", "rpc", "grpc", "bip32", "dev"] } tokio = { version = "^1.34.0", features = ["full"] } cosmos-sdk-proto = { version = "^0.20.0", features = ["grpc-transport"] } tonic = { version = "^0.10.2" } @@ -61,3 +61,6 @@ rand_distr = "^0.4.3" strum = "^0.25" strum_macros = "^0.25" tuples = { version = "^1.12.0" } + + +bip32 = { version = "^0.5.1", default-features = false, features = ["alloc", "secp256k1", "mnemonic", "bip39"] } \ No newline at end of file diff --git a/README.md b/README.md index 3e34e704..768c589a 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,11 @@ For `issues` and `high level docs` go to `ComposableFi/composable` repo ## Plan for today -1. Buy shit coin -2. Transfer to Centauri -3. Start simulator. \ No newline at end of file +3. Start simulator. +4. Split coin +5. Randomize +6. Make TX +7. Converts to Input and output back +8. TX solution. +6. Run for a while. +7. Deploy \ No newline at end of file diff --git a/mantis/node/Cargo.toml b/mantis/node/Cargo.toml index 6019c6e4..8212775a 100644 --- a/mantis/node/Cargo.toml +++ b/mantis/node/Cargo.toml @@ -9,7 +9,10 @@ name = "mantis" [dependencies] cw-mantis-order = { path = "../../contracts/cosmwasm/order" } clap = { workspace = true, features = ["derive"] } -cosmrs = { workspace = true, features = ["cosmwasm", "rpc", "grpc"] } +cosmrs = { workspace = true} +bip32 = { workspace = true} + + tokio = { workspace = true, features = ["full"] } cosmos-sdk-proto = { workspace = true, features = ["grpc-transport"] } tonic = { workspace = true } diff --git a/mantis/node/src/bin/mantis.rs b/mantis/node/src/bin/mantis.rs index 399e2fc4..925cdd0d 100644 --- a/mantis/node/src/bin/mantis.rs +++ b/mantis/node/src/bin/mantis.rs @@ -1,5 +1,6 @@ use cosmos_sdk_proto::cosmwasm::wasm::v1::QuerySmartContractStateRequest; +use cosmrs::{cosmwasm::MsgExecuteContract, rpc::Client}; use cw_mantis_order::OrderItem; use mantis_node::{ mantis::{args::*, cosmos::*}, @@ -9,7 +10,16 @@ use mantis_node::{ #[tokio::main] async fn main() { let args = MantisArgs::parsed(); - let _client = create_wasm_query_client(&args.centauri).await; + let read_client = create_wasm_query_client(&args.centauri).await; + + let signer = mantis_node::mantis::beaker::cli::support::signer::from_mnemonic( + args.wallet.as_str(), + "centauri", + ) + .expect("mnemonic"); + + + let mut write_client = create_wasm_write_client(&args.centauri).await; loop { @@ -30,8 +40,18 @@ 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 WriteClient, _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, _assets: String) { + if std::time::Instant::now().elapsed().as_millis() % 10 == 0 { + + let msg = MsgExecuteContract { + sender: todo!(), + contract: todo!(), + msg: todo!(), + funds: todo!(), + }; + + //let result = write_client.execute_contract(request).await.expect("executed"); + } } /// gets orders, groups by pairs @@ -42,8 +62,8 @@ async fn simulate_order(_write_client: &mut WriteClient, _order_contract: String /// gets CVM routing data /// uses cfmm algorithm async fn solve( - read: &mut ReadClient, - _write: WriteClient, + read: &mut CosmWasmReadClient, + _write: CosmWasmWriteClient, order_contract: String, _cvm_contract: String, ) { diff --git a/mantis/node/src/mantis/beaker/cli/mod.rs b/mantis/node/src/mantis/beaker/cli/mod.rs new file mode 100644 index 00000000..05ed7c04 --- /dev/null +++ b/mantis/node/src/mantis/beaker/cli/mod.rs @@ -0,0 +1 @@ +pub mod support; diff --git a/mantis/node/src/mantis/beaker/cli/support/mod.rs b/mantis/node/src/mantis/beaker/cli/support/mod.rs new file mode 100644 index 00000000..eef58b8f --- /dev/null +++ b/mantis/node/src/mantis/beaker/cli/support/mod.rs @@ -0,0 +1 @@ +pub mod signer; diff --git a/mantis/node/src/mantis/beaker/cli/support/signer.rs b/mantis/node/src/mantis/beaker/cli/support/signer.rs new file mode 100644 index 00000000..25611bdb --- /dev/null +++ b/mantis/node/src/mantis/beaker/cli/support/signer.rs @@ -0,0 +1,11 @@ +use cosmrs::crypto::secp256k1::SigningKey; + +pub fn from_mnemonic(phrase: &str, derivation_path: &str) -> Result { + let seed = bip32::Mnemonic::new(phrase, bip32::Language::English) + .expect("mnemonic") + .to_seed(""); + let xprv = bip32::XPrv::derive_from_path(seed, &derivation_path.parse().expect("parse")) + .expect("derived"); + let signer_priv: SigningKey = xprv.into(); + Ok(signer_priv) +} diff --git a/mantis/node/src/mantis/beaker/mod.rs b/mantis/node/src/mantis/beaker/mod.rs new file mode 100644 index 00000000..4f773726 --- /dev/null +++ b/mantis/node/src/mantis/beaker/mod.rs @@ -0,0 +1 @@ +pub mod cli; diff --git a/mantis/node/src/mantis/cosmos.rs b/mantis/node/src/mantis/cosmos.rs index 73645831..08f511a9 100644 --- a/mantis/node/src/mantis/cosmos.rs +++ b/mantis/node/src/mantis/cosmos.rs @@ -1,19 +1,42 @@ use crate::prelude::*; -use cosmos_sdk_proto::cosmwasm::wasm::v1::msg_client::MsgClient; -use cosmos_sdk_proto::cosmwasm::wasm::v1::query_client::QueryClient; - +use cosmos_sdk_proto::cosmos::auth::v1beta1::QueryAccountRequest; use tonic::transport::Channel; -pub type WriteClient = MsgClient; -pub type ReadClient = QueryClient; +pub type CosmWasmWriteClient = cosmos_sdk_proto::cosmwasm::wasm::v1::msg_client::MsgClient; +pub type CosmWasmReadClient = + cosmos_sdk_proto::cosmwasm::wasm::v1::query_client::QueryClient; + +pub type CosmosQueryClient = + cosmos_sdk_proto::cosmos::auth::v1beta1::query_client::QueryClient; -pub async fn create_wasm_query_client(rpc: &str) -> QueryClient { +pub async fn create_cosmos_query_client(rpc: &str) -> CosmosQueryClient { + use cosmos_sdk_proto::cosmos::auth::v1beta1::query_client::*; + use cosmos_sdk_proto::cosmos::auth::v1beta1::*; let url = tonic::transport::Endpoint::from_str(rpc).expect("url"); QueryClient::connect(url).await.expect("connected") } -pub async fn create_wasm_write_client(rpc: &str) -> MsgClient { +pub async fn query_cosmos_account(rpc: &str, address : String) -> cosmos_sdk_proto::cosmos::auth::v1beta1::BaseAccount { + use cosmos_sdk_proto::traits::Message; + use cosmos_sdk_proto::cosmos::auth::v1beta1::*; + let mut client = create_cosmos_query_client(rpc).await; + let account = client.account(QueryAccountRequest { + address, + }).await.expect("account").into_inner(); + 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) + .await + .expect("connected") +} + +pub async fn create_wasm_write_client(rpc: &str) -> CosmWasmWriteClient { let url = tonic::transport::Endpoint::from_str(rpc).expect("url"); - MsgClient::connect(url).await.expect("connected") + cosmos_sdk_proto::cosmwasm::wasm::v1::msg_client::MsgClient::connect(url) + .await + .expect("connected") } diff --git a/mantis/node/src/mantis/mod.rs b/mantis/node/src/mantis/mod.rs index 742d582d..0bfa1a57 100644 --- a/mantis/node/src/mantis/mod.rs +++ b/mantis/node/src/mantis/mod.rs @@ -1,2 +1,3 @@ pub mod args; pub mod cosmos; +pub mod beaker;