-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshared_bundle.rs
More file actions
55 lines (49 loc) · 1.78 KB
/
shared_bundle.rs
File metadata and controls
55 lines (49 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use renegade_sdk::AssembleQuoteOptions;
use renegade_sdk::example_utils::{Wallet, build_renegade_client, execute_bundle, get_signer};
use renegade_sdk::{
ExternalMatchClient, ExternalOrderBuilder,
types::{ExternalOrder, OrderSide},
};
/// Testnet wETH
const BASE_MINT: &str = "0xc3414a7ef14aaaa9c4522dfc00a4e66e74e9c25a";
/// Testnet USDC
const QUOTE_MINT: &str = "0xdf8d259c04020562717557f2b5a3cf28e92707d1";
#[tokio::main]
async fn main() -> Result<(), eyre::Error> {
// Get wallet from private key
let signer = get_signer().await?;
// Get the external match client
let client = build_renegade_client(false /* use_base */)?;
let order = ExternalOrderBuilder::new()
.base_mint(BASE_MINT)
.quote_mint(QUOTE_MINT)
.quote_amount(30_000_000) // $30 USDC
.min_fill_size(30_000_000) // $30 USDC
.side(OrderSide::Sell)
.build()
.unwrap();
fetch_quote_and_execute(&client, order, &signer).await?;
Ok(())
}
/// Fetch a quote from the external api and print it
async fn fetch_quote_and_execute(
client: &ExternalMatchClient,
order: ExternalOrder,
wallet: &Wallet,
) -> Result<(), eyre::Error> {
// Fetch a quote from the relayer
println!("Fetching quote...");
let res = client.request_quote(order.clone()).await?;
let quote = match res {
Some(quote) => quote,
None => eyre::bail!("No quote found"),
};
// Assemble the quote into a bundle
println!("Assembling quote...");
let options = AssembleQuoteOptions::new().with_allow_shared(true);
let resp = match client.assemble_quote_with_options(quote, options).await? {
Some(resp) => resp,
None => eyre::bail!("No bundle found"),
};
execute_bundle(wallet, resp.match_bundle.settlement_tx).await
}