pub struct UnsignedOrder {
pub sell_token: Address,
pub buy_token: Address,
pub receiver: Address,
pub sell_amount: U256,
pub buy_amount: U256,
pub valid_to: u32,
pub app_data: B256,
pub fee_amount: U256,
pub kind: OrderKind,
pub partially_fillable: bool,
pub sell_token_balance: TokenBalance,
pub buy_token_balance: TokenBalance,
}Expand description
An unsigned CoW Protocol order ready to be hashed and signed.
Fields§
§sell_token: AddressToken to sell.
buy_token: AddressToken to buy.
receiver: AddressAddress that receives the bought tokens.
sell_amount: U256Amount of sell_token to sell (after fee, in atoms).
buy_amount: U256Minimum amount of buy_token to receive (in atoms).
valid_to: u32Order expiry as Unix timestamp.
app_data: B256App-data hash (bytes32).
fee_amount: U256Protocol fee included in sell_amount (in atoms).
kind: OrderKindSell or buy direction.
partially_fillable: boolWhether the order may be partially filled.
sell_token_balance: TokenBalanceSource of sell funds.
buy_token_balance: TokenBalanceDestination of buy funds.
Implementations§
Source§impl UnsignedOrder
impl UnsignedOrder
Sourcepub const fn sell(
sell_token: Address,
buy_token: Address,
sell_amount: U256,
buy_amount: U256,
) -> Self
pub const fn sell( sell_token: Address, buy_token: Address, sell_amount: U256, buy_amount: U256, ) -> Self
Construct a sell order with defaults: ERC-20 balances, fee_amount = 0,
app_data = B256::ZERO, valid_to = 0, receiver = Address::ZERO.
Use the builder methods to override any field before signing.
§Arguments
sell_token- Address of the token to sell.buy_token- Address of the token to buy.sell_amount- Amount ofsell_tokento sell (in atoms).buy_amount- Minimum amount ofbuy_tokento receive (in atoms).
§Returns
A new UnsignedOrder with OrderKind::Sell and sensible defaults.
Sourcepub const fn buy(
sell_token: Address,
buy_token: Address,
sell_amount: U256,
buy_amount: U256,
) -> Self
pub const fn buy( sell_token: Address, buy_token: Address, sell_amount: U256, buy_amount: U256, ) -> Self
Construct a buy order with defaults: ERC-20 balances, fee_amount = 0,
app_data = B256::ZERO, valid_to = 0, receiver = Address::ZERO.
§Arguments
sell_token- Address of the token to sell.buy_token- Address of the token to buy.sell_amount- Maximum amount ofsell_tokenwilling to sell (in atoms).buy_amount- Amount ofbuy_tokento buy (in atoms).
§Returns
A new UnsignedOrder with OrderKind::Buy and sensible defaults.
Sourcepub const fn with_receiver(self, receiver: Address) -> Self
pub const fn with_receiver(self, receiver: Address) -> Self
Override the receiver address.
Sourcepub const fn with_valid_to(self, valid_to: u32) -> Self
pub const fn with_valid_to(self, valid_to: u32) -> Self
Set the order expiry as a Unix timestamp.
Sourcepub const fn with_app_data(self, app_data: B256) -> Self
pub const fn with_app_data(self, app_data: B256) -> Self
Set the app-data hash.
Sourcepub const fn with_fee_amount(self, fee_amount: U256) -> Self
pub const fn with_fee_amount(self, fee_amount: U256) -> Self
Override the fee amount (defaults to zero).
Sourcepub const fn with_partially_fillable(self) -> Self
pub const fn with_partially_fillable(self) -> Self
Allow partial fills.
Sourcepub const fn with_sell_token_balance(self, balance: TokenBalance) -> Self
pub const fn with_sell_token_balance(self, balance: TokenBalance) -> Self
Override the sell-token balance source.
Sourcepub const fn with_buy_token_balance(self, balance: TokenBalance) -> Self
pub const fn with_buy_token_balance(self, balance: TokenBalance) -> Self
Override the buy-token balance destination.
Sourcepub const fn is_expired(&self, timestamp: u64) -> bool
pub const fn is_expired(&self, timestamp: u64) -> bool
Returns true if the order has expired at the given Unix timestamp.
An order is expired when timestamp > valid_to.
use alloy_primitives::{Address, U256};
use cow_types::UnsignedOrder;
let order = UnsignedOrder::sell(Address::ZERO, Address::ZERO, U256::ZERO, U256::ZERO)
.with_valid_to(1_000_000);
assert!(!order.is_expired(999_999));
assert!(!order.is_expired(1_000_000)); // valid_to is inclusive
assert!(order.is_expired(1_000_001));Sourcepub fn has_custom_receiver(&self) -> bool
pub fn has_custom_receiver(&self) -> bool
Returns true if a non-zero receiver address is set.
Sourcepub fn has_app_data(&self) -> bool
pub fn has_app_data(&self) -> bool
Returns true if a non-zero app-data hash is attached.
Sourcepub const fn is_partially_fillable(&self) -> bool
pub const fn is_partially_fillable(&self) -> bool
Returns true if this order allows partial fills.
Sourcepub const fn total_amount(&self) -> U256
pub const fn total_amount(&self) -> U256
Returns the total token amount at stake: sell_amount + buy_amount.
Uses saturating addition to avoid overflow on extreme values.
Trait Implementations§
Source§impl Clone for UnsignedOrder
impl Clone for UnsignedOrder
Source§fn clone(&self) -> UnsignedOrder
fn clone(&self) -> UnsignedOrder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UnsignedOrder
impl Debug for UnsignedOrder
Auto Trait Implementations§
impl Freeze for UnsignedOrder
impl RefUnwindSafe for UnsignedOrder
impl Send for UnsignedOrder
impl Sync for UnsignedOrder
impl Unpin for UnsignedOrder
impl UnsafeUnpin for UnsignedOrder
impl UnwindSafe for UnsignedOrder
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.