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 UpdateRegistry msg for gov proposal to update the token registry #1486

Merged
merged 4 commits into from
Nov 12, 2022
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
5 changes: 1 addition & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ import (
uibctransfer "github.com/umee-network/umee/v3/x/ibctransfer"
uibctransferkeeper "github.com/umee-network/umee/v3/x/ibctransfer/keeper"
"github.com/umee-network/umee/v3/x/leverage"
leverageclient "github.com/umee-network/umee/v3/x/leverage/client"
leveragekeeper "github.com/umee-network/umee/v3/x/leverage/keeper"
leveragetypes "github.com/umee-network/umee/v3/x/leverage/types"
"github.com/umee-network/umee/v3/x/oracle"
Expand Down Expand Up @@ -449,6 +448,7 @@ func New(
app.GetSubspace(leveragetypes.ModuleName),
app.BankKeeper,
app.OracleKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -537,8 +537,6 @@ func New(
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
// TODO: remove and use new proposal flow
AddRoute(leveragetypes.RouterKey, leverage.NewUpdateRegistryProposalHandler(app.LeverageKeeper)).
AddRoute(gravitytypes.RouterKey, gravitykeeper.NewGravityProposalHandler(app.GravityKeeper)).
AddRoute(bech32ibctypes.RouterKey, bech32ibc.NewBech32IBCProposalHandler(app.bech32IbcKeeper))

Expand Down Expand Up @@ -991,7 +989,6 @@ func getGovProposalHandlers() []govclient.ProposalHandler {
distrclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
leverageclient.ProposalHandler,
ibcclientclient.UpdateClientProposalHandler,
ibcclientclient.UpgradeProposalHandler,
}
Expand Down
82 changes: 82 additions & 0 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package app

import (
"bytes"
"encoding/json"
"fmt"
"strconv"
"testing"
"time"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -20,6 +23,7 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -331,3 +335,81 @@ func IntegrationTestNetworkConfig() network.Config {

return cfg
}

type GenerateAccountStrategy func(int) []sdk.AccAddress

// AddTestAddrsIncremental constructs and returns accNum amount of accounts with an
// initial balance of accAmt in random order
func AddTestAddrsIncremental(app *UmeeApp, ctx sdk.Context, accNum int, accAmt math.Int) []sdk.AccAddress {
return addTestAddrs(app, ctx, accNum, accAmt, createIncrementalAccounts)
}

func addTestAddrs(
app *UmeeApp, ctx sdk.Context, accNum int,
accAmt math.Int, strategy GenerateAccountStrategy,
) []sdk.AccAddress {
testAddrs := strategy(accNum)

initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt))

for _, addr := range testAddrs {
initAccountWithCoins(app, ctx, addr, initCoins)
}

return testAddrs
}

func TestAddr(addr string, bech string) (sdk.AccAddress, error) {
res, err := sdk.AccAddressFromHexUnsafe(addr)
if err != nil {
return nil, err
}
bechexpected := res.String()
if bech != bechexpected {
return nil, fmt.Errorf("bech encoding doesn't match reference")
}

bechres, err := sdk.AccAddressFromBech32(bech)
if err != nil {
return nil, err
}
if !bytes.Equal(bechres, res) {
return nil, err
}

return res, nil
}

// createIncrementalAccounts is a strategy used by addTestAddrs() in order to generated addresses in ascending order.
func createIncrementalAccounts(accNum int) []sdk.AccAddress {
var addresses []sdk.AccAddress
var buffer bytes.Buffer

// start at 100 so we can make up to 999 test addresses with valid test addresses
for i := 100; i < (accNum + 100); i++ {
numString := strconv.Itoa(i)
buffer.WriteString("A58856F0FD53BF058B4909A21AEC019107BA6") // base address string

buffer.WriteString(numString) // adding on final two digits to make addresses unique
res, _ := sdk.AccAddressFromHexUnsafe(buffer.String())
bech := res.String()
addr, _ := TestAddr(buffer.String(), bech)

addresses = append(addresses, addr)
buffer.Reset()
}

return addresses
}

func initAccountWithCoins(app *UmeeApp, ctx sdk.Context, addr sdk.AccAddress, coins sdk.Coins) {
err := app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, coins)
if err != nil {
panic(err)
}

err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, coins)
if err != nil {
panic(err)
}
}
22 changes: 0 additions & 22 deletions proto/umee/leverage/v1/gov.proto

This file was deleted.

27 changes: 27 additions & 0 deletions proto/umee/leverage/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ syntax = "proto3";
package umee.leverage.v1;

import "cosmos/base/v1beta1/coin.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "umee/leverage/v1/leverage.proto";

option go_package = "github.com/umee-network/umee/v3/x/leverage/types";

Expand Down Expand Up @@ -38,6 +41,10 @@ service Msg {

// SupplyCollateral combines the Supply and Collateralize actions.
rpc SupplyCollateral(MsgSupplyCollateral) returns (MsgSupplyCollateralResponse);

// GovUpdateRegistry adds new tokens to the token registry or
// updates existing tokens with new settings.
rpc GovUpdateRegistry(MsgGovUpdateRegistry) returns (MsgGovUpdateRegistryResponse);
}

// MsgSupply represents a user's request to supply assets to the module.
Expand Down Expand Up @@ -159,3 +166,23 @@ message MsgSupplyCollateralResponse {
// Collateralized is the amount of uTokens collateralized.
cosmos.base.v1beta1.Coin collateralized = 1 [(gogoproto.nullable) = false];
}

// MsgGovUpdateRegistry defines the Msg/GovUpdateRegistry request type.
message MsgGovUpdateRegistry {
option (gogoproto.equal) = true;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string title = 2;
string description = 3;
// add_tokens defines new token settings.
repeated Token add_tokens = 4 [(gogoproto.nullable) = false];
// update_tokens defines the new settings for existed tokens.
repeated Token update_tokens = 5 [(gogoproto.nullable) = false];
}

// MsgGovUpdateRegistryResponse defines the Msg/GovUpdateRegistry response type.
message MsgGovUpdateRegistryResponse {}
86 changes: 83 additions & 3 deletions x/leverage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ The leverage module depends directly on `x/oracle` for asset prices, and interac
2. **[State](#state)**
3. **[Queries](#queries)**
4. **[Messages](#messages)**
5. **[Events](#events)**
6. **[Parameters](#params)**
7. **[EndBlock](#end-block)**
5. **[Update Registry Proposal](#update-registry-proposal)**
6. **[Events](#events)**
7. **[Parameters](#params)**
8. **[EndBlock](#end-block)**
- [Bad Debt Sweeping](#sweep-bad-debt)
- [Interest Accrual](#accrue-interest)

Expand Down Expand Up @@ -263,6 +264,85 @@ See [leverage query proto](https://github.com/umee-network/umee/blob/main/proto/

See [leverage tx proto](https://github.com/umee-network/umee/blob/main/proto/umee/leverage/v1/tx.proto#L11) for list of supported messages.

## Update Registry Proposal

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

### Cli
```bash
umeed tx gov submit-proposal [path-to-proposal-json] [flags]
```

Example:

```bash
umeed tx gov submit-proposal /path/to/proposal.json --from umee1..

// Note `authority` will be gov module account address in proposal.json
umeed q auth module-accounts -o json | jq '.accounts[] | select(.name=="gov") | .base_account.address'
```

where `proposal.json` contains:

```json
{
"messages": [
{
"@type": "/umee.leverage.v1.MsgGovUpdateRegistry",
"authority": "umee10d07y265gmmuvt4z0w9aw880jnsr700jg5w6jp",
"title": "Update the Leverage Token Registry",
"description": "Update the uumee token in the leverage registry.",
"add_tokens": [
{
"base_denom": "uumee",
"reserve_factor": "0.100000000000000000",
"collateral_weight": "0.050000000000000000",
"liquidation_threshold": "0.050000000000000000",
"base_borrow_rate": "0.020000000000000000",
"kink_borrow_rate": "0.200000000000000000",
"max_borrow_rate": "1.500000000000000000",
"kink_utilization": "0.200000000000000000",
"liquidation_incentive": "0.100000000000000000",
"symbol_denom": "UMEE",
"exponent": 6,
"enable_msg_supply": true,
"enable_msg_borrow": true,
"blacklist": false,
"max_collateral_share": "0.900000000000000000",
"max_supply_utilization": "0.900000000000000000",
"min_collateral_liquidity": "0.900000000000000000",
"max_supply": "123123"
},
],
"update_tokens": [
{
"base_denom": "uatom",
"reserve_factor": "0.100000000000000000",
"collateral_weight": "0.050000000000000000",
"liquidation_threshold": "0.050000000000000000",
"base_borrow_rate": "0.020000000000000000",
"kink_borrow_rate": "0.200000000000000000",
"max_borrow_rate": "1.500000000000000000",
"kink_utilization": "0.200000000000000000",
"liquidation_incentive": "0.100000000000000000",
"symbol_denom": "ATOM",
"exponent": 6,
"enable_msg_supply": true,
"enable_msg_borrow": true,
"blacklist": false,
"max_collateral_share": "0.900000000000000000",
"max_supply_utilization": "0.900000000000000000",
"min_collateral_liquidity": "0.900000000000000000",
"max_supply": "123123"
},
]
}
],
"metadata": "AQ==",
"deposit": "100uumee"
}
```

## Events

See [leverage events proto](https://github.com/umee-network/umee/blob/main/proto/umee/leverage/v1/events.proto) for list of supported events.
Expand Down
26 changes: 0 additions & 26 deletions x/leverage/client/cli/proposal.go

This file was deleted.

56 changes: 0 additions & 56 deletions x/leverage/client/cli/proposal_test.go

This file was deleted.

Loading