use {
alloy_primitives::{Address, U256, address},
alloy_signer_local::PrivateKeySigner,
cowprotocol::{Chain, OrderBookApi},
std::str::FromStr,
};
const WETH_SEPOLIA: Address = address!("fFf9976782d46CC05630D1f6eBAb18b2324d6B14");
const COW_SEPOLIA: Address = address!("0625aFB445C3B6B7B929342a04A22599fd5dBB59");
const SELL_AMOUNT_WEI: u128 = 10_000_000_000_000_000;
#[tokio::main]
async fn main() -> cowprotocol::Result<()> {
let Ok(raw_key) = std::env::var("SEPOLIA_PRIVATE_KEY") else {
println!("set SEPOLIA_PRIVATE_KEY=... to run live (skipping)");
return Ok(());
};
let signer = PrivateKeySigner::from_str(raw_key.trim())
.expect("SEPOLIA_PRIVATE_KEY must be a 0x-prefixed 32-byte hex string");
let owner = signer.address();
println!("signer: {owner:?}");
let quoted = OrderBookApi::with_chain(Chain::Sepolia)
.build()
.quote_builder()
.with_sell_token(WETH_SEPOLIA)
.with_buy_token(COW_SEPOLIA)
.with_from(owner)
.with_sell_amount(U256::from(SELL_AMOUNT_WEI))
.build()
.await?;
let response = quoted.response();
println!("quote id: {}", response.id);
println!("buy amount: {}", response.quote.buy_amount);
println!("fee amount: {}", response.quote.fee_amount);
println!("valid to: {}", response.quote.valid_to);
let uid = quoted.sign(&signer)?.submit().await?;
println!("order uid: {uid}");
println!("explorer: https://explorer.cow.fi/sepolia/orders/{uid}");
Ok(())
}