Skip to content

Commit

Permalink
fix: rm locked, add reserved
Browse files Browse the repository at this point in the history
  • Loading branch information
wischli committed Nov 17, 2023
1 parent 0e05be5 commit 762ddb8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
9 changes: 5 additions & 4 deletions libs/types/src/investments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ pub struct InvestmentPortfolio<Balance> {
pub claimable_tranche_tokens: Balance,
/// The amount of tranche tokens which can be transferred
pub free_tranche_tokens: Balance,
/// The amount of tranche tokens which cannot be transferred
pub locked_tranche_tokens: Balance,
/// The amount of tranche tokens which can not be used at all and get
/// slashed
pub reserved_tranche_tokens: Balance,
/// The unprocessed redeem order amount in tranche tokens
pub pending_redeem_tranche_tokens: Balance,
/// The amount of pool currency which can be collected for a redeem order
Expand All @@ -274,8 +275,8 @@ impl<Balance: Default> InvestmentPortfolio<Balance> {
self
}

pub fn with_locked_tranche_tokens(mut self, amount: Balance) -> Self {
self.locked_tranche_tokens = amount;
pub fn with_reserved_tranche_tokens(mut self, amount: Balance) -> Self {
self.reserved_tranche_tokens = amount;
self
}

Expand Down
5 changes: 2 additions & 3 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ pub mod investment_portfolios {
/// require the pallet's Config trait.
pub fn get_account_portfolio<T, PoolInspector>(
investor: <T as frame_system::Config>::AccountId,
// TODO: Add limit for iterations
) -> Vec<(
<T as pallet_investments::Config>::InvestmentId,
InvestmentPortfolio<Balance>,
Expand Down Expand Up @@ -421,12 +420,12 @@ pub mod investment_portfolios {
.entry(TrancheCurrency::generate(pool_id, tranche_id))
.and_modify(|p| {
p.free_tranche_tokens = balance.free.into();
p.locked_tranche_tokens = balance.frozen.into();
p.reserved_tranche_tokens = balance.reserved.into();
})
.or_insert(
InvestmentPortfolio::<Balance>::new()
.with_free_tranche_tokens(balance.free.into())
.with_locked_tranche_tokens(balance.frozen.into()),
.with_reserved_tranche_tokens(balance.reserved.into()),
);
}
});
Expand Down
25 changes: 24 additions & 1 deletion runtime/integration-tests/src/generic/cases/investments.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use cfg_primitives::{Balance, PoolId};
use cfg_primitives::{AccountId, Balance, PoolId};
use cfg_traits::{investments::TrancheCurrency as _, Seconds};
use cfg_types::{investments::InvestmentPortfolio, permissions::PoolRole, tokens::TrancheCurrency};
use frame_support::traits::fungibles::MutateHold;
use runtime_common::apis::{
runtime_decl_for_investments_api::InvestmentsApiV1, runtime_decl_for_pools_api::PoolsApiV1,
};
Expand All @@ -26,6 +27,7 @@ const INVESTOR: Keyring = Keyring::Alice;
const POOL_A: PoolId = 23;
const EXPECTED_POOL_BALANCE: Balance = usd6(1_000_000);
const REDEEM_AMOUNT: Balance = EXPECTED_POOL_BALANCE / 2;
const HOLD_AMOUNT: Balance = EXPECTED_POOL_BALANCE / 10;
const FOR_FEES: Balance = cfg(1);

mod common {
Expand Down Expand Up @@ -159,6 +161,27 @@ fn investment_portfolio_single_tranche<T: Runtime>() {
.with_free_tranche_tokens(EXPECTED_POOL_BALANCE - REDEEM_AMOUNT)
)]
);

// Simulate holding
env.parachain_state_mut(|| {
<pallet_restricted_tokens::Pallet<T> as MutateHold<AccountId>>::hold(
invest_id.into(),
&(),
&INVESTOR.id(),
HOLD_AMOUNT,
)
.unwrap();
});
investment_portfolio = env.parachain_state_mut(|| T::Api::investment_portfolio(INVESTOR.id()));
assert_eq!(
investment_portfolio,
vec![(
invest_id,
InvestmentPortfolio::<Balance>::new()
.with_free_tranche_tokens(EXPECTED_POOL_BALANCE - REDEEM_AMOUNT - HOLD_AMOUNT)
.with_reserved_tranche_tokens(HOLD_AMOUNT)
)]
);
}

crate::test_for_runtimes!(all, investment_portfolio_single_tranche);
1 change: 1 addition & 0 deletions runtime/integration-tests/src/generic/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub trait Runtime:
+ orml_oracle::Config<OracleKey = OracleKey, OracleValue = Quantity>
+ orml_xtokens::Config<CurrencyId = CurrencyId, Balance = Balance>
+ pallet_xcm::Config
+ pallet_restricted_tokens::Config<Balance = Balance, CurrencyId = CurrencyId>
{
/// Just the RuntimeCall type, but redefined with extra bounds.
/// You can add `From` bounds in order to convert pallet calls to
Expand Down

0 comments on commit 762ddb8

Please sign in to comment.