Skip to content
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: simplify constraints and remove InvestmentProperties trait #1571

Merged
merged 4 commits into from
Sep 27, 2023

Conversation

lemunozm
Copy link
Contributor

Description

Some simplifications regarding investment info/properties. Slack conversation

Changes and Descriptions

  • Removed the InvestmentProperties trait. Now, the type InvestmentInfo is used directly (which I think simplifies some parts)
  • Removed the need for the where bound everywhere the investment pallets is used to determine the correct InvestmentInfo (this simplifies things for future integration tests)

@lemunozm lemunozm added Q3-medium Can be done with good experience in the language, but little knowledge of the codebase. P2-nice-to-have Issue is worth doing. I11-cleaning No mandatory issue that leave the repo more readable/organized labels Sep 27, 2023
@lemunozm lemunozm self-assigned this Sep 27, 2023
@lemunozm lemunozm force-pushed the investments/simplify-constraints branch from 2392851 to bf1224f Compare September 27, 2023 07:43
@@ -595,7 +572,7 @@ where
amount,
})?;

let info = T::Accountant::info(investment_id).map_err(|_| Error::<T>::UnknownInvestment)?;
let _ = T::Accountant::info(investment_id).map_err(|_| Error::<T>::UnknownInvestment)?;
Copy link
Contributor Author

@lemunozm lemunozm Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this line could be removed to save a read access to the database, but there is a test that checks for the error UnknownInvestment. If removed a future Accountant::transfer() fails with a different error but I think the logic would be still ok

@@ -662,7 +638,7 @@ where
who: T::AccountId,
investment_id: T::InvestmentId,
) -> DispatchResultWithPostInfo {
let info = T::Accountant::info(investment_id).map_err(|_| Error::<T>::UnknownInvestment)?;
let _ = T::Accountant::info(investment_id).map_err(|_| Error::<T>::UnknownInvestment)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@@ -955,7 +928,7 @@ where
&mut total_order.amount,
)?;

T::Accountant::transfer(info.id(), send, recv, transfer_amount)
T::Accountant::transfer(investment_id, send, recv, transfer_amount)
Copy link
Contributor Author

@lemunozm lemunozm Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

info.id() and investment_id always match with the same value, so we can save from using info in some places

Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look sane. But I am still thinking whether it is worth the refactor. Just am wondering whether we need to have that abstraction for pallet-linked-pools.

But I we can go back and change it again if we want to.

@lemunozm
Copy link
Contributor Author

Ok! Happy to revert some parts if needed in the future.

Note that the InvestmentAccountant trait is still generic over InvestmentInfo. So it is not fixed to always use the InvestmentInfo type.

@lemunozm lemunozm enabled auto-merge (squash) September 27, 2023 09:24
@lemunozm lemunozm merged commit 8ecf05c into main Sep 27, 2023
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I11-cleaning No mandatory issue that leave the repo more readable/organized P2-nice-to-have Issue is worth doing. Q3-medium Can be done with good experience in the language, but little knowledge of the codebase.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants