Skip to content

Commit

Permalink
feat: automatically clear unsupplied blacklisted tokens (#1808)
Browse files Browse the repository at this point in the history
* feat: automatically clear unsupplied blacklisted tokens

* cl++

* add oracle hooks call

* lint++

* README++

---------

Co-authored-by: Robert Zaremba <[email protected]>
  • Loading branch information
toteki and robert-zaremba authored Feb 14, 2023
1 parent 0e4df51 commit 614d2c5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Features

- [1808](https://github.com/umee-network/umee/pull/1808) Blacklisted tokens automatically cleared from token registry if they have not yet been supplied.

### Fixes

- [1812](https://github.com/umee-network/umee/pull/1812) MaxCollateralShare now works during partial oracle outages when certain conditions are safe.
Expand Down
6 changes: 6 additions & 0 deletions x/leverage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ See [leverage tx proto](https://github.com/umee-network/umee/blob/main/proto/ume

`Update-Registry` gov proposal will adds the new tokens to token registry or update the existing token with new settings.

Under certain conditions, tokens will be automatically deleted:
- The token has been blacklisted by a previous proposal or the current one
- The token has not been supplied to the module, so there are no uTokens, borrows, or collateral associated with it.

The conditions allow for mistakenly registered tokens which have never been used to be removed from the registry. It is not safe to remove a token with active supply or borrows, so those stay listed in the registry when blacklisted.

### CLI
```bash
umeed tx gov submit-proposal [path-to-proposal-json] [flags]
Expand Down
6 changes: 6 additions & 0 deletions x/leverage/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,5 +468,11 @@ func (s msgServer) GovUpdateRegistry(
return &types.MsgGovUpdateRegistryResponse{}, err
}

// cleans blacklisted tokens from the registry if they have not been supplied
err = s.keeper.CleanTokenRegistry(ctx)
if err != nil {
return &types.MsgGovUpdateRegistryResponse{}, err
}

return &types.MsgGovUpdateRegistryResponse{}, nil
}
30 changes: 30 additions & 0 deletions x/leverage/keeper/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@ import (
"github.com/umee-network/umee/v4/x/leverage/types"
)

// CleanTokenRegistry deletes all blacklisted tokens in the leverage registry
// whose uToken supplies are zero. Called automatically on registry update.
func (k Keeper) CleanTokenRegistry(ctx sdk.Context) error {
tokens := k.GetAllRegisteredTokens(ctx)
for _, t := range tokens {
if t.Blacklist {
uDenom := types.ToUTokenDenom(t.BaseDenom)
uSupply := k.GetUTokenSupply(ctx, uDenom)
if uSupply.IsZero() {
err := k.deleteTokenSettings(ctx, t)
if err != nil {
return err
}
}
}
}
return nil
}

// deleteTokenSettings deletes a Token in the x/leverage module's KVStore.
// it should only be called by CleanTokenRegistry.
func (k Keeper) deleteTokenSettings(ctx sdk.Context, token types.Token) error {
store := ctx.KVStore(k.storeKey)
tokenKey := types.KeyRegisteredToken(token.BaseDenom)
store.Delete(tokenKey)
// call oracle hooks on deleted (not just blacklisted) token
k.hooks.AfterRegisteredTokenRemoved(ctx, token)
return nil
}

// SetTokenSettings stores a Token into the x/leverage module's KVStore.
func (k Keeper) SetTokenSettings(ctx sdk.Context, token types.Token) error {
if err := token.Validate(); err != nil {
Expand Down

0 comments on commit 614d2c5

Please sign in to comment.