1use alloy::primitives::{Address, U256};
4use thiserror::Error;
5
6#[derive(Debug, Error)]
8pub enum SdkError {
9 #[error(
11 "transferWithCommitmentAddress is not configured (zero address). Set ETH_TWC_CONTRACT_ADDRESS for integration-test, or use default release build with CREATE2 address baked in config."
12 )]
13 ContractNotConfigured,
14
15 #[error(
17 "TransferWithCommitment is not deployed at {address} on chain id {chain_id} (no contract code). Deploy via CREATE2 (see contracts/TWC_CREATE2.md)."
18 )]
19 ContractNotDeployed { address: Address, chain_id: u64 },
20
21 #[error(
23 "Signed data domain.chain_id ({domain}) does not match client chain id ({client})"
24 )]
25 DomainChainIdMismatch { domain: String, client: u64 },
26
27 #[error(
29 "Signed data domain.verifyingContract ({domain}) does not match transferWithCommitmentAddress ({configured})"
30 )]
31 DomainVerifyingContractMismatch {
32 domain: Address,
33 configured: Address,
34 },
35
36 #[error(
38 "validAfter ({valid_after}) must be <= validBefore ({valid_before})"
39 )]
40 InvalidValidTimeWindow {
41 valid_after: U256,
42 valid_before: U256,
43 },
44
45 #[error("transfer details must not be empty")]
47 EmptyTransferDetails,
48
49 #[error(
51 "EIP-712 message `from` ({from}) does not match signer address ({signer})"
52 )]
53 FromSignerMismatch { from: Address, signer: Address },
54
55 #[error(
57 "CancelAuthorization `authorizer` ({authorizer}) does not match signer address ({signer})"
58 )]
59 AuthorizerSignerMismatch { authorizer: Address, signer: Address },
60
61 #[error("TransferWithCommitmentSent event not found")]
63 EventNotFound,
64
65 #[error("Transaction receipt not found for the given hash")]
67 ReceiptNotFound,
68
69 #[error("RPC / contract error: {0}")]
71 Alloy(String),
72
73 #[error("Signing error: {0}")]
75 Signer(#[from] alloy::signers::Error),
76}
77
78impl From<alloy::contract::Error> for SdkError {
79 fn from(e: alloy::contract::Error) -> Self {
80 SdkError::Alloy(e.to_string())
81 }
82}
83
84impl From<alloy::transports::TransportError> for SdkError {
85 fn from(e: alloy::transports::TransportError) -> Self {
86 SdkError::Alloy(e.to_string())
87 }
88}