Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -298,6 +298,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 @@ -470,5 +470,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