Skip to main content

df_papertrade_core/trade/writes/
cancel.rs

1//! Cancelling a queued intent before the relayer sends it, signed by the session key.
2
3use df_hyperliquid_core::client::Http;
4use df_hyperliquid_core::utils::Address;
5
6use crate::account::Account;
7use crate::account::store::Store;
8use crate::client::{Accepted, Client, Error};
9use crate::trade::{CancelIntent, Intent, deadline};
10
11impl<H: Http + Clone> Client<H> {
12    /// Cancels a queued intent (`intent_id`) before the relayer sends it. The relayer's answer is
13    /// returned as is, without checking that it kept the cancel.
14    pub async fn cancel(
15        &self,
16        store: &impl Store,
17        owner: Address,
18        account: Option<&Account>,
19        intent_id: [u8; 32],
20    ) -> Result<Accepted, Error> {
21        let key = self.session_key(store, owner, account).await?;
22        let cancel = CancelIntent { user: owner, intent_id, deadline: deadline(self.now_ms()) };
23        let signed =
24            key.sign(Intent::CancelIntent(cancel), self.now_ms()).map_err(|e| Error::Signature(e.to_string()))?;
25        Ok(self.relayer().submit(&signed).await?)
26    }
27}