#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct Op {
pub(crate) id: &'static str,
pub(crate) method: Method,
pub(crate) path: &'static str,
pub(crate) auth: AuthTier,
pub(crate) retry: bool,
pub(crate) secret: bool,
pub(crate) answers: &'static [u16],
}
impl Op {
const fn new(id: &'static str, method: Method, path: &'static str, auth: AuthTier) -> Self {
let retry = matches!(method, Method::Get);
Self { id, method, path, auth, retry, secret: false, answers: &[] }
}
const fn get(id: &'static str, path: &'static str, auth: AuthTier) -> Self {
Self::new(id, Method::Get, path, auth)
}
const fn post(id: &'static str, path: &'static str, auth: AuthTier) -> Self {
Self::new(id, Method::Post, path, auth)
}
const fn put(id: &'static str, path: &'static str, auth: AuthTier) -> Self {
Self::new(id, Method::Put, path, auth)
}
const fn delete(id: &'static str, path: &'static str, auth: AuthTier) -> Self {
Self::new(id, Method::Delete, path, auth)
}
const fn retried(self) -> Self {
Self { retry: true, ..self }
}
const fn secret(self) -> Self {
Self { secret: true, ..self }
}
const fn answers(self, statuses: &'static [u16]) -> Self {
Self { answers: statuses, ..self }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Method {
Get,
Post,
Put,
Delete,
}
impl Method {
pub(crate) const fn as_str(self) -> &'static str {
match self {
Self::Get => "GET",
Self::Post => "POST",
Self::Put => "PUT",
Self::Delete => "DELETE",
}
}
pub(crate) fn as_reqwest(self) -> reqwest::Method {
match self {
Self::Get => reqwest::Method::GET,
Self::Post => reqwest::Method::POST,
Self::Put => reqwest::Method::PUT,
Self::Delete => reqwest::Method::DELETE,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum AuthTier {
Public,
OptionalSession,
Session,
SessionOrCredential,
}
macro_rules! ops {
($( $(#[$meta:meta])* $name:ident = $op:expr; )+) => {
$( $(#[$meta])* pub(crate) const $name: Op = $op; )+
#[cfg(test)]
pub(crate) const ALL: &[Op] = &[$($name),+];
};
}
use AuthTier::{OptionalSession, Public, Session, SessionOrCredential as Either};
ops! {
GET_VENUES = Op::get("getVenues", "/v1/venues", Public);
GET_BOOK = Op::get("getBook", "/v1/books", Public);
GET_MARKETS = Op::get("getMarkets", "/v1/markets", Public);
GET_VOLUME = Op::get("getVolume", "/v1/volume", Public);
GET_HEALTH = Op::get("getHealth", "/health", Public).answers(&[503]);
GET_INFO = Op::get("getV1Info", "/v1/info", Public);
GET_TRADE_PROOF = Op::get("getTradeProof", "/v1/trades/{id}/proof", Public);
GET_EXPLORER_TRANSFERS =
Op::get("getExplorerTransfers", "/v1/explorer/transfers", OptionalSession);
GET_EXPLORER_PENDING_TRANSFERS = Op::get(
"getExplorerPendingTransfers",
"/v1/explorer/transfers/pending",
OptionalSession,
);
GET_EXPLORER_TRANSFER =
Op::get("getExplorerTransfer", "/v1/explorer/transfers/{id}", Public);
GET_TRADE_HISTORY = Op::get("getV1TradesHistory", "/v1/trades/history", OptionalSession);
GET_PENDING_TRADES = Op::get("getV1TradesPending", "/v1/trades/pending", OptionalSession);
GET_EVENTS = Op::get("getV1Events", "/v1/events", Public);
GET_MY_EVENTS = Op::get("getV1MeEvents", "/v1/me/events", Either);
GET_SNAPSHOT = Op::get("getV1Snapshot", "/v1/snapshot", Public);
GET_MY_SNAPSHOT = Op::get("getV1MeSnapshot", "/v1/me/snapshot", Either);
STREAM = Op::get("getV1Stream", "/v1/stream", Public);
GET_ME = Op::get("getMe", "/v1/me", Session);
GET_BALANCES = Op::get("getBalances", "/v1/balances", Session);
GET_STATS = Op::get("getStats", "/v1/me/stats", Session);
GET_EXPOSURE = Op::get("getV1MeExposure", "/v1/me/exposure", Either);
GET_VENUE_SETUP = Op::get("getVenueSetup", "/v1/accounts/{venue}/setup", Session);
GET_WALLET_FUNDING = Op::get("getWalletFunding", "/v1/wallets/{venue}", Session);
GET_ESCROW = Op::get("getEscrow", "/v1/escrow", Session);
DELETE_LINK = Op::delete("deleteLink", "/v1/accounts/{venue}", Session);
GET_ROUTE = Op::get("getRoute", "/v1/routes", Session);
GET_TRANSFERS = Op::get("getTransfers", "/v1/transfers", Session);
GET_TRANSFER = Op::get("getTransfer", "/v1/transfers/{id}", Session);
CANCEL_TRANSFER = Op::delete("cancelTransfer", "/v1/transfers/{id}", Session);
POST_TRANSFER = Op::post("postTransfer", "/v1/transfers", Session).retried();
PREPARE_TRANSFER_WITHDRAWAL = Op::post(
"prepareTransferWithdrawal",
"/v1/transfers/{id}/withdrawal/prepare",
Session,
);
SUBMIT_TRANSFER_WITHDRAWAL =
Op::post("submitTransferWithdrawal", "/v1/transfers/{id}/withdrawal", Session)
.retried();
PREPARE_TRANSFER_CONVERSION = Op::post(
"prepareTransferConversion",
"/v1/transfers/{id}/conversion/prepare",
Session,
)
.retried();
FENCE_TRANSFER_CONVERSION =
Op::post("reportTransferConversion", "/v1/transfers/{id}/conversion", Session);
REPORT_TRANSFER_CONVERSION = FENCE_TRANSFER_CONVERSION.retried();
PREPARE_GROUPED_ROUTE =
Op::post("prepareGroupedRoute", "/v1/transfers/{id}/grouped", Session).secret();
ABORT_GROUPED_ROUTE =
Op::delete("abortGroupedRoute", "/v1/transfers/{id}/grouped", Session).retried();
COMMIT_GROUPED_ROUTE =
Op::post("commitGroupedRoute", "/v1/transfers/{id}/grouped/signatures", Session)
.retried();
GET_TAKE = Op::get("getV1TakesId", "/v1/takes/{id}", Session).secret();
DELETE_TAKE = Op::delete("deleteTake", "/v1/takes/{id}", Session);
GET_TAKE_HISTORY = Op::get("getTakeHistory", "/v1/takes/history", Session).secret();
GET_FILLS = Op::get("getFills", "/v1/fills", Either).secret();
GET_FILL_HISTORY = Op::get("getV1FillsHistory", "/v1/fills/history", Either);
ACCEPT_FILL = Op::post("acceptFill", "/v1/fills/{id}/accept", Either).retried();
SUBMIT_DELIVERY =
Op::post("submitDelivery", "/v1/fills/{id}/delivery", Either).retried().secret();
PREPARE_PAYMENT_REFUND =
Op::post("preparePaymentRefund", "/v1/fills/{id}/refund/prepare", Session);
SUBMIT_PAYMENT_REFUND =
Op::post("submitPaymentRefund", "/v1/fills/{id}/refund", Session).retried();
GET_ORDERS = Op::get("getOrders", "/v1/orders", Either);
GET_ORDER = Op::get("getOrder", "/v1/orders/{id}", Either);
GET_ORDER_HISTORY = Op::get("getV1OrdersHistory", "/v1/orders/history", Either);
DELETE_QUOTES = Op::delete("deleteQuotes", "/v1/orders/{id}/quotes", Either);
GET_WITHDRAWAL_HISTORY =
Op::get("getV1WithdrawalsHistory", "/v1/withdrawals/history", Session);
CREATE_CREDENTIAL = Op::post("postV1Credentials", "/v1/credentials", Session).secret();
DELETE_CREDENTIAL = Op::delete("deleteV1CredentialsId", "/v1/credentials/{id}", Session);
ROTATE_CREDENTIAL =
Op::post("postV1CredentialsIdRotate", "/v1/credentials/{id}/rotate", Session).secret();
AUTH_CHALLENGE = Op::post("postAuthChallenge", "/v1/auth/challenge", Public);
AUTH_VERIFY = Op::post("postAuthVerify", "/v1/auth/verify", Public).secret();
REVOKE_SESSION = Op::delete("deleteV1AuthSessionsId", "/v1/auth/sessions/{id}", Session);
LINK = Op::post("postLink", "/v1/accounts/link", Session).retried();
SETUP_STEP = Op::post("postVenueSetupStep", "/v1/accounts/{venue}/setup/{step}", Session);
PREPARE_WALLET_PERMIT = Op::post("postWalletPermit", "/v1/wallets/{venue}/permit", Session);
SUBMIT_WALLET_PERMIT = PREPARE_WALLET_PERMIT.retried();
PREPARE_MAKER = Op::post("prepareMaker", "/v1/maker/{venue}/prepare", Session).retried();
SUBMIT_MAKER_SIGNATURES =
Op::post("submitMakerSignatures", "/v1/maker/preparations/{id}/signatures", Session)
.retried();
GET_MAKER_PREPARATION =
Op::get("getMakerPreparation", "/v1/maker/preparations/{id}", Session);
CANCEL_MAKER_PREPARATION =
Op::delete("cancelMakerPreparation", "/v1/maker/preparations/{id}", Session);
PREPARE_CLOSE = Op::post("postCloses", "/v1/closes", Session);
SUBMIT_CLOSE = Op::post("postCloseSignatures", "/v1/closes/{id}/signatures", Session).retried();
GET_QUOTE_LINES = Op::get("getQuoteLines", "/v1/quote-lines", Either);
PREPARE_QUOTE_LINES = Op::post("prepareQuoteLines", "/v1/quote-lines/prepare", Either);
PUBLISH_QUOTE_LINES = Op::post("publishQuoteLines", "/v1/quote-lines", Either).retried();
RENEW_LEASE =
Op::put("putV1QuoteIdentitiesIdLease", "/v1/quote-identities/{id}/lease", Either)
.retried();
CANCEL_IDENTITY_QUOTES = Op::delete(
"deleteV1QuoteIdentitiesIdQuotes",
"/v1/quote-identities/{id}/quotes",
Either,
);
POST_TAKE = Op::post("postTake", "/v1/takes", Session).retried().secret();
SUBMIT_TAKE_SIGNATURES =
Op::post("postTakeSignatures", "/v1/takes/{id}/signatures", Session).retried().secret();
REISSUE_ASTER_REQUEST =
Op::post("reissueAsterRequest", "/v1/takes/{id}/aster-request", Session)
.retried()
.secret();
PREPARE_WITHDRAWAL = Op::post("postWithdrawalPrepare", "/v1/withdrawals/prepare", Session);
SUBMIT_WITHDRAWAL = Op::post("postWithdrawal", "/v1/withdrawals", Session).retried();
QUOTE_MOVE = Op::get("quoteMove", "/v1/moves/quote", Session);
CREATE_MOVE = Op::post("createMove", "/v1/moves", Session).retried();
GET_MOVE = Op::get("getMove", "/v1/moves/{id}", Session);
CLOSE_MOVE = Op::post("closeMove", "/v1/moves/{id}/close", Session).retried();
CREATE_BRIDGE = Op::post("createBridge", "/v1/moves/{id}/bridges", Session).retried();
GET_BRIDGE = Op::get("getBridge", "/v1/bridges/{id}", Session);
GET_BRIDGE_FUNDING = Op::get("getBridgeFunding", "/v1/bridges/{id}/funding", Session);
SIGN_BRIDGE = Op::post("signBridge", "/v1/bridges/{id}/signatures", Session).retried();
FENCE_BRIDGE =
Op::post("reportBridgeTransaction", "/v1/bridges/{id}/transactions", Session);
REPORT_BRIDGE_TRANSACTION = FENCE_BRIDGE.retried();
CREATE_DIRECT = Op::post("createDirectOperation", "/v1/direct", Session).retried();
GET_DIRECT = Op::get("getDirectOperation", "/v1/direct/{id}", Session);
GET_DIRECT_FUNDING = Op::get("getDirectFunding", "/v1/direct/{id}/funding", Session);
FENCE_DIRECT = Op::post("reportDirectOperation", "/v1/direct/{id}", Session);
REPORT_DIRECT = FENCE_DIRECT.retried();
}
#[cfg(test)]
pub(crate) const DEFERRED: &[(&str, &str)] = &[
("postEscrowWithdrawPrepare", "escrow available-balance withdrawal: web-only today"),
("postEscrowWithdraw", "escrow available-balance withdrawal: web-only today"),
("postLinkChallenge", "linking another owner: one key per session in 0.1"),
];
#[cfg(test)]
pub(crate) const NEVER: &[(&str, &str)] = &[
("postAsterSigningRpc", "browser-wallet signing stub"),
("getSiteShareImage", "link preview"),
("getTradeShareMetadata", "link preview"),
];
#[cfg(test)]
mod conformance;