Skip to content

Commit 9a126b1

Browse files
authored
Merge pull request #300 from propeller-heads/rfq/dc/ENG-4698-add-execution-quickstart
feat: Add execution to RFQ quickstart
2 parents 725b373 + 6ef3f5a commit 9a126b1

File tree

8 files changed

+721
-129
lines changed

8 files changed

+721
-129
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ mini-moka = "0.10"
4848
lazy_static = "1.4.0"
4949

5050
# Tycho dependencies
51-
tycho-common = "0.81.0"
52-
tycho-client = "0.81.0"
51+
tycho-common = "0.81.5"
52+
tycho-client = "0.81.5"
5353

5454
# EVM dependencies
5555
foundry-config = { git = "https://github.com/foundry-rs/foundry", rev = "5a552bb0de7126fa35170fd84532bbd3d40cd348", optional = true }
@@ -97,7 +97,7 @@ unicode-width = "0.1.13"
9797
tracing-appender = "0.2.3"
9898

9999
# tycho execution for quickstart
100-
tycho-execution = "0.112.0"
100+
tycho-execution = "0.116.0"
101101

102102
[features]
103103
default = ["evm", "rfq"]

examples/quickstart/Readme.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export RPC_URL=<your-rpc-url>
1212
cargo run --release --example quickstart
1313
```
1414

15-
By default, the example will trade 10 USDC -> WETH on Ethereum Mainnet. Setting the chain will by default trade 10 USDC -> WETH on that chain.
15+
By default, the example will trade 10 USDC -> WETH on Ethereum Mainnet. Setting the chain will by default trade 10
16+
USDC -> WETH on that chain.
1617
If you want a different trade or chain, you can do:
1718

1819
```bash
@@ -22,11 +23,12 @@ cargo run --release --example quickstart -- --sell-token "0x833589fCD6eDb6E08f4c
2223

2324
for 10 USDC -> WETH on Base.
2425

25-
To be able to execute or simulate the best swap, you need to pass your private key. Assuming your private key is stored in your PK env var:
26+
To be able to execute or simulate the best swap, you need to pass your private key. Assuming your private key is stored
27+
in your PK env var:
2628

2729
```bash
2830
cargo run --release --example quickstart -- --swapper-pk $PK
2931
```
3032

