Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pallets/pallet-bonded-coins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ pub mod pallet {

let pool_account = &pool_id.clone().into();

// Touch the pool account in order to be able to transfer the collateral
// currency to it. This should also verify that the currency actually exists.
T::CollateralCurrencies::touch(collateral_id.clone(), pool_account, &who)?;

currencies
.into_iter()
.zip(currency_ids.iter())
Expand All @@ -313,10 +317,6 @@ pub mod pallet {
Ok(())
})?;

// Touch the pool account in order to be able to transfer the collateral
// currency to it. This should also verify that the currency actually exists.
T::CollateralCurrencies::touch(collateral_id.clone(), pool_account, &who)?;

Pools::<T>::set(
&pool_id,
Some(PoolDetails::new(
Expand Down Expand Up @@ -961,13 +961,13 @@ pub mod pallet {
Ok((currency_array, start_id))
}

fn get_currencies_number(pool_details: &PoolDetailsOf<T>) -> u32 {
pub(crate) fn get_currencies_number(pool_details: &PoolDetailsOf<T>) -> u32 {
// bonded_currencies is a BoundedVec with maximum length MaxCurrencies, which is
// a u32; conversion to u32 must thus be lossless.
pool_details.bonded_currencies.len().saturated_into()
}

fn calculate_pool_deposit<N: UniqueSaturatedInto<DepositCurrencyBalanceOf<T>>>(
pub(crate) fn calculate_pool_deposit<N: UniqueSaturatedInto<DepositCurrencyBalanceOf<T>>>(
n_currencies: N,
) -> DepositCurrencyBalanceOf<T> {
T::BaseDeposit::get()
Expand Down
38 changes: 23 additions & 15 deletions pallets/pallet-bonded-coins/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ pub(crate) const ACCOUNT_00: AccountId = AccountId::new([0u8; 32]);
pub(crate) const ACCOUNT_01: AccountId = AccountId::new([1u8; 32]);
const ACCOUNT_99: AccountId = AccountId::new([99u8; 32]);
// assets
pub(crate) const DEFAULT_BONDED_CURRENCY_ID: AssetId = 0;
pub(crate) const DEFAULT_COLLATERAL_CURRENCY_ID: AssetId = AssetId::MAX;
pub(crate) const DEFAULT_BONDED_CURRENCY_ID: AssetId = 1;
pub(crate) const DEFAULT_COLLATERAL_CURRENCY_ID: AssetId = 0;
pub(crate) const DEFAULT_COLLATERAL_DENOMINATION: u8 = 10;
pub(crate) const DEFAULT_BONDED_DENOMINATION: u8 = 10;
pub(crate) const ONE_HUNDRED_KILT: u128 = 100_000_000_000_000_000;

// helper functions
pub fn assert_relative_eq(target: Float, expected: Float, epsilon: Float) {
Expand Down Expand Up @@ -98,7 +99,7 @@ pub mod runtime {
bonded_currencies,
state,
collateral_id,
denomination: 10,
denomination: DEFAULT_BONDED_DENOMINATION,
owner,
}
}
Expand Down Expand Up @@ -276,19 +277,24 @@ pub mod runtime {

let collateral_assets = self.collaterals.into_iter().map(|id| (id, ACCOUNT_99, false, 1));

pallet_assets::GenesisConfig::<Test> {
assets: self
.pools
.iter()
.flat_map(|(owner, pool)| {
pool.bonded_currencies
.iter()
.map(|id| (*id, owner.to_owned(), false, 1u128))
.collect::<Vec<(AssetId, AccountId, bool, Balance)>>()
})
.chain(collateral_assets)
.collect(),
let all_assets: Vec<_> = self
.pools
.iter()
.flat_map(|(owner, pool)| {
pool.bonded_currencies
.iter()
.map(|id| (*id, owner.to_owned(), false, 1u128))
.collect::<Vec<(AssetId, AccountId, bool, Balance)>>()
})
.chain(collateral_assets)
.collect();

// NextAssetId is set to the maximum value of all collateral/bonded currency ids, plus one.
// If no currencies are created, it's set to 0.
let next_asset_id = all_assets.iter().map(|(id, ..)| id).max().map_or(0, |id| id + 1);

pallet_assets::GenesisConfig::<Test> {
assets: all_assets,
accounts: self.bonded_balance,
metadata: self
.pools
Expand All @@ -313,6 +319,8 @@ pub mod runtime {
self.pools.into_iter().for_each(|(pool_id, pool)| {
crate::Pools::<Test>::insert(pool_id, pool);
});

crate::NextAssetId::<Test>::set(next_asset_id);
});

ext
Expand Down
1 change: 1 addition & 0 deletions pallets/pallet-bonded-coins/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mod curves;
mod transactions;
Loading