pub struct UnsignedOrder {
pub sell_token: Address,
pub buy_token: Address,
pub receiver: Address,
pub sell_amount: Uint<256, 4>,
pub buy_amount: Uint<256, 4>,
pub valid_to: u32,
pub app_data: FixedBytes<32>,
pub fee_amount: Uint<256, 4>,
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: Uint<256, 4>Amount of sell_token to sell (after fee, in atoms).
buy_amount: Uint<256, 4>Minimum amount of buy_token to receive (in atoms).
valid_to: u32Order expiry as Unix timestamp.
app_data: FixedBytes<32>App-data hash (bytes32).
fee_amount: Uint<256, 4>Protocol 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: Uint<256, 4>,
buy_amount: Uint<256, 4>,
) -> UnsignedOrder
pub const fn sell( sell_token: Address, buy_token: Address, sell_amount: Uint<256, 4>, buy_amount: Uint<256, 4>, ) -> UnsignedOrder
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: Uint<256, 4>,
buy_amount: Uint<256, 4>,
) -> UnsignedOrder
pub const fn buy( sell_token: Address, buy_token: Address, sell_amount: Uint<256, 4>, buy_amount: Uint<256, 4>, ) -> UnsignedOrder
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) -> UnsignedOrder
pub const fn with_receiver(self, receiver: Address) -> UnsignedOrder
Override the receiver address.
Sourcepub const fn with_valid_to(self, valid_to: u32) -> UnsignedOrder
pub const fn with_valid_to(self, valid_to: u32) -> UnsignedOrder
Set the order expiry as a Unix timestamp.
Sourcepub const fn with_app_data(self, app_data: FixedBytes<32>) -> UnsignedOrder
pub const fn with_app_data(self, app_data: FixedBytes<32>) -> UnsignedOrder
Set the app-data hash.
Sourcepub const fn with_fee_amount(self, fee_amount: Uint<256, 4>) -> UnsignedOrder
pub const fn with_fee_amount(self, fee_amount: Uint<256, 4>) -> UnsignedOrder
Override the fee amount (defaults to zero).
Sourcepub const fn with_partially_fillable(self) -> UnsignedOrder
pub const fn with_partially_fillable(self) -> UnsignedOrder
Allow partial fills.
Sourcepub const fn with_sell_token_balance(
self,
balance: TokenBalance,
) -> UnsignedOrder
pub const fn with_sell_token_balance( self, balance: TokenBalance, ) -> UnsignedOrder
Override the sell-token balance source.
Sourcepub const fn with_buy_token_balance(
self,
balance: TokenBalance,
) -> UnsignedOrder
pub const fn with_buy_token_balance( self, balance: TokenBalance, ) -> UnsignedOrder
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) -> Uint<256, 4>
pub const fn total_amount(&self) -> Uint<256, 4>
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
Source§impl Display for UnsignedOrder
impl Display for UnsignedOrder
Source§impl TryFrom<&GpV2OrderStruct> for UnsignedOrder
impl TryFrom<&GpV2OrderStruct> for UnsignedOrder
Source§fn try_from(
s: &GpV2OrderStruct,
) -> Result<UnsignedOrder, <UnsignedOrder as TryFrom<&GpV2OrderStruct>>::Error>
fn try_from( s: &GpV2OrderStruct, ) -> Result<UnsignedOrder, <UnsignedOrder as TryFrom<&GpV2OrderStruct>>::Error>
Decode a raw GpV2OrderStruct into a fully typed UnsignedOrder.
Resolves the hashed kind, sell_token_balance, and buy_token_balance
fields back into their enum representations via
crate::from_struct_to_order.
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§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.