#[cfg(feature = "std")] use zeroize::Zeroize; use serde::{Serialize, Deserialize}; use scale::{Encode, Decode, MaxEncodedLen}; use scale_info::TypeInfo; use serai_primitives::{Coin, Amount, SeraiAddress, ExternalAddress, Data}; use tokens_primitives::OutInstruction; use crate::RefundableInInstruction; #[cfg(feature = "std")] use crate::InInstruction; #[derive( Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo, )] #[cfg_attr(feature = "std", derive(Zeroize))] pub enum Shorthand { Raw(Data), Swap { origin: Option, coin: Coin, minimum: Amount, out: OutInstruction, }, AddLiquidity { origin: Option, minimum: Amount, gas: Amount, address: SeraiAddress, }, } impl Shorthand { #[cfg(feature = "std")] pub fn transfer(origin: Option, address: SeraiAddress) -> Option { Some(Self::Raw( Data::new( (RefundableInInstruction { origin, instruction: InInstruction::Transfer(address) }) .encode(), ) .ok()?, )) } } impl TryFrom for RefundableInInstruction { type Error = &'static str; fn try_from(shorthand: Shorthand) -> Result { Ok(match shorthand { Shorthand::Raw(raw) => { RefundableInInstruction::decode(&mut raw.data()).map_err(|_| "invalid raw instruction")? } Shorthand::Swap { .. } => todo!(), Shorthand::AddLiquidity { .. } => todo!(), }) } }