Skip to content

Commit

Permalink
Merge pull request #2 from ComposableFi/dz/2
Browse files Browse the repository at this point in the history
feat: query cosmos account for nonce porting code from beaker
  • Loading branch information
dzmitry-lahoda authored Nov 19, 2023
2 parents 2761f4e + 01897a3 commit 2aa1a36
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 20 deletions.
18 changes: 16 additions & 2 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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"] }
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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
5 changes: 4 additions & 1 deletion mantis/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
30 changes: 25 additions & 5 deletions mantis/node/src/bin/mantis.rs
Original file line number Diff line number Diff line change
@@ -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::*},
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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,
) {
Expand Down
1 change: 1 addition & 0 deletions mantis/node/src/mantis/beaker/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod support;
1 change: 1 addition & 0 deletions mantis/node/src/mantis/beaker/cli/support/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod signer;
11 changes: 11 additions & 0 deletions mantis/node/src/mantis/beaker/cli/support/signer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use cosmrs::crypto::secp256k1::SigningKey;

pub fn from_mnemonic(phrase: &str, derivation_path: &str) -> Result<SigningKey, String> {
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)
}
1 change: 1 addition & 0 deletions mantis/node/src/mantis/beaker/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod cli;
39 changes: 31 additions & 8 deletions mantis/node/src/mantis/cosmos.rs
Original file line number Diff line number Diff line change
@@ -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<Channel>;
pub type ReadClient = QueryClient<Channel>;
pub type CosmWasmWriteClient = cosmos_sdk_proto::cosmwasm::wasm::v1::msg_client::MsgClient<Channel>;
pub type CosmWasmReadClient =
cosmos_sdk_proto::cosmwasm::wasm::v1::query_client::QueryClient<Channel>;

pub type CosmosQueryClient =
cosmos_sdk_proto::cosmos::auth::v1beta1::query_client::QueryClient<Channel>;

pub async fn create_wasm_query_client(rpc: &str) -> QueryClient<Channel> {
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<Channel> {
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")
}
1 change: 1 addition & 0 deletions mantis/node/src/mantis/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod args;
pub mod cosmos;
pub mod beaker;

0 comments on commit 2aa1a36

Please sign in to comment.