diff --git a/pallets/pool-system/src/lib.rs b/pallets/pool-system/src/lib.rs index dca34da1cd..17fe6ff76b 100644 --- a/pallets/pool-system/src/lib.rs +++ b/pallets/pool-system/src/lib.rs @@ -521,7 +521,7 @@ pub mod pallet { /// Pre-requirements for a TrancheUpdate are not met /// for example: Tranche changed but not its metadata or vice versa InvalidTrancheUpdate, - /// No metada for the given currency found + /// No metadata for the given currency found MetadataForCurrencyNotFound, /// The given tranche token name exceeds the length limit TrancheTokenNameTooLong, diff --git a/pallets/pool-system/src/pool_types.rs b/pallets/pool-system/src/pool_types.rs index f5b800461d..99453d6344 100644 --- a/pallets/pool-system/src/pool_types.rs +++ b/pallets/pool-system/src/pool_types.rs @@ -119,6 +119,7 @@ pub struct PoolDetails< Rate: FixedPointNumber, Balance: FixedPointOperand + sp_arithmetic::MultiplyRational, MaxTranches: Get, + TrancheCurrency: Into, { /// Currency that the pool is denominated in (immutable). pub currency: CurrencyId, @@ -197,6 +198,7 @@ pub struct PoolEssence where CurrencyId: Copy, StringLimit: Get, + TrancheCurrency: Into, { /// Currency that the pool is denominated in (immutable). pub currency: CurrencyId, @@ -235,6 +237,7 @@ impl< Balance: FixedPointOperand + BaseArithmetic + Unsigned + From + sp_arithmetic::MultiplyRational, CurrencyId: Copy, + TrancheCurrency: Into, EpochId: BaseArithmetic + Copy, PoolId: Copy + Encode, Rate: FixedPointNumber, @@ -273,9 +276,12 @@ impl< let mut tranches: Vec> = Vec::new(); for tranche in self.tranches.residual_top_slice().iter() { - let metadata = AssetRegistry::metadata(&self.currency).ok_or(DispatchError::Other( - "Always exists a currency for an existing pool", - ))?; + let metadata = AssetRegistry::metadata( + &::AssetId::from( + tranche.currency.into(), + ), + ) + .ok_or(DispatchError::CannotLookup)?; tranches.push(TrancheEssence { currency: tranche.currency, diff --git a/pallets/pool-system/src/tests/mod.rs b/pallets/pool-system/src/tests/mod.rs index 2b4e5daeca..b9bcb2d916 100644 --- a/pallets/pool-system/src/tests/mod.rs +++ b/pallets/pool-system/src/tests/mod.rs @@ -2436,6 +2436,68 @@ fn create_tranche_token_metadata() { }); } +#[test] +fn essence() { + new_test_ext().execute_with(|| { + let pool_owner = 1_u64; + let tranche_input = vec![ + TrancheInput { + tranche_type: TrancheType::Residual, + seniority: None, + metadata: TrancheMetadata { + token_name: BoundedVec::try_from("ResName".as_bytes().to_owned()) + .expect("String not out of bounds"), + token_symbol: BoundedVec::try_from("ResSym".as_bytes().to_owned()) + .expect("String not out of bounds"), + }, + }, + TrancheInput { + tranche_type: TrancheType::NonResidual { + interest_rate_per_sec: Rate::one(), + min_risk_buffer: Perquintill::from_percent(10), + }, + seniority: None, + metadata: TrancheMetadata { + token_name: BoundedVec::try_from("NonResName".as_bytes().to_owned()) + .expect("String not out of bounds"), + token_symbol: BoundedVec::try_from("NRSym".as_bytes().to_owned()) + .expect("String not out of bounds"), + }, + }, + ]; + + assert_ok!(PoolSystem::create( + pool_owner.clone(), + pool_owner.clone(), + DEFAULT_POOL_ID, + tranche_input.clone(), + AUSD_CURRENCY_ID, + 10_000 * CURRENCY, + vec![], + )); + + let pool_details = Pool::::get(DEFAULT_POOL_ID).expect("Pool is registered; qed"); + let essence = pool_details + .essence::<::AssetRegistry, Balance, StringLimit>() + .expect("Tranche token metadata is registered; qed"); + + assert_eq!(essence.currency, AUSD_CURRENCY_ID); + assert_eq!(essence.max_reserve, 10_000 * CURRENCY); + assert_eq!(essence.max_nav_age, pool_details.parameters.max_nav_age); + assert_eq!( + essence.min_epoch_time, + pool_details.parameters.min_epoch_time + ); + + tranche_input.iter().zip(essence.tranches.iter()).for_each( + |(tranche_input, tranche_essence)| { + assert_eq!(tranche_input.metadata, tranche_essence.metadata); + assert_eq!(tranche_input.tranche_type, tranche_essence.ty); + }, + ); + }) +} + mod changes { use cfg_traits::changes::ChangeGuard; use sp_std::collections::btree_set::BTreeSet;