Skip to main content

UnsignedOrder

Struct UnsignedOrder 

Source
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: Address

Token to sell.

§buy_token: Address

Token to buy.

§receiver: Address

Address that receives the bought tokens.

§sell_amount: U256

Amount of sell_token to sell (after fee, in atoms).

§buy_amount: U256

Minimum amount of buy_token to receive (in atoms).

§valid_to: u32

Order expiry as Unix timestamp.

§app_data: B256

App-data hash (bytes32).

§fee_amount: U256

Protocol fee included in sell_amount (in atoms).

§kind: OrderKind

Sell or buy direction.

§partially_fillable: bool

Whether the order may be partially filled.

§sell_token_balance: TokenBalance

Source of sell funds.

§buy_token_balance: TokenBalance

Destination of buy funds.

Implementations§

Source§

impl UnsignedOrder

Source

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 of sell_token to sell (in atoms).
  • buy_amount - Minimum amount of buy_token to receive (in atoms).
§Returns

A new UnsignedOrder with OrderKind::Sell and sensible defaults.

Source

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 of sell_token willing to sell (in atoms).
  • buy_amount - Amount of buy_token to buy (in atoms).
§Returns

A new UnsignedOrder with OrderKind::Buy and sensible defaults.

Source

pub const fn with_receiver(self, receiver: Address) -> Self

Override the receiver address.

Source

pub const fn with_valid_to(self, valid_to: u32) -> Self

Set the order expiry as a Unix timestamp.

Source

pub const fn with_app_data(self, app_data: B256) -> Self

Set the app-data hash.

Source

pub const fn with_fee_amount(self, fee_amount: U256) -> Self

Override the fee amount (defaults to zero).

Source

pub const fn with_partially_fillable(self) -> Self

Allow partial fills.

Source

pub const fn with_sell_token_balance(self, balance: TokenBalance) -> Self

Override the sell-token balance source.

Source

pub const fn with_buy_token_balance(self, balance: TokenBalance) -> Self

Override the buy-token balance destination.

Source

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));
Source

pub const fn is_sell(&self) -> bool

Returns true if this is a sell-direction order.

Source

pub const fn is_buy(&self) -> bool

Returns true if this is a buy-direction order.

Source

pub fn has_custom_receiver(&self) -> bool

Returns true if a non-zero receiver address is set.

Source

pub fn has_app_data(&self) -> bool

Returns true if a non-zero app-data hash is attached.

Source

pub fn has_fee(&self) -> bool

Returns true if the fee amount is non-zero.

Source

pub const fn is_partially_fillable(&self) -> bool

Returns true if this order allows partial fills.

Source

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

Source§

fn clone(&self) -> UnsignedOrder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UnsignedOrder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for UnsignedOrder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more