31-
See [here](https://docs.propellerheads.xyz/tycho/for-solvers/tycho-quickstart) a complete guide on how to run the
33+
See [here](https://docs.propellerheads.xyz/tycho) a complete guide on how to run the
3234
Quickstart example.

examples/quickstart/main.rs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use tycho_execution::encoding::{
3232
errors::EncodingError,
3333
evm::{approvals::permit2::PermitSingle, encoder_builders::TychoRouterEncoderBuilder},
3434
models,
35-
models::{EncodedSolution, Solution, Swap, Transaction, UserTransferType},
35+
models::{EncodedSolution, Solution, SwapBuilder, Transaction, UserTransferType},
3636
};
3737
use tycho_simulation::{
3838
evm::{
@@ -73,15 +73,15 @@ struct Cli {
7373
#[arg(long, default_value = FAKE_PK)]
7474
swapper_pk: String,
7575
#[arg(long, default_value = "ethereum")]
76-
chain: String,
76+
chain: Chain,
7777
}
7878

7979
impl Cli {
8080
fn with_defaults(mut self) -> Self {
8181
// By default, we swap a small amount of USDC to WETH on whatever chain we choose
8282

8383
if self.buy_token.is_none() {
84-
self.buy_token = Some(match self.chain.as_str() {
84+
self.buy_token = Some(match self.chain.to_string().as_str() {
8585
"ethereum" => "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2".to_string(),
8686
"base" => "0x4200000000000000000000000000000000000006".to_string(),
8787
"unichain" => "0x4200000000000000000000000000000000000006".to_string(),
@@ -90,7 +90,7 @@ impl Cli {
9090
}
9191

9292
if self.sell_token.is_none() {
93-
self.sell_token = Some(match self.chain.as_str() {
93+
self.sell_token = Some(match self.chain.to_string().as_str() {
9494
"ethereum" => "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48".to_string(),
9595
"base" => "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913".to_string(),
9696
"unichain" => "0x078d782b760474a361dda0af3839290b0ef57ad6".to_string(),
@@ -111,8 +111,7 @@ async fn main() {
111111

112112
let cli = Cli::parse().with_defaults();
113113

114-
let chain = Chain::from_str(&cli.chain)
115-
.unwrap_or_else(|_| panic!("Unknown chain {chain}", chain = cli.chain));
114+
let chain = cli.chain;
116115

117116
let tycho_url = env::var("TYCHO_URL").unwrap_or_else(|_| {
118117
get_default_url(&chain)
@@ -236,10 +235,8 @@ async fn main() {
236235
)
237236
.expect("Failed to private key signer");
238237
let tx_signer = EthereumWallet::from(wallet.clone());
239-
let named_chain =
240-
NamedChain::from_str(&cli.chain.replace("ethereum", "mainnet")).expect("Invalid chain");
241238
let provider = ProviderBuilder::default()
242-
.with_chain(named_chain)
239+
.with_chain(NamedChain::try_from(chain.id()).expect("Invalid chain"))
243240
.wallet(tx_signer.clone())
244241
.connect(&env::var("RPC_URL").expect("RPC_URL env var not set"))
245242
.await
@@ -288,7 +285,7 @@ async fn main() {
288285
.clone();
289286

290287
let tx = encode_tycho_router_call(
291-
named_chain.into(),
288+
chain.id(),
292289
encoded_solution.clone(),
293290
&solution,
294291
chain.native_token().address,
@@ -381,7 +378,7 @@ async fn main() {
381378
wallet.address(),
382379
Address::from_slice(&sell_token_address),
383380
tx.clone(),
384-
named_chain as u64,
381+
chain.id(),
385382
)
386383
.await;
387384

@@ -434,7 +431,7 @@ async fn main() {
434431
wallet.address(),
435432
&sell_token_address,
436433
tx.clone(),
437-
named_chain as u64,
434+
chain.id(),
438435
)
439436
.await
440437
{
@@ -478,7 +475,7 @@ async fn main() {
478475
wallet.address(),
479476
&sell_token_address,
480477
tx,
481-
named_chain as u64,
478+
chain.id(),
482479
)
483480
.await
484481
{
@@ -608,16 +605,8 @@ fn create_solution(
608605
expected_amount: BigUint,
609606
) -> Solution<'static> {
610607
// Prepare data to encode. First we need to create a swap object
611-
let simple_swap = Swap::new(
612-
component,
613-
sell_token.address.clone(),
614-
buy_token.address.clone(),
615-
// Split defines the fraction of the amount to be swapped. A value of 0 indicates 100% of
616-
// the amount or the total remaining balance.
617-
0f64,
618-
None,
619-
None,
620-
);
608+
let simple_swap =
609+
SwapBuilder::new(component, sell_token.address.clone(), buy_token.address.clone()).build();
621610

622611
// Compute a minimum amount out
623612
//

examples/rfq_quickstart/Readme.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,37 @@ This quickstart guide enables you to:
1010
You need to set up the WebSocket credentials of the desired RFQs to access live pricing data:
1111

1212
```bash
13-
export BEBOP_WS_USER=<your-bebop-ws-username>
14-
export BEBOP_WS_KEY=<your-bebop-ws-key>
13+
export BEBOP_USER=<your-bebop-ws-username>
14+
export BEBOP_KEY=<your-bebop-ws-key>
1515
cargo run --release --example rfq_quickstart
1616
```
1717

1818
By default, the example will request price levels for 10 USDC -> WETH on Ethereum Mainnet using RFQs.
1919
If we choose a different chain, by default, price levels for USDC -> WETH will be requested on that chain.
20-
If you want a different trade and chain, you can use the following command, replacing the values with the token and chain that you'd like:
20+
If you want a different trade and chain, you can use the following command, replacing the values with the token and
21+
chain that you'd like:
2122

2223
```bash
23-
export BEBOP_WS_USER=<your-bebop-ws-username>
24-
export BEBOP_WS_KEY=<your-bebop-ws-key>
24+
export BEBOP_USER=<your-bebop-ws-username>
25+
export BEBOP_KEY=<your-bebop-ws-key>
2526
cargo run --release --example rfq_quickstart -- --sell-token "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb" --buy-token "0x4200000000000000000000000000000000000006" --sell-amount 10 --chain "base"
2627
```
2728

2829
for 10 USDC -> WETH on Base.
2930

3031
## Important Notes
3132

32-
- **Credentials**: Contact RFQ protocols directly to obtain WebSocket API credentials for accessing live market maker quotes
33+
- **Credentials**: Contact RFQ protocols directly to obtain WebSocket API credentials for accessing live market maker
34+
quotes
3335

3436
## What you'll see
3537

3638
The example will:
39+
3740
1. Connect to the RFQ's WebSocket API using your credentials
3841
2. Stream live price quotes from market makers for your specified token pair
3942
3. Display the best available quotes with pricing information
4043

44+
TODO: update this once docs are merged
4145
See [here](https://docs.propellerheads.xyz/tycho/for-solvers/tycho-quickstart) a complete guide on how to run the
4246
Quickstart example.

0 commit comments

Comments
 (0)