Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Apr 3, 2024
1 parent 2a1b7bc commit d779208
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 78 deletions.
50 changes: 1 addition & 49 deletions libs/types/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@ use core::marker::PhantomData;

use cfg_primitives::{
types::{PoolId, TrancheId},
Balance, PalletIndex,
Balance,
};
use cfg_traits::{investments::TrancheCurrency as TrancheCurrencyT, HasLocalAssetRepresentation};
use orml_traits::asset_registry;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
use sp_runtime::{traits::Get, DispatchError, TokenError};
use staging_xcm::{
prelude::{AccountKey20, GlobalConsensus, PalletInstance},
v3::{MultiLocation, NetworkId},
VersionedMultiLocation,
};

use crate::{domain_address::DomainAddress, xcm::XcmMetadata, EVMChainId};

Expand Down Expand Up @@ -493,8 +488,6 @@ pub mod before {
}

pub mod usdc {
use sp_std::vec::Vec;

use super::*;

pub const MIN_SWAP_ORDER_AMOUNT: Balance = 10_000_000;
Expand Down Expand Up @@ -530,47 +523,6 @@ pub mod usdc {
hex_literal::hex!("af88d065e77c8cC2239327C5EDb3A432268e5831");
pub const CONTRACT_CELO: [u8; 20] =
hex_literal::hex!("37f750B7cC259A2f741AF45294f6a16572CF5cAd");

/// The metadata generator for the LP wrapped USDC currencies
// TODO(future): If no further LP wrapped USDC variants are expected, move this
// to `chain_spec.rs`.
pub fn lp_wrapped_usdc_metadata(
name: Vec<u8>,
symbol: Vec<u8>,
pallet_index: PalletIndex,
chain_id: EVMChainId,
contract_address_usdc: [u8; 20],
pool_currency: bool,
) -> Result<AssetMetadata, DispatchError> {
Ok(AssetMetadata {
decimals: DECIMALS,
name: name
.try_into()
.map_err(|_| DispatchError::Other("asset name exceeds limit"))?,
symbol: symbol
.try_into()
.map_err(|_| DispatchError::Other("asset symbol exceeds limit"))?,
existential_deposit: EXISTENTIAL_DEPOSIT,
location: Some(VersionedMultiLocation::V3(MultiLocation {
parents: 0,
interior: staging_xcm::v3::Junctions::X3(
PalletInstance(pallet_index),
GlobalConsensus(NetworkId::Ethereum { chain_id }),
AccountKey20 {
network: None,
key: contract_address_usdc,
},
),
})),
additional: CustomMetadata {
transferability: CrossChainTransferability::LiquidityPools,
mintable: false,
permissioned: false,
pool_currency,
local_representation: Some(LOCAL_ASSET_ID),
},
})
}
}

#[cfg(test)]
Expand Down
52 changes: 33 additions & 19 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ use cfg_primitives::{
};
use cfg_types::{
fee_keys::FeeKey,
tokens::{
usdc::{
lp_wrapped_usdc_metadata, CHAIN_ID_ETH_GOERLI_TESTNET, CONTRACT_ETH_GOERLI,
CURRENCY_ID_LOCAL, CURRENCY_ID_LP_ETH_GOERLI,
},
AssetMetadata, CrossChainTransferability, CurrencyId, CustomMetadata,
},
tokens::{usdc, AssetMetadata, CrossChainTransferability, CurrencyId, CustomMetadata},
};
use cfg_utils::vec_to_fixed_array;
use cumulus_primitives_core::ParaId;
Expand All @@ -52,8 +46,10 @@ use sp_runtime::{
FixedPointNumber,
};
use staging_xcm::{
latest::MultiLocation,
prelude::{GeneralIndex, GeneralKey, PalletInstance, Parachain, X2, X3},
latest::{MultiLocation, NetworkId},
prelude::{
AccountKey20, GeneralIndex, GeneralKey, GlobalConsensus, PalletInstance, Parachain, X2, X3,
},
};

/// Specialized `ChainSpec` instances for our runtimes.
Expand Down Expand Up @@ -1053,7 +1049,7 @@ fn asset_registry_assets() -> Vec<(CurrencyId, Vec<u8>)> {
.encode(),
),
(
CURRENCY_ID_LOCAL,
usdc::CURRENCY_ID_LOCAL,
AssetMetadata {
decimals: 6,
name: b"Local USDC"
Expand All @@ -1077,21 +1073,39 @@ fn asset_registry_assets() -> Vec<(CurrencyId, Vec<u8>)> {
.encode(),
),
(
CURRENCY_ID_LP_ETH_GOERLI,
lp_wrapped_usdc_metadata(
b"LP Ethereum Wrapped USDC"
usdc::CURRENCY_ID_LP_ETH_GOERLI,
AssetMetadata {
decimals: usdc::DECIMALS,
name: b"LP Ethereum Wrapped USDC"
.to_vec()
.try_into()
.expect("fit in the BoundedVec"),
b"LpEthUSDC"
symbol: b"LpEthUSDC"
.to_vec()
.try_into()
.expect("fit in the BoundedVec"),
development_runtime::LiquidityPoolsPalletIndex::get(),
CHAIN_ID_ETH_GOERLI_TESTNET,
CONTRACT_ETH_GOERLI,
true,
)
existential_deposit: usdc::EXISTENTIAL_DEPOSIT,
location: Some(staging_xcm::VersionedMultiLocation::V3(MultiLocation {
parents: 0,
interior: staging_xcm::v3::Junctions::X3(
PalletInstance(development_runtime::LiquidityPoolsPalletIndex::get()),
GlobalConsensus(NetworkId::Ethereum {
chain_id: usdc::CHAIN_ID_ETH_GOERLI_TESTNET,
}),
AccountKey20 {
network: None,
key: usdc::CONTRACT_ETH_GOERLI,
},
),
})),
additional: CustomMetadata {
transferability: CrossChainTransferability::LiquidityPools,
mintable: false,
permissioned: false,
pool_currency: true,
local_representation: Some(usdc::LOCAL_ASSET_ID),
},
}
.encode(),
),
]
Expand Down
2 changes: 1 addition & 1 deletion pallets/oracle-collection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ pub mod util {

/// Computes fastly the median of a list of values
/// Extracted from orml
pub fn median<T: Ord>(items: &mut Vec<T>) -> Option<&T> {
pub fn median<T: Ord>(items: &mut [T]) -> Option<&T> {
if items.is_empty() {
return None;
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/pool-system/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl<T: Config> PoolMutate<T::AccountId, T::PoolId> for Pallet<T> {
tranche_type: t.tranche_type,
seniority: t.seniority,
})
.collect(),
.collect::<Vec<_>>(),
)?;

Self::take_deposit(depositor.clone(), pool_id)?;
Expand Down
2 changes: 1 addition & 1 deletion pallets/pool-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ pub mod pallet {

pub fn is_valid_tranche_change(
old_tranches: Option<&TranchesOf<T>>,
new_tranches: &Vec<TrancheUpdate<T::Rate>>,
new_tranches: &[TrancheUpdate<T::Rate>],
) -> DispatchResult {
// There is a limit to the number of allowed tranches
ensure!(
Expand Down
12 changes: 5 additions & 7 deletions pallets/pool-system/src/pool_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,16 @@ impl<
let mut tranches: Vec<TrancheEssence<TrancheCurrency, Rate, StringLimit>> = Vec::new();

for tranche in self.tranches.residual_top_slice().iter() {
let metadata = AssetRegistry::metadata(&self.currency.into()).ok_or(
DispatchError::Other("Always exists a currency for an existing pool"),
)?;
let metadata = AssetRegistry::metadata(&self.currency).ok_or(DispatchError::Other(
"Always exists a currency for an existing pool",
))?;

tranches.push(TrancheEssence {
currency: tranche.currency,
ty: tranche.tranche_type,
metadata: TrancheMetadata {
token_name: BoundedVec::try_from(metadata.name)
.unwrap_or(BoundedVec::default()),
token_symbol: BoundedVec::try_from(metadata.symbol)
.unwrap_or(BoundedVec::default()),
token_name: metadata.name,
token_symbol: metadata.symbol,
},
});
}
Expand Down
3 changes: 3 additions & 0 deletions runtime/common/src/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ impl<O: OriginTrait<AccountId = AccountId>> Feeder<O> {
}
}

// There is an issue with clippy that detect this as an error:
// https://github.com/rust-lang/rust-clippy/issues/12245
#[allow(clippy::unconditional_recursion)]
impl<O: OriginTrait> PartialEq for Feeder<O> {
fn eq(&self, other: &Self) -> bool {
self.0.eq(&other.0)
Expand Down

0 comments on commit d779208

Please sign in to comment.