diff --git a/crates/bitcoin/src/address.rs b/crates/bitcoin/src/address.rs index 28809257cd..43edece67d 100644 --- a/crates/bitcoin/src/address.rs +++ b/crates/bitcoin/src/address.rs @@ -3,6 +3,7 @@ use bitcoin_hashes::{hash160::Hash as Hash160, Hash}; use codec::{Decode, Encode, MaxEncodedLen}; use primitive_types::{H160, H256}; use scale_info::TypeInfo; +use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; #[cfg(not(feature = "std"))] @@ -13,8 +14,10 @@ use secp256k1::{constants::PUBLIC_KEY_SIZE, Error as Secp256k1Error, PublicKey a /// A Bitcoin address is a serialized identifier that represents the destination for a payment. /// Address prefixes are used to indicate the network as well as the format. Since the Parachain /// follows SPV assumptions we do not need to know which network a payment is included in. -#[derive(Encode, Decode, Clone, Ord, PartialOrd, PartialEq, Eq, Debug, Copy, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize, std::hash::Hash))] +#[derive( + Serialize, Deserialize, Encode, Decode, Clone, Ord, PartialOrd, PartialEq, Eq, Debug, Copy, TypeInfo, MaxEncodedLen, +)] +#[cfg_attr(feature = "std", derive(std::hash::Hash))] pub enum Address { // input: {signature} {pubkey} // output: OP_DUP OP_HASH160 {hash160(pubkey)} OP_EQUALVERIFY OP_CHECKSIG @@ -150,7 +153,6 @@ impl From<[u8; PUBLIC_KEY_SIZE]> for PublicKey { } } -#[cfg(feature = "std")] impl serde::Serialize for PublicKey { fn serialize(&self, serializer: S) -> Result where @@ -161,7 +163,6 @@ impl serde::Serialize for PublicKey { } } -#[cfg(feature = "std")] impl<'de> serde::Deserialize<'de> for PublicKey { fn deserialize(deserializer: D) -> Result where diff --git a/crates/bitcoin/src/types.rs b/crates/bitcoin/src/types.rs index f1a38b3318..1fa46b57e6 100644 --- a/crates/bitcoin/src/types.rs +++ b/crates/bitcoin/src/types.rs @@ -19,7 +19,6 @@ use alloc::{vec, vec::Vec}; #[cfg(feature = "std")] use codec::alloc::string::String; -#[cfg(feature = "std")] use serde::{Deserialize, Serialize}; /// We also check the coinbase proof in order to defend against the 'leaf-node weakness'. @@ -591,8 +590,9 @@ pub struct BlockChain { } /// Represents a bitcoin 32 bytes hash digest encoded in little-endian -#[derive(Encode, Decode, Default, PartialEq, Eq, Clone, Copy, Debug, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +#[derive( + Serialize, Deserialize, Encode, Decode, Default, PartialEq, Eq, Clone, Copy, Debug, TypeInfo, MaxEncodedLen, +)] pub struct H256Le { content: [u8; 32], } diff --git a/crates/loans/Cargo.toml b/crates/loans/Cargo.toml index c551a20997..9852952375 100644 --- a/crates/loans/Cargo.toml +++ b/crates/loans/Cargo.toml @@ -8,7 +8,7 @@ version = "1.9.3" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -serde = { version = "1.0.136", default-features = false, features = ["derive"] , optional = true } +serde = { version = "1.0.136", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } scale-info = { version = "2.2.0", default-features = false, features = ["derive"] } num-traits = { default-features = false, version = "0.2" } diff --git a/crates/loans/src/rate_model.rs b/crates/loans/src/rate_model.rs index fb625c6f18..0e95e3cd6a 100644 --- a/crates/loans/src/rate_model.rs +++ b/crates/loans/src/rate_model.rs @@ -23,8 +23,19 @@ use sp_runtime::traits::{CheckedAdd, CheckedDiv, CheckedSub, Saturating}; use crate::*; /// Parallel interest rate model -#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive( + serde::Deserialize, + serde::Serialize, + Encode, + Decode, + Eq, + PartialEq, + Copy, + Clone, + RuntimeDebug, + TypeInfo, + MaxEncodedLen, +)] pub enum InterestRateModel { Jump(JumpModel), Curve(CurveModel), @@ -76,8 +87,19 @@ impl InterestRateModel { } /// The jump interest rate model -#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive( + serde::Deserialize, + serde::Serialize, + Encode, + Decode, + Eq, + PartialEq, + Copy, + Clone, + RuntimeDebug, + TypeInfo, + MaxEncodedLen, +)] pub struct JumpModel { /// The base interest rate when utilization rate is 0 pub base_rate: Rate, @@ -147,8 +169,19 @@ impl JumpModel { } /// The curve interest rate model -#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive( + serde::Deserialize, + serde::Serialize, + Encode, + Decode, + Eq, + PartialEq, + Copy, + Clone, + RuntimeDebug, + TypeInfo, + MaxEncodedLen, +)] pub struct CurveModel { pub base_rate: Rate, } diff --git a/crates/loans/src/types.rs b/crates/loans/src/types.rs index 0c4f887e17..afc4b870ff 100644 --- a/crates/loans/src/types.rs +++ b/crates/loans/src/types.rs @@ -76,8 +76,19 @@ pub struct EarnedSnapshot { } /// The current state of a market. For more information, see [Market]. -#[derive(Clone, Copy, PartialEq, Eq, codec::Decode, codec::Encode, RuntimeDebug, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive( + serde::Deserialize, + serde::Serialize, + Encode, + Decode, + Eq, + PartialEq, + Copy, + Clone, + RuntimeDebug, + TypeInfo, + MaxEncodedLen, +)] pub enum MarketState { Active, Pending, @@ -89,8 +100,19 @@ pub enum MarketState { /// Market. /// /// A large pool of liquidity where accounts can lend and borrow. -#[derive(Clone, PartialEq, Eq, codec::Decode, codec::Encode, RuntimeDebug, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[derive( + serde::Deserialize, + serde::Serialize, + Encode, + Decode, + Eq, + PartialEq, + Copy, + Clone, + RuntimeDebug, + TypeInfo, + MaxEncodedLen, +)] pub struct Market { /// The secure collateral ratio pub collateral_factor: Ratio, diff --git a/crates/vault-registry/Cargo.toml b/crates/vault-registry/Cargo.toml index 8cc4cc4333..c40a558ccf 100644 --- a/crates/vault-registry/Cargo.toml +++ b/crates/vault-registry/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Interlay Ltd"] edition = "2021" [dependencies] -serde = { version = "1.0.130", default-features = false, features = ["derive"] , optional = true } +serde = { version = "1.0.130", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive", "max-encoded-len"] } scale-info = { version = "2.2.0", default-features = false, features = ["derive"] } @@ -80,7 +80,6 @@ std = [ "loans/std", ] runtime-benchmarks = [ -# "primitives", "frame-benchmarking", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", diff --git a/crates/vault-registry/src/types.rs b/crates/vault-registry/src/types.rs index 9f161923b3..d96a7760f3 100644 --- a/crates/vault-registry/src/types.rs +++ b/crates/vault-registry/src/types.rs @@ -171,8 +171,8 @@ pub struct Vault { // Number of tokens pending issue pub to_be_issued_tokens: Balance, diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 293e2e10ad..73e9fa2a4e 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -17,7 +17,6 @@ use scale_decode::DecodeAsType; #[cfg(feature = "std")] use scale_encode::EncodeAsType; use scale_info::TypeInfo; -#[cfg(feature = "std")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; pub use bitcoin::types::H256Le; @@ -77,15 +76,19 @@ mod arithmetic { } } -#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize, std::hash::Hash))] +#[derive( + Serialize, Deserialize, Encode, Decode, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, TypeInfo, MaxEncodedLen, +)] +#[cfg_attr(feature = "std", derive(std::hash::Hash))] pub struct VaultCurrencyPair { pub collateral: CurrencyId, pub wrapped: CurrencyId, } -#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize, std::hash::Hash))] +#[derive( + Serialize, Deserialize, Encode, Decode, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, TypeInfo, MaxEncodedLen, +)] +#[cfg_attr(feature = "std", derive(std::hash::Hash))] pub struct VaultId { pub account_id: AccountId, pub currencies: VaultCurrencyPair, @@ -124,9 +127,9 @@ impl From<(AccountId, VaultCurrencyPair pub mod issue { use super::*; - #[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)] - #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] - #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] + #[derive(Serialize, Deserialize, Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)] + #[cfg_attr(feature = "std", derive(Debug))] + #[serde(rename_all = "camelCase")] pub enum IssueRequestStatus { /// opened, but not yet executed or cancelled Pending, @@ -144,8 +147,8 @@ pub mod issue { // Due to a known bug in serde we need to specify how u128 is (de)serialized. // See https://github.com/paritytech/substrate/issues/4641 - #[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)] - #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] + #[derive(Serialize, Deserialize, Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)] + #[cfg_attr(feature = "std", derive(Debug))] pub struct IssueRequest { /// the vault associated with this issue request pub vault: VaultId, @@ -186,9 +189,8 @@ pub mod issue { } } -#[derive(Eq, PartialEq, Encode, Decode, Default, TypeInfo)] -#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] -#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] +#[derive(Serialize, Deserialize, Eq, PartialEq, Encode, Decode, Default, TypeInfo)] +#[serde(rename_all = "camelCase")] /// a wrapper around a balance, used in RPC to workaround a bug where using u128 /// in runtime-apis fails. See pub struct BalanceWrapper { @@ -214,9 +216,9 @@ fn deserialize_from_string<'de, D: Deserializer<'de>, T: std::str::FromStr>(dese pub mod redeem { use super::*; - #[derive(Encode, Decode, Clone, Eq, PartialEq, TypeInfo, MaxEncodedLen)] - #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] - #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] + #[derive(Serialize, Deserialize, Encode, Decode, Clone, Eq, PartialEq, TypeInfo, MaxEncodedLen)] + #[cfg_attr(feature = "std", derive(Debug))] + #[serde(rename_all = "camelCase")] pub enum RedeemRequestStatus { /// opened, but not yet executed or cancelled Pending, @@ -236,8 +238,8 @@ pub mod redeem { // Due to a known bug in serde we need to specify how u128 is (de)serialized. // See https://github.com/paritytech/substrate/issues/4641 - #[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)] - #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] + #[derive(Serialize, Deserialize, Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)] + #[cfg_attr(feature = "std", derive(Debug))] pub struct RedeemRequest { /// the vault associated with this redeem request pub vault: VaultId, @@ -283,9 +285,9 @@ pub mod redeem { pub mod replace { use super::*; - #[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)] - #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize, Eq))] - #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] + #[derive(Serialize, Deserialize, Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)] + #[cfg_attr(feature = "std", derive(Debug, Eq))] + #[serde(rename_all = "camelCase")] pub enum ReplaceRequestStatus { /// accepted, but not yet executed or cancelled Pending, @@ -303,8 +305,8 @@ pub mod replace { // Due to a known bug in serde we need to specify how u128 is (de)serialized. // See https://github.com/paritytech/substrate/issues/4641 - #[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)] - #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize, Eq))] + #[derive(Serialize, Deserialize, Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)] + #[cfg_attr(feature = "std", derive(Eq, Debug))] pub struct ReplaceRequest { /// the vault which has requested to be replaced pub old_vault: VaultId, @@ -344,9 +346,8 @@ pub mod replace { pub mod oracle { use super::*; - #[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo, MaxEncodedLen)] - #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] - #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] + #[derive(Serialize, Deserialize, Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo, MaxEncodedLen)] + #[serde(rename_all = "camelCase")] pub enum Key { ExchangeRate(CurrencyId), FeeEstimation, @@ -503,8 +504,7 @@ macro_rules! create_currency_id { } create_currency_id! { - #[derive(Encode, Decode, Eq, Hash, PartialEq, Copy, Clone, Debug, PartialOrd, Ord, TypeInfo, MaxEncodedLen)] - #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] + #[derive(Serialize, Deserialize,Encode, Decode, Eq, Hash, PartialEq, Copy, Clone, Debug, PartialOrd, Ord, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(EncodeAsType,DecodeAsType))] #[repr(u8)] pub enum TokenSymbol { @@ -518,9 +518,23 @@ create_currency_id! { } } -#[derive(Encode, Decode, Eq, Hash, PartialEq, Copy, Clone, Debug, PartialOrd, Ord, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] +#[derive( + Serialize, + Deserialize, + Encode, + Decode, + Eq, + Hash, + PartialEq, + Copy, + Clone, + Debug, + PartialOrd, + Ord, + TypeInfo, + MaxEncodedLen, +)] +#[serde(rename_all = "camelCase")] #[cfg_attr(feature = "std", derive(EncodeAsType, DecodeAsType))] pub enum LpToken { Token(TokenSymbol), @@ -528,9 +542,23 @@ pub enum LpToken { StableLpToken(StablePoolId), } -#[derive(Encode, Decode, Eq, Hash, PartialEq, Copy, Clone, Debug, PartialOrd, Ord, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] +#[derive( + Serialize, + Deserialize, + Encode, + Decode, + Eq, + Hash, + PartialEq, + Copy, + Clone, + Debug, + PartialOrd, + Ord, + TypeInfo, + MaxEncodedLen, +)] +#[serde(rename_all = "camelCase")] #[cfg_attr(feature = "std", derive(EncodeAsType, DecodeAsType))] pub enum CurrencyId { Token(TokenSymbol),