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: StringSchema 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: MetadataStructured metadata attached to the order.
Implementations§
Source§impl AppDataDoc
impl AppDataDoc
Sourcepub fn new(app_code: impl Into<String>) -> Self
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());Sourcepub fn with_environment(self, env: impl Into<String>) -> Self
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.
Sourcepub fn with_referrer(self, referrer: Referrer) -> Self
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— theReferrercontaining the partner address.
§Returns
self with metadata.referrer set.
Sourcepub fn with_utm(self, utm: Utm) -> Self
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— theUtmtracking parameters.
§Returns
self with metadata.utm set.
Sourcepub fn with_hooks(self, hooks: OrderInteractionHooks) -> Self
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
hooks— theOrderInteractionHookscontaining pre/post lists.
§Returns
self with metadata.hooks set.
Sourcepub fn with_partner_fee(self, fee: PartnerFee) -> Self
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
fee— thePartnerFee(single or multi-entry).
§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());Sourcepub fn with_replaced_order(self, uid: impl Into<String>) -> Self
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— the0x-prefixed order UID of the order being replaced (56 bytes =0x+ 112 hex chars).
§Returns
self with metadata.replaced_order set.
Sourcepub fn with_signer(self, signer: impl Into<String>) -> Self
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— the0x-prefixed Ethereum address of the signing contract.
§Returns
self with metadata.signer set.
Sourcepub const fn with_order_class(self, kind: OrderClassKind) -> Self
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
kind— theOrderClassKindvariant.
§Returns
self with metadata.order_class set.
Sourcepub fn with_bridging(self, bridging: Bridging) -> Self
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
bridging— theBridgingrecord.
§Returns
self with metadata.bridging set.
Sourcepub fn with_flashloan(self, flashloan: Flashloan) -> Self
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
flashloan— theFlashloanrecord.
§Returns
self with metadata.flashloan set.
Sourcepub fn with_wrappers(self, wrappers: Vec<WrapperEntry>) -> Self
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
wrappers— list ofWrapperEntryrecords.
§Returns
self with metadata.wrappers set.
Sourcepub fn with_user_consents(self, consents: Vec<UserConsent>) -> Self
pub fn with_user_consents(self, consents: Vec<UserConsent>) -> Self
Attach UserConsent records for terms of service acceptance.
§Parameters
consents— list ofUserConsentrecords.
§Returns
self with metadata.user_consents set.
Trait Implementations§
Source§impl Clone for AppDataDoc
impl Clone for AppDataDoc
Source§fn clone(&self) -> AppDataDoc
fn clone(&self) -> AppDataDoc
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AppDataDoc
impl Debug for AppDataDoc
Source§impl Default for AppDataDoc
impl Default for AppDataDoc
Source§fn default() -> AppDataDoc
fn default() -> AppDataDoc
Source§impl<'de> Deserialize<'de> for AppDataDoc
impl<'de> Deserialize<'de> for AppDataDoc
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for AppDataDoc
impl Display for AppDataDoc
Auto Trait Implementations§
impl Freeze for AppDataDoc
impl RefUnwindSafe for AppDataDoc
impl Send for AppDataDoc
impl Sync for AppDataDoc
impl Unpin for AppDataDoc
impl UnsafeUnpin for AppDataDoc
impl UnwindSafe for AppDataDoc
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.