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

feat: Add DirectLiquidationFee and uToken liquidation option #1222

Merged
merged 42 commits into from
Aug 10, 2022

Conversation

toteki
Copy link
Member

@toteki toteki commented Aug 7, 2022

Description

  • Adds proto for DirectLiquidationFee as well as actually implementing the behavior.

Misc additions:

  • Moved token <-> uToken denom functions to types package. Previously there were similar functions in both types and keeper.
  • Improved operations tests in simulation package and fixed a hidden bug (fees making messages fail if the random generator hit certain values, due to some transactions not using CoinsSpentInMsg)

closes: #1158


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)

Copy link
Member Author

@toteki toteki left a comment

Choose a reason for hiding this comment

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

Adds proto for DirectLiquidationFee as well as actually implementing the behavior.

Misc additions:

  • Moved token <-> uToken denom functions to types package. Previously there were similar functions in both types and keeper.
  • Improved operations tests in simulation package and fixed a hidden bug (fees making messages fail if the random generator hit certain values, due to some transactions not using CoinsSpentInMsg)

@codecov-commenter
Copy link

codecov-commenter commented Aug 8, 2022

Codecov Report

Merging #1222 (87f6468) into main (959a1e4) will decrease coverage by 0.23%.
The diff coverage is 51.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1222      +/-   ##
==========================================
- Coverage   51.20%   50.97%   -0.24%     
==========================================
  Files          67       67              
  Lines        6657     6772     +115     
==========================================
+ Hits         3409     3452      +43     
- Misses       3008     3077      +69     
- Partials      240      243       +3     
Impacted Files Coverage Δ
x/leverage/keeper/collateral.go 52.94% <0.00%> (-17.65%) ⬇️
x/leverage/keeper/filter.go 68.42% <0.00%> (-31.58%) ⬇️
x/leverage/keeper/liquidate.go 38.85% <0.00%> (-1.55%) ⬇️
x/leverage/keeper/reserves.go 68.18% <0.00%> (-10.77%) ⬇️
x/leverage/keeper/store.go 68.36% <0.00%> (-2.16%) ⬇️
x/leverage/keeper/token.go 76.66% <ø> (-1.60%) ⬇️
x/leverage/simulation/genesis.go 0.00% <0.00%> (ø)
x/leverage/simulation/params.go 0.00% <0.00%> (ø)
x/leverage/keeper/validate.go 42.59% <7.14%> (-14.56%) ⬇️
x/leverage/keeper/supply.go 42.85% <14.28%> (ø)
... and 12 more

@toteki toteki marked this pull request as ready for review August 8, 2022 17:40
@toteki toteki requested review from a team as code owners August 8, 2022 17:40
@adamewozniak adamewozniak self-requested a review August 10, 2022 18:18
Copy link
Collaborator

@adamewozniak adamewozniak left a comment

Choose a reason for hiding this comment

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

looks good! liquidation logic change is sound & simple. mostly just have nitpics 😄

CHANGELOG.md Outdated Show resolved Hide resolved
x/leverage/keeper/borrows.go Outdated Show resolved Hide resolved
x/leverage/keeper/borrows.go Outdated Show resolved Hide resolved
x/leverage/keeper/collateral.go Outdated Show resolved Hide resolved
x/leverage/keeper/collateral.go Outdated Show resolved Hide resolved
x/leverage/keeper/collateral.go Outdated Show resolved Hide resolved
x/leverage/keeper/keeper.go Outdated Show resolved Hide resolved
x/leverage/keeper/keeper.go Outdated Show resolved Hide resolved
x/leverage/types/errors.go Outdated Show resolved Hide resolved
x/leverage/keeper/liquidate.go Outdated Show resolved Hide resolved
adamewozniak and others added 10 commits August 10, 2022 13:23
Co-authored-by: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com>
Co-authored-by: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com>
Co-authored-by: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com>
Co-authored-by: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com>
Co-authored-by: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com>
@mergify mergify bot merged commit 8277b19 into main Aug 10, 2022
@mergify mergify bot deleted the adam/directliquidation branch August 10, 2022 21:34
if err != nil {
return err
}
return k.setBorrow(ctx, borrowAddr, k.GetBorrow(ctx, borrowAddr, repay.Denom).Sub(repay))
Copy link
Member

Choose a reason for hiding this comment

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

if result is zero (old_borrow - repay) then we should close the position and remove the record.

Copy link
Member Author

Choose a reason for hiding this comment

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

setBorrow (or technically setAdjustedBorrow which it uses internally) clears the record whenever something would be set to zero

// If there are not enough uTokens in balance, Withdraw will attempt to withdraw uToken collateral
// to make up the difference (as long as borrow limit allows). If the uToken denom is invalid or
// balances are insufficient to withdraw the full amount requested, returns an error.
func (k Keeper) Withdraw(ctx sdk.Context, supplierAddr sdk.AccAddress, uToken sdk.Coin) error {
Copy link
Member

Choose a reason for hiding this comment

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

+1 for renaming to uToken

x/leverage/keeper/reserves.go Show resolved Hide resolved
@robert-zaremba robert-zaremba mentioned this pull request Aug 10, 2022
17 tasks
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.

Liquidator must be incentivized to keep uTokens
4 participants