-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add InvestmentPortfolio Runtime API #1608
Conversation
@@ -219,26 +219,6 @@ pub trait InvestmentAccountant<AccountId> { | |||
) -> Result<(), Self::Error>; | |||
} | |||
|
|||
/// Trait to handle Investment Portfolios for accounts | |||
pub trait InvestmentsPortfolio<Account> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: Removed because unused.
libs/types/src/investments.rs
Outdated
/// The amount of tranche tokens which can not be used at all and get | ||
/// slashed | ||
pub reserved_tranche_tokens: Balance, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: Decided against supporting frozen
as we don't support frozen fungibles in restricted tokens yet and are not freezing anywhere in the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't we want to add the CurrencyId
of the actual pool_currency
here as a field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it's impossible to map free pool_currency
to an InvestmentId
because
- We will have multiple pools with the same
pool_currency
- Once it is
free
, the root cause for that is unknown without introducing additional storage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry. I meant, to add this in order for the UI to show that they user has pending amount of PoolCurrency
investing. So the UI know what currencie to display.
Does this make more sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I cant follow. Could you elaborate @mustermeiszer ? We already have a field for pending pool currency. Any pool currency that is not related to an investment id shouldnt be part of this portfolio API per definition (no key value mapping).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn investment_portfolio(account_id: AccountId) -> Vec<(InvestmentId, InvestmentPortfolio)>
as per this API the UI has no knowledge what is the pool_currency
, so we should give it this information in the structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I get it, you are talking about the currency id while I was still in the amounts space. I will add it then to have a full portfolio without any need for further queries. On that note: The investment id key contains the pool id such that another query suffices to read the pool currency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runtime/altair/src/lib.rs
Outdated
impl runtime_common::apis::InvestmentsApi<Block, AccountId, TrancheCurrency, InvestmentPortfolio<Balance>> for Runtime { | ||
fn investment_portfolio(account_id: AccountId) -> Vec<(TrancheCurrency, InvestmentPortfolio<Balance>)> { | ||
runtime_common::investment_portfolios::get_account_portfolio::<Runtime, PoolSystem>(account_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: Maybe we should bump the version to V2 but Apps has not used this API so far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I would just overwrite as you did.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very nice, thanks for adding coverage in the integration tests and useful notes ✨
/// NOTE: Moving inner scope to any pallet would introduce tight(er) | ||
/// coupling due to requirement of iterating over storage maps which in turn | ||
/// require the pallet's Config trait. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
libs/types/src/investments.rs
Outdated
/// The amount of tranche tokens which can not be used at all and get | ||
/// slashed | ||
pub reserved_tranche_tokens: Balance, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't we want to add the CurrencyId
of the actual pool_currency
here as a field?
libs/types/src/investments.rs
Outdated
/// The amount of tranche tokens which can not be used at all and get | ||
/// slashed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the and get slashed
is confusing. Wouldn't it be and could can get clashed
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the wording is suboptimal as it the can is implicitly connected to can not be used at all as well as (can) get slashed. I will improve this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runtime/altair/src/lib.rs
Outdated
impl runtime_common::apis::InvestmentsApi<Block, AccountId, TrancheCurrency, InvestmentPortfolio<Balance>> for Runtime { | ||
fn investment_portfolio(account_id: AccountId) -> Vec<(TrancheCurrency, InvestmentPortfolio<Balance>)> { | ||
runtime_common::investment_portfolios::get_account_portfolio::<Runtime, PoolSystem>(account_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I would just overwrite as you did.
>::new(); | ||
|
||
// Denote current tranche token balances before dry running collecting | ||
orml_tokens::Accounts::<T>::iter_key_prefix(&investor).for_each(|currency| { | ||
if let CurrencyId::Tranche(pool_id, tranche_id) = CurrencyId::from(currency) { | ||
let balance = orml_tokens::Accounts::<T>::get(&investor, currency); | ||
let pool_currency = PoolInspector::currency_for(pool_id) | ||
.expect("Pool must exist; qed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can safely expect here and the two below cases of querying the pool currency. If we want to be super duper safe, I can wrap the rest of the inner scopes into a .map
. WDYT @mustermeiszer ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I would also say so. I also think zo remember that api calls are wrapped in a panic catching-something, I will double check that.
But think the expect is fine!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and clean!
Description
Fixes #1589
Changes and Descriptions
InvestmenPortfolio
Runtime APIInvestmentsPortfolio
trait due to not being usedTODO
Checklist: