From 762ddb83848867d6f05e9f5a2bddaa3873382474 Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Fri, 17 Nov 2023 17:34:14 +0100 Subject: [PATCH] fix: rm locked, add reserved --- libs/types/src/investments.rs | 9 ++++--- runtime/common/src/lib.rs | 5 ++-- .../src/generic/cases/investments.rs | 25 ++++++++++++++++++- .../integration-tests/src/generic/config.rs | 1 + 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/libs/types/src/investments.rs b/libs/types/src/investments.rs index 9793efa53d..18604ed2c6 100644 --- a/libs/types/src/investments.rs +++ b/libs/types/src/investments.rs @@ -251,8 +251,9 @@ pub struct InvestmentPortfolio { 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 @@ -274,8 +275,8 @@ impl InvestmentPortfolio { 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 } diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 522f82f5c8..dd1a3825be 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -388,7 +388,6 @@ pub mod investment_portfolios { /// require the pallet's Config trait. pub fn get_account_portfolio( investor: ::AccountId, - // TODO: Add limit for iterations ) -> Vec<( ::InvestmentId, InvestmentPortfolio, @@ -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::::new() .with_free_tranche_tokens(balance.free.into()) - .with_locked_tranche_tokens(balance.frozen.into()), + .with_reserved_tranche_tokens(balance.reserved.into()), ); } }); diff --git a/runtime/integration-tests/src/generic/cases/investments.rs b/runtime/integration-tests/src/generic/cases/investments.rs index 46dcac0098..be4546c604 100644 --- a/runtime/integration-tests/src/generic/cases/investments.rs +++ b/runtime/integration-tests/src/generic/cases/investments.rs @@ -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, }; @@ -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 { @@ -159,6 +161,27 @@ fn investment_portfolio_single_tranche() { .with_free_tranche_tokens(EXPECTED_POOL_BALANCE - REDEEM_AMOUNT) )] ); + + // Simulate holding + env.parachain_state_mut(|| { + as MutateHold>::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::::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); diff --git a/runtime/integration-tests/src/generic/config.rs b/runtime/integration-tests/src/generic/config.rs index 83a943b7ae..7a68e129b8 100644 --- a/runtime/integration-tests/src/generic/config.rs +++ b/runtime/integration-tests/src/generic/config.rs @@ -96,6 +96,7 @@ pub trait Runtime: + orml_oracle::Config + orml_xtokens::Config + pallet_xcm::Config + + pallet_restricted_tokens::Config { /// Just the RuntimeCall type, but redefined with extra bounds. /// You can add `From` bounds in order to convert pallet calls to