Off-chain Orders in Rust
This page will walk you through creating and submitting off-chain Orders using Rust and the Signet SDK.
The Orders contract enables trustless, cross-chain asset swaps between Signet and Ethereum. Signet nodes listen for Order and Filled events, and ensure that all transactions that emit Orders have corresponding Fills executed on the destination chain in the same block.
Order events are emitted on Signet, while Filled events may be emitted on either Ethereum or Signet. Off-chain orders are pre-signed, using Permit2, and may be executed by a third-party filler, allowing users to perform gasless swaps.
Setup
Set up your Rust project
cargo new my_cool_app --binInstall the required Signet crates
1cargo add signet-zenith
2cargo add signet-constants
3cargo add signet-types
4cargo add signet-tx-cacheEnsure your account has approved Permit2 to spend your input tokens.
Consult the Pecorino Quickstart guide for contract addresses and RPC endpoints.
Creating an Order
The signet-types crate provides a simple order builder via the UnsignedOrder struct, which can be used to build orders. We can start by creating a simple order that swaps 1 WETH on Signet for 1 WETH on Ethereum:
1use signet_types::signing::order::{UnsignedOrder};
2use signet_constants::pecorino as constants;
3
4let mut order = UnsignedOrder::default()
5 .with_input(
6 constants::RU_WETH,
7 U256::from(1e18), // 1 WETH
8 ).with_output(
9 constants::HOST_WETH,
10 U256::from(1e18),
11 your_address,
12 1, // Ethereum mainnet
13 );The UnsignedOrder struct also provides methods to sign orders, using any
alloy signer. The signer requires that you provide the constants object, so
that the permit2 signer can correctly derive the domain separator.
1use signet_types::signing::order::{UnsignedOrder};
2use signet_constants::pecorino as constants;
3
4let signed = UnsignedOrder::default()
5 .with_input(token_address, amount)
6 .with_output(token_address, amount, recipient, chain_id)
7 .with_chain(constants)
8 .with_nonce(permit2_nonce)
9 .sign(&signer).await?;Submitting an Order
Once signed, the order can be submitted to the Signet network via the Signet tx cache. The tx cache makes the Order available to Searchers, who will include it in execution bundles.
1use signet_tx_cache::TxCache;
2
3let tx_cache = TxCache::pecorino();
4tx_cache.forward_order(signed_order).await?;For on-chain order creation, check out Solidity Orders.