use crate::error::{VerificationError, VerificationKind};
pub(crate) const TYPED_DATA: &str = "typed_data";
pub(crate) const DOMAIN: &str = "domain";
pub(crate) const PRIMARY_TYPE: &str = "primaryType";
pub(crate) const TYPES: &str = "types";
pub(crate) const MESSAGE: &str = "message";
pub(crate) const OP: &str = "op";
pub(crate) const SIGNER: &str = "signer";
pub(crate) const DIGEST: &str = "digest";
pub(crate) const SIGNING_WINDOW: &str = "signing window";
pub(crate) const CHALLENGE: &str = "challenge";
pub(crate) const CHALLENGE_WINDOW: &str = "challenge window";
pub(crate) const FILLS_TAKER_FEE: &str = "fills.taker_fee";
pub(crate) const FILLS_SWAP_ID: &str = "fills.swap_id";
pub(crate) const BOOK: &str = "book";
pub(crate) const FEE_ABOVE_ACCEPTED: &str = "fee above accepted";
pub(crate) const REGISTRY: &str = "registry";
pub(crate) const ESCROW: &str = "escrow";
pub(crate) const SETTLEMENT: &str = "settlement";
pub(crate) const ENVIRONMENT: &str = "environment";
pub(crate) const NO_ESCROW_VENUE: &str = "no escrow venue";
pub(crate) const VENUE: &str = "venue";
pub(crate) const TO_SIGN: &str = "to_sign";
pub(crate) const TO_SIGN_KIND: &str = "to_sign.kind";
pub(crate) const TO_SIGN_SIGNER: &str = "to_sign.signer";
pub(crate) const KIND: &str = "kind";
pub(crate) const SETUP_STEP: &str = "step";
pub(crate) const SETUP_KIND: &str = "step.kind";
pub(crate) const OWNER: &str = "owner";
pub(crate) const SPENDER: &str = "spender";
pub(crate) const VALUE: &str = "value";
pub(crate) const DEADLINE: &str = "deadline";
pub(crate) const AGENT_APPROVAL: &str = "agent approval";
pub(crate) const AGENT_USER: &str = "agent approval.user";
pub(crate) const AGENT_NONCE: &str = "agent approval.nonce";
pub(crate) const AGENT: &str = "agent approval.agent";
pub(crate) const AGENT_EXPIRY: &str = "agent approval.expired";
pub(crate) const AGENT_PERMISSIONS: &str = "agent approval.permissions";
pub(crate) const AGENT_ADDRESSES: &str = "agent approval.ipWhitelist";
pub(crate) const LIGHTER_REGISTRATION: &str = "lighter registration";
pub(crate) const LIGHTER_OWNER: &str = "lighter registration.owner";
pub(crate) const LINKED_ACCOUNT: &str = "linked account";
pub(crate) const FUNDING: &str = "funding";
pub(crate) const DESTINATION: &str = "destination";
pub(crate) const MINIMUM_RECEIVED: &str = "minimum_received";
pub(crate) const DESTINATION_OWNER: &str = "delivery_to.owner";
pub(crate) const WALLET_FUNDS: &str = "wallet funds";
pub(crate) const WALLET_FUNDS_OBSERVED_AT: &str = "wallet funds.observed_at";
pub(crate) const FILLS: &str = "fills";
pub(crate) const FILLS_ID: &str = "fills.id";
pub(crate) const FILLS_ROLE: &str = "fills.role";
pub(crate) const FILLS_FROM_VENUE: &str = "fills.from_venue";
pub(crate) const FILLS_TO_VENUE: &str = "fills.to_venue";
pub(crate) const FILLS_PAYER: &str = "fills.payer";
pub(crate) const FILLS_TAKER_RECIPIENT: &str = "fills.taker_recipient";
pub(crate) const FILLS_DESTINATION: &str = "fills.destination";
pub(crate) const FILLS_AMOUNT_IN: &str = "fills.amount_in";
pub(crate) const FILLS_AMOUNT_OUT: &str = "fills.amount_out";
pub(crate) const FILLS_DELIVERY_TO: &str = "fills.delivery_to";
pub(crate) const FILLS_PAY_BY: &str = "fills.pay_by";
pub(crate) const FILLS_T1: &str = "fills.t1";
pub(crate) const FILLS_T2: &str = "fills.t2";
pub(crate) const AMOUNT_IN: &str = "amount_in";
pub(crate) const AMOUNT_OUT: &str = "amount_out";
pub(crate) const PAYER: &str = "payer";
pub(crate) const FILL_ID: &str = "fill_id";
pub(crate) const PAYMENTS: &str = "payments";
pub(crate) const PAYMENTS_SWAP_ID: &str = "payments.swapId";
pub(crate) const PAYMENTS_PAYER: &str = "payments.payer";
pub(crate) const PAYMENTS_RECIPIENT: &str = "payments.recipient";
pub(crate) const PAYMENTS_HASHLOCK: &str = "payments.hashlock";
pub(crate) const PAYMENTS_AMOUNT: &str = "payments.amount";
pub(crate) const PAYMENTS_REFUND_AT: &str = "payments.refundAt";
pub(crate) const PAYMENTS_DEADLINE: &str = "payments.deadline";
pub(crate) const PAYMENTS_DEX: &str = "payments.dex";
pub(crate) const PAYMENTS_ORDER_ID: &str = "payments.orderId";
pub(crate) const PAYMENTS_SEQUENCE: &str = "payments.sequence";
pub(crate) const PAYMENTS_AMOUNT_OUT: &str = "payments.amountOut";
pub(crate) const PAYMENTS_RECEIVE_RECIPIENT: &str = "payments.receiveRecipient";
pub(crate) const PAYMENTS_RECEIVE: &str = "payments.receive";
pub(crate) const DEPOSIT: &str = "deposit";
pub(crate) const LIGHTER_TRANSFER: &str = "lighter transfer";
pub(crate) const LIGHTER_KEY: &str = "lighter transfer.api_key_index";
pub(crate) const LIGHTER_FEE: &str = "lighter transfer.usdc_fee";
pub(crate) const LIGHTER_MAKER_ACCOUNT: &str = "lighter transfer.to_account_index";
pub(crate) const LIGHTER_PAYER_ACCOUNT: &str = "lighter transfer.from_account_index";
pub(crate) const ASTER_TRANSFER: &str = "aster transfer";
pub(crate) const ASTER_NONCE: &str = "aster transfer.nonce";
pub(crate) const FUNDING_PLAN: &str = "funding_plan";
pub(crate) const FUNDING_WITHDRAWAL: &str = "funding_plan.withdrawal_to";
pub(crate) const FUNDING_OBSERVED_AT: &str = "funding_plan.observed_at";
pub(crate) const FUNDING_REQUESTS: &str = "funding_plan.requests";
pub(crate) const WALLET_FUNDING: &str = "wallet_funding";
pub(crate) const AMOUNT: &str = "amount";
pub(crate) const RECIPIENT: &str = "recipient";
pub(crate) const HYPERLIQUID_CHAIN: &str = "hyperliquidChain";
pub(crate) const TOKEN: &str = "token";
pub(crate) const FROM_SUB_ACCOUNT: &str = "fromSubAccount";
pub(crate) const SOURCE_DEX: &str = "sourceDex";
pub(crate) const DESTINATION_DEX: &str = "destinationDex";
pub(crate) const NONCE: &str = "nonce";
pub(crate) const TS: &str = "ts";
pub(crate) const ACCOUNT: &str = "account";
pub(crate) const TO: &str = "to";
pub(crate) const FEE: &str = "fee";
pub(crate) const DATA: &str = "data";
pub(crate) const USER: &str = "user";
pub(crate) const TO_ADDRESS: &str = "toAddress";
pub(crate) const CLIENT_TRAN_ID: &str = "clientTranId";
pub(crate) const STATE: &str = "state";
pub(crate) const CLIENT_REQUEST_ID: &str = "client_request_id";
pub(crate) const ORDER_OWNER_ADDRESS: &str = "order.owner_address";
pub(crate) const ORDER_QUOTE_SIGNER: &str = "order.quote_signer";
pub(crate) const ORDER_QUOTE_IDENTITY_ID: &str = "order.quote_identity_id";
pub(crate) const INTENT_AMOUNT: &str = "intent.amount";
pub(crate) const INTENT_QUOTE_IDENTITY_ID: &str = "intent.quote_identity_id";
pub(crate) const INTENT_FUNDING_SOURCE: &str = "intent.funding_source";
pub(crate) const EXPECTED_REVISION: &str = "expected_revision";
pub(crate) const EXPIRES_AT: &str = "expires_at";
pub(crate) const ORDER_ID: &str = "order.id";
pub(crate) const EXISTING_ORDER: &str = "existing order";
pub(crate) const MAKER_CAPITAL: &str = "maker capital";
pub(crate) const ORDER: &str = "order";
pub(crate) const FUNDING_EXISTING_AVAILABLE: &str = "funding.existing_available";
pub(crate) const FUNDING_IDLE_AMOUNT: &str = "funding.idle_amount";
pub(crate) const FUNDING_WALLET_AMOUNT: &str = "funding.wallet_amount";
pub(crate) const FUNDING_VENUE_AMOUNT: &str = "funding.venue_amount";
pub(crate) const FUNDING_DEPOSIT: &str = "funding.deposit";
pub(crate) const SEQUENCE: &str = "sequence";
pub(crate) const MARGIN_MOVE_SIGNER: &str = "margin_move.signer";
pub(crate) const MARGIN_MOVE_AMOUNT: &str = "margin_move.amount";
pub(crate) const FUND_SIGNER: &str = "fund.signer";
pub(crate) const FUND_OWNER: &str = "fund.owner";
pub(crate) const FUND_OFFER_ID: &str = "fund.offerId";
pub(crate) const FUND_AMOUNT: &str = "fund.amount";
pub(crate) const FUND_DEPOSIT: &str = "fund.deposit";
pub(crate) const FUND_QUOTE_SIGNER: &str = "fund.quoteSigner";
pub(crate) const FUND_OPERATOR: &str = "fund.operator";
pub(crate) const FUND_MIN_QUOTE_SEQUENCE: &str = "fund.minQuoteSequence";
pub(crate) const OFFER_ID: &str = "offerId";
pub(crate) const QUOTES: &str = "quotes";
pub(crate) const QUOTES_VENUE: &str = "quotes.venue";
pub(crate) const QUOTES_CHAIN_ID: &str = "quotes.chainId";
pub(crate) const QUOTES_TOKEN: &str = "quotes.token";
pub(crate) const QUOTES_RECIPIENT: &str = "quotes.recipient";
pub(crate) const QUOTES_SUPPLY: &str = "quotes.supply";
pub(crate) const QUOTES_RECEIVE: &str = "quotes.receive";
pub(crate) const QUOTES_MIN_FILL: &str = "quotes.minFill";
pub(crate) const ORDERS: &str = "orders";
pub(crate) const CREDENTIAL_QUOTE_SIGNER: &str = "credential.quote_signer";
pub(crate) const CREDENTIAL_SCOPES: &str = "credential.scopes";
pub(crate) const QUOTE_IDENTITY_ID: &str = "quote_identity_id";
pub(crate) const VALID_UNTIL: &str = "valid_until";
pub(crate) const LINES: &str = "lines";
pub(crate) const DRAFTS: &str = "drafts";
pub(crate) const DRAFTS_ORDER_ID: &str = "drafts.order_id";
pub(crate) const DRAFTS_VENUE: &str = "drafts.venue";
pub(crate) const DRAFTS_QUOTES: &str = "drafts.quotes";
pub(crate) const DRAFTS_QUOTES_VENUE: &str = "drafts.quotes.venue";
pub(crate) const DRAFTS_QUOTES_RECIPIENT: &str = "drafts.quotes.recipient";
pub(crate) const DRAFTS_QUOTES_SUPPLY: &str = "drafts.quotes.supply";
pub(crate) const DRAFTS_QUOTES_RECEIVE: &str = "drafts.quotes.receive";
pub(crate) const DRAFTS_QUOTES_MIN_FILL: &str = "drafts.quotes.min_fill";
pub(crate) const QUOTE_SIZE: &str = "quote_size";
pub(crate) const POOL_STATE: &str = "pool.state";
pub(crate) const POOL_QUOTE_SIGNER: &str = "pool.quote_signer";
pub(crate) const CANCELS: &str = "cancels";
pub(crate) const MOVE_ID: &str = "move_id";
pub(crate) const BRIDGE_WALLET: &str = "bridge wallet";
pub(crate) const BRIDGE_ORIGIN: &str = "bridge origin";
pub(crate) const BRIDGE_VENUE: &str = "bridge venue";
pub(crate) const BRIDGE_FUNDING: &str = "bridge funding";
pub(crate) const BRIDGE_ORDER: &str = "order.data";
pub(crate) const ORDER_VERSION: &str = "order.version";
pub(crate) const ORDER_SOLVER: &str = "order.solver";
pub(crate) const ORDER_FEES: &str = "order.fees";
pub(crate) const ORDER_INPUTS: &str = "order.inputs";
pub(crate) const ORDER_INPUT: &str = "order.inputs.payment";
pub(crate) const ORDER_AMOUNT: &str = "order.inputs.payment.amount";
pub(crate) const ORDER_REFUND: &str = "order.inputs.refunds";
pub(crate) const ORDER_REFUND_EXTRA: &str = "order.inputs.refunds.extraData";
pub(crate) const ORDER_OUTPUT_CHAIN: &str = "order.output.chainId";
pub(crate) const ORDER_OUTPUT_EXTRA: &str = "order.output.extraData";
pub(crate) const ORDER_DEADLINE: &str = "order.output.deadline";
pub(crate) const ORDER_PAYMENTS: &str = "order.output.payments";
pub(crate) const ORDER_CURRENCY: &str = "order.output.payments.currency";
pub(crate) const ORDER_MINIMUM: &str = "order.output.payments.minimumAmount";
pub(crate) const ORDER_RECIPIENT: &str = "order.output.payments.recipient";
pub(crate) const ACCOUNT_CREDIT: &str = "account credit";
pub(crate) const ORDER_CALLS: &str = "order.output.calls";
pub(crate) const fn differs(detail: &'static str) -> VerificationError {
VerificationError { kind: VerificationKind::Differs, detail, index: None }
}
pub(crate) const fn stale(detail: &'static str) -> VerificationError {
VerificationError { kind: VerificationKind::Stale, detail, index: None }
}
pub(crate) const fn changed(detail: &'static str) -> VerificationError {
VerificationError { kind: VerificationKind::Changed, detail, index: None }
}
pub(crate) const fn deployment(detail: &'static str) -> VerificationError {
VerificationError { kind: VerificationKind::Deployment, detail, index: None }
}
pub(crate) const fn unsupported(detail: &'static str) -> VerificationError {
VerificationError { kind: VerificationKind::Unsupported, detail, index: None }
}
pub(crate) const fn at(error: VerificationError, index: usize) -> VerificationError {
match error.index {
Some(_) => error,
None => VerificationError { index: Some(index), ..error },
}
}
#[cfg(test)]
mod tests {
use std::path::Path;
#[test]
fn checks_report_no_literal_detail() {
fn visit(path: &Path, offenders: &mut Vec<String>) {
if path.is_dir() {
for entry in std::fs::read_dir(path).unwrap() {
visit(&entry.unwrap().path(), offenders);
}
return;
}
let text = std::fs::read_to_string(path).unwrap();
let literals = [
"differs(\"",
"stale(\"",
"changed(\"",
"deployment(\"",
"unsupported(\"",
"detail: \"",
];
offenders.extend(
literals
.iter()
.filter(|literal| text.contains(*literal))
.map(|literal| format!("{}: {literal}", path.display())),
);
}
let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
let mut offenders = Vec::new();
visit(&src.join("protocol"), &mut offenders);
visit(&src.join("book.rs"), &mut offenders);
assert!(offenders.is_empty(), "literal details: {offenders:?}");
}
}