use alloy_primitives::{Address, U256};
use alloy_sol_types::sol;
use serde::{Deserialize, Serialize};
use alloy_primitives::hex;
use crate::types::{Side, SignatureType};
#[derive(Debug, Clone)]
pub struct OrderData {
pub maker: Address,
pub taker: Address,
pub token_id: U256,
pub maker_amount: U256,
pub taker_amount: U256,
pub side: Side,
pub fee_rate_bps: U256,
pub nonce: U256,
pub signer: Option<Address>,
pub expiration: Option<U256>,
pub signature_type: Option<SignatureType>,
}
sol! {
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
struct Order {
uint256 salt;
address maker;
address signer;
address taker;
uint256 tokenId;
uint256 makerAmount;
uint256 takerAmount;
uint256 expiration;
uint256 nonce;
uint256 feeRateBps;
uint8 side;
uint8 signatureType;
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SignedOrder {
pub order: Order,
pub signature: String,
}
impl SignedOrder {
pub fn new(order: Order, signature: Vec<u8>) -> Self {
Self {
order,
signature: format!("0x{}", hex::encode(signature)),
}
}
}