-
Notifications
You must be signed in to change notification settings - Fork 85
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
Investments: RuntimeApi for redeem and collected tokens #1589
Comments
@onnovisser Could you elaborate on the desired inputs? Would it just be an
Just to be clear, this refers to the amount of tranche tokens which can be collected by an account after their investment was processed during epoch execution? AFAIK, this information can only be retrieved by simulating a collection. cc @mustermeiszer |
@wischli
|
Thanks for the details. I would still like to know the expected input parameters for the runtime API call. In the initial issue description it appears to be just an |
just |
I actually think that only the following requirement should be added as runtime api:
The rest can be obtained in a more lightweight fashion by querying entries of the corresponding double storage maps. AFAIK, querying I was wondering whether Apps are using any indexer service? If so, seems like a great use case. Here's how you'd derive the other three above requirements. Code works but can be optimized by utilizing
const trancheIdsWithAmounts = (await api.query.ormlTokens.accounts.entries())
.map(([storageKey, amount]) => [...storageKey.toHuman(), amount])
.filter(([accountId, asset, amount]) => accountId === investor && asset.Tranche)
.map(([_, investmentId, amount]) => [investmentId.Tranche[1], amount])
const redeemInvestmentIdsWithAmounts = (await api.query.investments.redeemOrders.entries())
.map(([storageKey, amount]) => [...storageKey.toHuman(), amount])
.filter(([accountId, investmentId, amount]) => accountId === investor)
.map(([_, investmentId, amount]) => [investmentId, amount]) The part of tokens of an invest order that have not been processed yet: const investInvestmentIdsWithAmounts = (await api.query.investments.redeemOrders.entries())
.map(([storageKey, amount]) => [...storageKey.toHuman(), amount])
.filter(([accountId, investmentId, amount]) => accountId === investor)
.map(([_, investmentId, amount]) => [investmentId, amount])
Via WDYT @onnovisser ? |
@wischli |
Maybe like you said, using subquery for this would be more practical, if it's not feasible to do via a Runtime API |
It appears to me that your current flow already has knowledge of all remaining tokens that still have to be redeemed after epoch execution?! You only need to feed it all corresponding pool and tranche ids for the investor. As mentioned: This should be solved off-chain IMO. |
Yes, Ideally we wouldn't even have that function in our frontend though. I just copied how the chain computes the collectable tokens. I think Frederik is also of the opinion that most data we get should be done via runtime calls if possible, to also be more resilient to chain changes. But if there's no feasible way then we can do it in the frontend. Btw, what is the investments portfolio currently returning? I see here it gets |
Decision from sync call: The Runtime API exposes a call which returns the investment portfolio of an account: fn account_portfolio(investor: account_id) -> Vec<(InvestmentId, InvestmentPortfolio)>;
type InvestmentId = TrancheCurrency;
pub struct TrancheCurrency {
pub pool_id: PoolId,
pub tranche_id: TrancheId,
}
struct InvestmentPortfolio {
/// The unprocessed invest order amount in pool currency
pending_invest_currency: Balance,
/// The amount of tranche tokens which can be collected for an invest order
claimable_tranche_tokens: Balance,
/// The amount of tranche tokens which can be transferred
free_tranche_tokens: Balance,
/// The amount of tranche tokens which cannot be transferred
locked_tranche_tokens_: Balance,
/// The unprocessed redeem order amount in tranche tokens
pending_redeem_tranche_tokens: Balance,
/// The amount of pool currency which can be collected for a redeem order
claimable_currency: Balance
} cc @onnovisser EDIT: Changed |
Nit: would name it |
Makes sense since we have another portfolio related to an account for loans |
IMO the above sketch of the For instance, I don't think all tranche tokens can be treated equally? Moreover, assuming that we have different pool currencies in the future, these might neither have the same demonination nor FIAT value. pub struct InvestmentPortfolio<Balance, CurrencyId> {
/// The unprocessed invest order amount in pool currency
pub pending_invest_currency: BTreeMap<CurrencyId, Balance>,
/// The amount of tranche tokens which can be collected for an invest order
pub claimable_tranche_tokens: BTreeMap<CurrencyId, Balance>,
/// The amount of tranche tokens which can be transferred
pub free_tranche_tokens: BTreeMap<CurrencyId, Balance>,
/// The amount of tranche tokens which cannot be transferred
pub frozen_tranche_tokens: BTreeMap<CurrencyId, Balance>,
/// The unprocessed redeem order amount in tranche tokens
pub pending_redeem_tranche_tokens: BTreeMap<CurrencyId, Balance>,
/// The amount of pool currency which can be collected for a redeem order
pub claimable_currency: BTreeMap<CurrencyId, Balance>,
} WDYT about switching from |
@onnovisser I also saw that there already exists and fn investment_portfolio(account_id: AccountId) -> Option<Vec<(PoolId, CurrencyId, InvestmentId, Balance)>> Is this API used by Apps? Will it still be used when we have the new portfolio API? |
@wischli the return type of the API is |
|
Good point, I overlooked the return type of the |
Description
Output from a conversation with @onnovisser:
Apps needs an improvement in Investment API to obtain the following:
The text was updated successfully, but these errors were encountered: