Skip to content

feat: add total collateral function and query#1094

Merged
toteki merged 5 commits intomainfrom
adam/totalcollateral
Jul 4, 2022
Merged

feat: add total collateral function and query#1094
toteki merged 5 commits intomainfrom
adam/totalcollateral

Conversation

@toteki
Copy link
Copy Markdown
Contributor

@toteki toteki commented Jul 4, 2022

Adds GetTotalCollateral(denom) and an associated grpc query.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • added appropriate labels to the PR
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@toteki toteki requested review from a team as code owners July 4, 2022 18:29
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jul 4, 2022

Codecov Report

Merging #1094 (2f8085e) into main (644dcc1) will decrease coverage by 0.17%.
The diff coverage is 5.26%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1094      +/-   ##
==========================================
- Coverage   43.72%   43.54%   -0.18%     
==========================================
  Files          65       65              
  Lines        8298     8336      +38     
==========================================
+ Hits         3628     3630       +2     
- Misses       4421     4456      +35     
- Partials      249      250       +1     
Impacted Files Coverage Δ
x/leverage/client/cli/query.go 0.00% <0.00%> (ø)
x/leverage/keeper/grpc_query.go 5.77% <0.00%> (-0.14%) ⬇️
x/leverage/keeper/collateral.go 75.00% <33.33%> (-8.34%) ⬇️

@robert-zaremba robert-zaremba mentioned this pull request Jul 4, 2022
9 tasks
func (k Keeper) GetTotalCollateral(ctx sdk.Context, denom string) sdk.Int {
if !k.IsAcceptedUToken(ctx, denom) {
// non-uTokens cannot be collateral
return sdk.ZeroInt()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shouldn't we return error?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is an option, yes.

The current approach follows the other getters, in that they return zero when queried for the borrowed/reserved/etc amount of something that doesn't exist or wouldn't be valid input for a setter.

Compare to querying the borrowed amount of an invalid denom (or unregistered Token, or a uToken denom) - it will simply return zero. Actually trying to borrow the same denom returns an error though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK, then let's update the function docs please.

Copy link
Copy Markdown
Contributor Author

@toteki toteki Jul 4, 2022

Choose a reason for hiding this comment

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

lmk if the current godoc looks good

// GetTotalCollateral returns an sdk.Coin representing how much of a given uToken
// the x/leverage module account currently holds as collateral. Non-uTokens and invalid
// assets return zero.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good.

Co-authored-by: Robert Zaremba <robert@zaremba.ch>
Copy link
Copy Markdown
Contributor

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

utACK. Pending the function doc update

func (k Keeper) GetTotalCollateral(ctx sdk.Context, denom string) sdk.Int {
if !k.IsAcceptedUToken(ctx, denom) {
// non-uTokens cannot be collateral
return sdk.ZeroInt()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK, then let's update the function docs please.

@toteki toteki merged commit 75476fa into main Jul 4, 2022
@toteki toteki deleted the adam/totalcollateral branch July 4, 2022 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants