pub struct CowSwapConfig {
pub chain_id: SupportedChainId,
pub env: Env,
pub sell_token: Address,
pub sell_token_decimals: u8,
pub tokens: TokenRegistry,
pub slippage_bps: u32,
pub order_valid_secs: u32,
pub receiver: Option<Address>,
}Expand description
Configuration for the CoW Protocol swap executor.
Bundles all parameters needed to submit orders: target chain,
environment, sell token, slippage, TTL, and a TokenRegistry mapping
strategy symbols to on-chain addresses.
Construct via prod or staging, then
customise with the with_* builder methods.
§Example
use alloy_primitives::Address;
use cow_chains::{CowSwapConfig, SupportedChainId, TokenRegistry};
let empty: Vec<(&str, Address)> = vec![];
let config = CowSwapConfig::prod(
SupportedChainId::Mainnet,
Address::ZERO, // sell token
TokenRegistry::new(empty),
50, // 0.5% slippage
1800, // 30 min TTL
);
assert!(config.env.is_prod());
assert_eq!(config.slippage_bps, 50);Fields§
§chain_id: SupportedChainIdTarget chain.
env: EnvAPI environment (Prod or Staging).
sell_token: AddressThe token used as the quote / sell currency (e.g. USDC on Sepolia).
sell_token_decimals: u8Decimal count for Self::sell_token (e.g. 6 for USDC, 18 for WETH).
tokens: TokenRegistryRegistry mapping strategy asset symbols to their on-chain token addresses and decimal counts.
slippage_bps: u32Slippage tolerance in basis points (e.g. 50 = 0.5 %).
order_valid_secs: u32Default order TTL in seconds (e.g. 1800 = 30 min).
receiver: Option<Address>Optional override for the buy-token receiver address.
When None the order receiver defaults to the signing wallet address.
Implementations§
Source§impl CowSwapConfig
impl CowSwapConfig
Sourcepub const fn prod(
chain_id: SupportedChainId,
sell_token: Address,
tokens: TokenRegistry,
slippage_bps: u32,
order_valid_secs: u32,
) -> Self
pub const fn prod( chain_id: SupportedChainId, sell_token: Address, tokens: TokenRegistry, slippage_bps: u32, order_valid_secs: u32, ) -> Self
Convenience constructor defaulting to the production environment.
Self::sell_token_decimals defaults to 18; use
with_sell_token_decimals for
tokens such as USDC (6) or WBTC (8).
§Parameters
chain_id— the targetSupportedChainId.sell_token— the ERC-20Addressof the sell (quote) currency.tokens— theTokenRegistrymapping strategy symbols to tokens.slippage_bps— slippage tolerance in basis points (e.g.50= 0.5 %).order_valid_secs— order TTL in seconds (e.g.1800= 30 min).
§Returns
A new CowSwapConfig targeting Env::Prod with no custom receiver.
Sourcepub const fn staging(
chain_id: SupportedChainId,
sell_token: Address,
tokens: TokenRegistry,
slippage_bps: u32,
order_valid_secs: u32,
) -> Self
pub const fn staging( chain_id: SupportedChainId, sell_token: Address, tokens: TokenRegistry, slippage_bps: u32, order_valid_secs: u32, ) -> Self
Convenience constructor defaulting to the staging (barn) environment.
Same parameters as prod but targets Env::Staging
(barn.api.cow.fi). Self::sell_token_decimals defaults to 18.
§Parameters
See prod for parameter descriptions.
§Returns
A new CowSwapConfig targeting Env::Staging.
Sourcepub const fn with_sell_token(self, token: Address) -> Self
pub const fn with_sell_token(self, token: Address) -> Self
Sourcepub const fn with_chain_id(self, chain_id: SupportedChainId) -> Self
pub const fn with_chain_id(self, chain_id: SupportedChainId) -> Self
Override the chain ID.
§Arguments
chain_id— the new targetSupportedChainId.
§Returns
self with the updated chain ID.
Sourcepub const fn with_slippage_bps(self, slippage_bps: u32) -> Self
pub const fn with_slippage_bps(self, slippage_bps: u32) -> Self
Sourcepub const fn with_order_valid_secs(self, secs: u32) -> Self
pub const fn with_order_valid_secs(self, secs: u32) -> Self
Sourcepub const fn with_sell_token_decimals(self, decimals: u8) -> Self
pub const fn with_sell_token_decimals(self, decimals: u8) -> Self
Sourcepub const fn with_receiver(self, receiver: Address) -> Self
pub const fn with_receiver(self, receiver: Address) -> Self
Sourcepub const fn has_custom_receiver(&self) -> bool
pub const fn has_custom_receiver(&self) -> bool
Returns true if a custom receiver address has been set.
When false, the executor uses the signing wallet address as receiver.
§Returns
true when a receiver override is present.
Sourcepub fn effective_receiver(&self, default: Address) -> Address
pub fn effective_receiver(&self, default: Address) -> Address
Return the effective receiver: the override if set, otherwise default.
§Example
use alloy_primitives::{Address, address};
use cow_chains::{CowSwapConfig, SupportedChainId, TokenRegistry};
let wallet = address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
let empty: Vec<(&str, Address)> = vec![];
let config = CowSwapConfig::prod(
SupportedChainId::Mainnet,
Address::ZERO,
TokenRegistry::new(empty),
50,
1800,
);
assert_eq!(config.effective_receiver(wallet), wallet);
let override_addr = address!("0000000000000000000000000000000000000001");
let with_recv = config.with_receiver(override_addr);
assert_eq!(with_recv.effective_receiver(wallet), override_addr);Trait Implementations§
Source§impl Debug for CowSwapConfig
impl Debug for CowSwapConfig
Auto Trait Implementations§
impl Freeze for CowSwapConfig
impl RefUnwindSafe for CowSwapConfig
impl Send for CowSwapConfig
impl Sync for CowSwapConfig
impl Unpin for CowSwapConfig
impl UnsafeUnpin for CowSwapConfig
impl UnwindSafe for CowSwapConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.