Skip to content

Commit b93886a

Browse files
optional CVM
1 parent c3eb8c3 commit b93886a

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

mantis/node/src/bin/mantis.rs

+34-26
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async fn solve_orders(solver_args: &SolverArgs) {
103103
&tip,
104104
gas,
105105
all_orders,
106-
solver_args.cross_chain_solution_provider.as_ref(),
106+
solver_args.router.as_ref(),
107107
)
108108
.await;
109109
};
@@ -159,36 +159,44 @@ async fn solve(
159159
_write_client: &mut CosmWasmWriteClient,
160160
cosmos_query_client: &mut CosmWasmReadClient,
161161
// really this should query Python Blackbox
162-
cvm_contact: &String,
162+
cvm_contact: &Option<String>,
163163
order_contract: &String,
164164
signing_key: &cosmrs::crypto::secp256k1::SigningKey,
165165
rpc: &CosmosChainInfo,
166166
tip: &Tip,
167167
gas: Gas,
168168
all_orders: Vec<OrderItem>,
169-
router_api: &str,
169+
router_api: &Option<String>,
170170
) {
171-
let salt = crate::cvm::get_salt(signing_key, tip);
172171
log::info!(target: "mantis::solver", "Solving orders");
173-
172+
174173
let cows_per_pair = mantis_node::mantis::solve::find_cows(&all_orders);
175-
let cvm_glt = get_cvm_glt(cvm_contact, cosmos_query_client).await;
176174
for pair_solution in cows_per_pair {
177-
let (a, b) = mantis_node::mantis::solve::IntentBankInput::find_intent_amount(
178-
pair_solution.cows.as_ref(),
179-
&all_orders,
180-
pair_solution.optimal_price,
181-
&cvm_glt,
182-
pair_solution.ab.clone(),
183-
);
184-
185-
let a_cvm_route = blackbox::get_route(router_api, a, &cvm_glt, salt.as_ref()).await;
186-
let b_cvm_route = blackbox::get_route(router_api, b, &cvm_glt, salt.as_ref()).await;
187-
188-
let cvm_program = CvmProgram {
189-
tag: salt.to_vec(),
190-
instructions: [a_cvm_route, b_cvm_route].concat().to_vec(),
191-
};
175+
176+
177+
let salt = crate::cvm::get_salt(signing_key, tip);
178+
let program = if let Some(order_contract) = order_contract {
179+
let cvm_glt = get_cvm_glt(order_contract, cosmos_query_client).await;
180+
let (a, b) = mantis_node::mantis::solve::IntentBankInput::find_intent_amount(
181+
pair_solution.cows.as_ref(),
182+
&all_orders,
183+
pair_solution.optimal_price,
184+
&cvm_glt,
185+
pair_solution.ab.clone(),
186+
);
187+
188+
189+
let a_cvm_route = blackbox::get_route(router_api, a, &cvm_glt, salt.as_ref()).await;
190+
let b_cvm_route = blackbox::get_route(router_api, b, &cvm_glt, salt.as_ref()).await;
191+
192+
let cvm_program = CvmProgram {
193+
tag: salt.to_vec(),
194+
instructions: [a_cvm_route, b_cvm_route].concat().to_vec(),
195+
};
196+
}
197+
else {
198+
None
199+
};
192200
send_solution(
193201
pair_solution.cows,
194202
cvm_program,
@@ -206,7 +214,7 @@ async fn solve(
206214

207215
async fn send_solution(
208216
cows: Vec<OrderSolution>,
209-
program: CvmProgram,
217+
program: Option<CvmProgram>,
210218
tip: &Tip,
211219
optimal_price: Ratio,
212220
signing_key: &cosmrs::crypto::secp256k1::SigningKey,
@@ -215,11 +223,9 @@ async fn send_solution(
215223
gas: Gas,
216224
salt: Vec<u8>,
217225
) {
218-
println!("========================= settle =========================");
226+
log::info!("========================= settle =========================");
219227
// would be reasonable to do do cross chain if it solves some % of whole trade
220-
let route = if random::<bool>() {
221-
None
222-
} else {
228+
let route = if let Some(program) = program && random::<bool>() {
223229
Some(CrossChainPart {
224230
msg: cvm_runtime::outpost::ExecuteProgramMsg {
225231
salt,
@@ -229,6 +235,8 @@ async fn send_solution(
229235
},
230236
optimal_price,
231237
})
238+
} else {
239+
None
232240
};
233241
let solution = SolutionSubMsg {
234242
cows,

mantis/node/src/mantis/args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub struct SolverArgs {
102102

103103
/// CVM contract if interchain solving via CVM enabled
104104
#[arg(long)]
105-
pub cvm_contract: Optional<String>,
105+
pub cvm_contract: Option<String>,
106106

107107
/// HTTP url to call with parameters to obtain route or built in shortest pass router
108108
#[arg(long)]

0 commit comments

Comments
 (0)