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

Loans: Add Runtime API #1457

Merged
merged 12 commits into from Jul 18, 2023
Merged

Loans: Add Runtime API #1457

merged 12 commits into from Jul 18, 2023

Conversation

lemunozm
Copy link
Contributor

@lemunozm lemunozm commented Jul 17, 2023

Description

Fix partially #1174 for loans. I have not wanted to add the pool part because I'm not pretty involved in the index pool feature, and things have changed a bit from the last specs regarding this.

Also, not sure what we gain by merging pool & loan things in the same RuntimeAPI call. The user can make two API requests, and we maintain things isolated. If making two calls comes with some performance cost (that, as a first view, doesn't, because both calls can be done concurrently), then I think we can add an API wrapper that performs both API requests, keeping things isolated.

Changes and Descriptions

  • Add an RPC to get ActiveLoan data and computed values as present_value and interest_accrued.
  • Integration tests => Can be done in another PR => Loans: add integration tests #1458

@lemunozm lemunozm added P7-asap Issue should be addressed in the next days. D2-notify Pull request can be merged and notification about changes should be documented. I8-enhancement An additional feature. labels Jul 17, 2023
@lemunozm lemunozm self-assigned this Jul 17, 2023
src/rpc/loans.rs Outdated Show resolved Hide resolved
cdamian
cdamian previously approved these changes Jul 17, 2023
Comment on lines 496 to 500
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)]
#[scale_info(skip_type_params(T))]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "std", serde(bound = ""))]
pub struct ActiveLoanInfo<T: Config> {
Copy link
Contributor Author

@lemunozm lemunozm Jul 17, 2023

Choose a reason for hiding this comment

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

This is a bit tricky and probably useful for futures runtime APIs.

The line with bound = "" is mandatory for cases where you have both, the scale_info and derive(serde) lines. serde defaults to adding Serialize and Deserialize bounds to T, but T, in this case, does not need (and we don't want) to be serializable, it's only used to fetch information from associated types. With bounds = "", we remove those implicit bounds from serde.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for clarifying this. So this is the serde equivalent of scale_info(skip_type_params(T) more or less?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah! More or less. Also, if there were other bounds, and you do not want to "reset them" you should add bound = "K: MyOtherBound". That way you've reset the Serialize bound to T and K but not the MyOtherBound to K.

@lemunozm lemunozm requested a review from cdamian July 17, 2023 19:44
@cdamian
Copy link
Contributor

cdamian commented Jul 17, 2023

@lemunozm Can you also add an integration test for this similar to the one that we have for rewards?

@lemunozm
Copy link
Contributor Author

lemunozm commented Jul 18, 2023

Yeah, I wanted to do it, but looking into it, I've realized it would be quite time-consuming (creating a pool, creating assets, registering permissions, creating investors, investing in the pool, borrowing from loans to make the "active" loan, ...) just for being able to make the runtime API call, and right now I need to put efforts in other tasks for the release 😓.

Also, I would need to create integration tests for all loans related things. Right now, it's well-tested at pallet level but not at runtime level. I've created an issue to track this work here: #1458

Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

LGTM apart from my minor nit and the supposedly missing #[serde(rename_all = "camelCase")] for all call input arguments based on this comment.

pallets/loans/Cargo.toml Outdated Show resolved Hide resolved
@@ -43,6 +44,7 @@ std = [
"sp-std/std",
"cfg-primitives/std",
"scale-info/std",
"serde/std",
Copy link
Contributor

Choose a reason for hiding this comment

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

Since it's optional, shouldn't we apply ?

Suggested change
"serde/std",
"serde?/std",

Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering why adding this broke tests?

Copy link
Contributor Author

@lemunozm lemunozm Jul 18, 2023

Choose a reason for hiding this comment

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

I think:

  • serde?/std in case serde is enable it adds serde/std
  • serde/srd enables serde and it adds serde/std (what we want here)

@lemunozm
Copy link
Contributor Author

lemunozm commented Jul 18, 2023

Much much simpler PR after removing the annoying RPC part. Thanks @wischli!

Ref: Slack thread

@lemunozm lemunozm enabled auto-merge (squash) July 18, 2023 11:30
Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

All hail the runtime API!

@lemunozm lemunozm merged commit 222581d into main Jul 18, 2023
11 checks passed
@lemunozm lemunozm deleted the loans/runtime-api branch July 18, 2023 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D2-notify Pull request can be merged and notification about changes should be documented. I8-enhancement An additional feature. P7-asap Issue should be addressed in the next days.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants