Skip to main content

AppDataDoc

Struct AppDataDoc 

Source
pub struct AppDataDoc {
    pub version: String,
    pub app_code: Option<String>,
    pub environment: Option<String>,
    pub metadata: Metadata,
}
Expand description

Root document for CoW Protocol order app-data (schema v1.14.0).

Every CoW Protocol order carries a 32-byte appData field that commits to a JSON document describing the order’s intent, referral, hooks, and more. AppDataDoc is the Rust representation of that JSON document.

Serialise this struct to canonical JSON with appdata_hex to obtain the keccak256 hash used on-chain, or use get_app_data_info to derive the hash, CID, and canonical JSON in one call.

Use the builder methods (with_*) to attach optional metadata:

§Example

use cow_app_data::{AppDataDoc, OrderClassKind, Quote, Referrer};

let doc = AppDataDoc::new("MyDApp")
    .with_environment("production")
    .with_referrer(Referrer::code("COWRS-PARTNER"))
    .with_order_class(OrderClassKind::Limit);

assert_eq!(doc.app_code.as_deref(), Some("MyDApp"));
assert_eq!(doc.environment.as_deref(), Some("production"));
assert!(doc.metadata.has_referrer());
assert!(doc.metadata.has_order_class());

Fields§

§version: String

Schema version, e.g. "1.14.0".

§app_code: Option<String>

Application identifier, e.g. "CoW Swap" or your app name.

§environment: Option<String>

Deployment environment, e.g. "production".

§metadata: Metadata

Structured metadata attached to the order.

Implementations§

Source§

impl AppDataDoc

Source

pub fn new(app_code: impl Into<String>) -> Self

Create a minimal AppDataDoc with the given app_code and no extra metadata.

Sets version to LATEST_APP_DATA_VERSION, app_code to the provided value, and metadata to its Default (all fields None).

§Parameters
  • app_code — application identifier (e.g. "CoW Swap", "MyDApp"). Must be ≤ 50 characters to pass validation.
§Returns

A new AppDataDoc ready to be hashed or further customised with the with_* builder methods.

§Example
use cow_app_data::AppDataDoc;

let doc = AppDataDoc::new("MyDApp");
assert_eq!(doc.app_code.as_deref(), Some("MyDApp"));
assert_eq!(doc.version, "1.14.0");
assert!(!doc.metadata.has_referrer());
Source

pub fn with_environment(self, env: impl Into<String>) -> Self

Set the deployment environment (e.g. "production", "staging").

The environment string is included in the canonical JSON and therefore affects the keccak256 hash. Use it to distinguish orders from different deployment stages.

§Parameters
  • env — free-form environment label.
§Returns

self with environment set.

Source

pub fn with_referrer(self, referrer: Referrer) -> Self

Attach a Referrer address for partner attribution.

The referrer’s Ethereum address is embedded in the order’s app-data so the protocol can attribute volume to integration partners.

§Parameters
  • referrer — the Referrer containing the partner address.
§Returns

self with metadata.referrer set.

Source

pub fn with_utm(self, utm: Utm) -> Self

Attach Utm campaign tracking parameters.

UTM parameters (source, medium, campaign, content, term) let analytics pipelines attribute order volume to marketing campaigns.

§Parameters
  • utm — the Utm tracking parameters.
§Returns

self with metadata.utm set.

Source

pub fn with_hooks(self, hooks: OrderInteractionHooks) -> Self

Attach pre- and/or post-settlement interaction hooks.

Hooks are arbitrary contract calls the settlement contract executes before (pre) or after (post) the trade. See CowHook for details on individual hook entries.

§Parameters
§Returns

self with metadata.hooks set.

Source

pub fn with_partner_fee(self, fee: PartnerFee) -> Self

Attach a PartnerFee policy to this order.

Partner fees are charged by integration partners as a percentage of the trade. Each fee entry specifies a basis-point rate and a recipient address.

§Parameters
§Returns

self with metadata.partner_fee set.

§Example
use cow_app_data::{AppDataDoc, PartnerFee, PartnerFeeEntry};

let doc = AppDataDoc::new("MyDApp")
    .with_partner_fee(PartnerFee::single(PartnerFeeEntry::volume(50, "0xRecipient")));
assert!(doc.metadata.has_partner_fee());
Source

pub fn with_replaced_order(self, uid: impl Into<String>) -> Self

Mark this order as replacing a previously submitted order.

The protocol uses this to link replacement orders for analytics and to avoid double-fills.

§Parameters
  • uid — the 0x-prefixed order UID of the order being replaced (56 bytes = 0x + 112 hex chars).
§Returns

self with metadata.replaced_order set.

Source

pub fn with_signer(self, signer: impl Into<String>) -> Self

Attach the signer address for EIP-1271 or other smart-contract signers.

When the order is signed by a smart contract (not an EOA), this field records the contract address that will validate the signature on-chain.

§Parameters
  • signer — the 0x-prefixed Ethereum address of the signing contract.
§Returns

self with metadata.signer set.

Source

pub const fn with_order_class(self, kind: OrderClassKind) -> Self

Set the order class kind (market, limit, liquidity, or twap).

Solvers and the protocol UI use this to decide execution strategy and display. See OrderClassKind for the available variants.

§Parameters
§Returns

self with metadata.order_class set.

Source

pub fn with_bridging(self, bridging: Bridging) -> Self

Attach cross-chain Bridging metadata.

Records which bridge provider was used, the destination chain, and the destination token address so solvers and analytics can trace cross-chain flows.

§Parameters
§Returns

self with metadata.bridging set.

Source

pub fn with_flashloan(self, flashloan: Flashloan) -> Self

Attach Flashloan execution metadata.

Records the flash-loan parameters (amount, provider, token, adapter, receiver) so the settlement contract and solvers can reconstruct the flash-loan flow.

§Parameters
§Returns

self with metadata.flashloan set.

Source

pub fn with_wrappers(self, wrappers: Vec<WrapperEntry>) -> Self

Attach token WrapperEntry records.

Wrapper entries describe token wrapping/unwrapping operations applied during order execution (e.g. WETH ↔ ETH).

§Parameters
§Returns

self with metadata.wrappers set.

Source

pub fn with_user_consents(self, consents: Vec<UserConsent>) -> Self

Attach UserConsent records for terms of service acceptance.

§Parameters
§Returns

self with metadata.user_consents set.

Trait Implementations§

Source§

impl Clone for AppDataDoc

Source§

fn clone(&self) -> AppDataDoc

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 AppDataDoc

Source§

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

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

impl Default for AppDataDoc

Source§

fn default() -> AppDataDoc

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for AppDataDoc

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for AppDataDoc

Source§

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

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

impl Serialize for AppDataDoc

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,