Skip to content

Commit

Permalink
whole simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Dec 10, 2023
1 parent 3af3f3d commit 7883663
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
53 changes: 49 additions & 4 deletions mantis/node/src/bin/optimal-routing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use itertools::*;
use mantis_node::solver::router::*;
use std::collections::HashMap;
use tuples::TupleCloned;
fn main() {
let center_node = "CENTAURI";

Expand All @@ -24,16 +25,60 @@ fn main() {
let mut cfmm_tx_cost = vec![];
for (other_chain, other_tokens) in chains.clone() {
all_tokens.extend(other_tokens.clone());
let cfmms = other_tokens.clone().into_iter().combinations(2);
let cfmms = other_tokens
.clone()
.into_iter()
.combinations(2)
.map(|x| (x[0].clone(), x[1].clone()));
all_cfmms.extend(cfmms);
}
use rand::prelude::*;
let tx_costs_random = rand_distr::Uniform::new(0, 20);
let reserves_radom = rand_distr::Uniform::new(9500, 10051);
for cfmm in all_cfmms {
let value = reserves_radom.sample(&mut rand::thread_rng());
reserves.push(value);
for cfmm in all_cfmms.iter() {
let a = reserves_radom.sample(&mut rand::thread_rng());
let b = reserves_radom.sample(&mut rand::thread_rng());
reserves.push((a, b));
let value = tx_costs_random.sample(&mut rand::thread_rng());
cfmm_tx_cost.push(value);
}

let mut ibc_pools = 0u32;
let tx_costs_random = rand_distr::Uniform::new(0, 20);
let reserves_random = rand_distr::Uniform::new(10000, 11000);
for token_on_center in chains.get(center_node).unwrap() {
for (other_chain, other_tokens) in chains.iter() {
if other_chain != center_node {
for other_token in other_tokens {
if token_on_center.contains(other_token)
|| other_token.contains(token_on_center)
{
all_cfmms.push((token_on_center.to_owned(), other_token.to_owned()));
let a = reserves_random.sample(&mut rand::thread_rng());
let b = reserves_random.sample(&mut rand::thread_rng());
reserves.push((a, b));
cfmm_tx_cost.push(tx_costs_random.sample(&mut rand::thread_rng()));
ibc_pools += 1;
}
}
}
}
}

let mut fees = vec![];
let fees_random = rand_distr::Uniform::new(0.97, 0.999);
for cfmm in 0..all_cfmms.len() {
let value = fees_random.sample(&mut rand::thread_rng());
fees.push(value);
}

println!("{:?}", reserves);

for item in all_tokens.iter().enumerate() {
println!("{:?}", item);
}

for item in all_cfmms.iter().enumerate() {
println!("{:?}", item);
}
}
4 changes: 2 additions & 2 deletions mantis/simulation/optimal-routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
for other_chain, other_tokens in chains.items():
if other_chain != CENTER_NODE:
for other_token in other_tokens:
# Check wether the chain has the token in centuri, or the other way around
# Check wether the chain has the token in center, or the other way around
# Could cause problems if chainName == tokensName (for example OSMOSIS)
if other_token in token_on_center or token_on_center in other_token:
all_cfmms.append((token_on_center, other_token))
Expand All @@ -53,7 +53,7 @@
# simulate random fees
fees.extend(np.random.uniform(0.97, 0.999) for _ in range(len(all_cfmms)))

print(chains)
print(reserves)

for i, token in enumerate(all_tokens):
print(i, token)
Expand Down

0 comments on commit 7883663

Please sign in to comment.