Quickstart: Implementing Direct Matches
Renegade settles trades atomically — tokens move directly from your EOA via Permit2 when an order is filled. No deposits or withdrawals are needed.
The following example demonstrates how to use Renegade's SDK to:
- Approve Permit2 to spend your tokens
- Place an order to buy WETH
- Cancel a partially filled order
- Rust
- TypeScript
The full Rust source code, including the defintion of the ensure_allowances()
helper function, can be found
here.
// 1. Create a client
let private_key = std::env::var("PRIVATE_KEY")?;
let signer = PrivateKeySigner::from_str(&private_key)?;
let client = RenegadeClient::new_base_sepolia(&signer)?;
// 2. Create the Renegade account if absent
if client.get_account().await.is_err() {
client.create_account().await?;
}
// 3. Approve Permit2 to spend USDC
let usdc_mint: Address = USDC.parse()?;
let input_amount: u128 = 100_000; // 0.1 USDC (6 decimals)
ensure_allowances(&client, usdc_mint, input_amount, &signer).await?;
// 4. Place a buy order for WETH
// When matched, USDC transfers directly from your EOA via Permit2
let order = client
.new_order_builder()
.with_input_mint(USDC)?
.with_output_mint(WETH)?
.with_input_amount(input_amount)
.with_order_type(OrderType::PublicOrder)
.build()?;
client.place_order(order).await?;
// 5. Wait for a match (in production, poll or use websockets)
tokio::time::sleep(std::time::Duration::from_secs(10)).await;
// 6. Cancel unfilled orders
let orders = client.get_orders(false /* include_historic */).await?;
for order in orders {
println!("Cancelling order... {}", &order.id);
client.cancel_order(order.id).await?;
}
Coming soon.