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!: allow amount-specific control of collateral #1029

Merged
merged 37 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
40b33e1
allow amount-specific control of collateral
toteki Jun 16, 2022
ca35284
cl++
toteki Jun 16, 2022
d819429
lint++
toteki Jun 16, 2022
c17173a
++
toteki Jun 16, 2022
ea13344
Merge branch 'main' into adam/collateral
toteki Jun 27, 2022
7497233
make proto-gen
toteki Jun 27, 2022
f77d4d1
whitespace--
toteki Jun 27, 2022
232167b
fix renaming conflict
toteki Jun 27, 2022
4c950d9
--
toteki Jun 27, 2022
1115401
--
toteki Jun 27, 2022
47fa025
fix cli tests
toteki Jun 27, 2022
8c45081
fix keeper test
toteki Jun 27, 2022
ffffae8
uncomment ops test
toteki Jun 27, 2022
3415817
update comment
toteki Jun 27, 2022
6b6aa65
fix comparison
toteki Jun 27, 2022
7ed3c33
fix ops test
toteki Jun 27, 2022
f9d1fc4
spec++
toteki Jun 27, 2022
40104a6
Merge branch 'main' into adam/collateral
toteki Jun 28, 2022
6ac6e5a
apply suggestion
toteki Jun 29, 2022
dc1d385
apply suggestion
toteki Jun 29, 2022
c5febc0
Merge branch 'main' into adam/collateral
toteki Jun 29, 2022
226f58a
remove not-blacklisted requirement from RemoveCollateral
toteki Jun 29, 2022
e8de1ef
improve changelog
toteki Jun 29, 2022
9c3bd7b
add validateCollateralAsset(coin)
toteki Jun 29, 2022
e421fe7
Merge branch 'main' into adam/collateral
toteki Jun 29, 2022
afae084
fix ops test
toteki Jun 29, 2022
f4bed8c
Merge branch 'adam/collateral' of github.com:umee-network/umee into a…
toteki Jun 29, 2022
f352c4b
Merge branch 'main' into adam/collateral
toteki Jun 30, 2022
342a706
suggestion++
toteki Jul 1, 2022
a683b1c
asset -> coin
toteki Jul 1, 2022
3fb02e7
amount -> coin in MsgAdd/RemoveCollateral
toteki Jul 1, 2022
5624b4b
Merge branch 'main' into adam/collateral
toteki Jul 3, 2022
e923200
add validateBasic to new messages
toteki Jul 4, 2022
789a4d5
Add signer comments in proto files
toteki Jul 4, 2022
5a2bd99
make proto-gen
toteki Jul 4, 2022
40c6a2b
Merge branch 'main' into adam/collateral
toteki Jul 4, 2022
165bf5c
Merge branch 'main' into adam/collateral
toteki Jul 4, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking

- [1029](https://github.com/umee-network/umee/pull/1029) Removed MsgSetCollateral(addr,denom,bool), and replaced with MsgAddCollateral(addr,coin) and MsgRemoveCollateral(addr,coin)
- [1023](https://github.com/umee-network/umee/pull/1023) Restrict MsgWithdraw to only uToken input (no base token auto-convert)

### Features
Expand Down
27 changes: 9 additions & 18 deletions proto/umee/leverage/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@ import "gogoproto/gogo.proto";

// GenesisState defines the x/leverage module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated Token registry = 2 [(gogoproto.nullable) = false];
repeated AdjustedBorrow adjusted_borrows = 3 [(gogoproto.nullable) = false];
repeated CollateralSetting collateral_settings = 4
[(gogoproto.nullable) = false];
repeated Collateral collateral = 5 [(gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.Coin reserves = 6 [
Params params = 1 [(gogoproto.nullable) = false];
repeated Token registry = 2 [(gogoproto.nullable) = false];
repeated AdjustedBorrow adjusted_borrows = 3 [(gogoproto.nullable) = false];
repeated Collateral collateral = 4 [(gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.Coin reserves = 5 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
int64 last_interest_time = 7;
repeated BadDebt bad_debts = 8 [(gogoproto.nullable) = false];
repeated InterestScalar interest_scalars = 9 [(gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.Coin utoken_supply = 10 [
int64 last_interest_time = 6;
repeated BadDebt bad_debts = 7 [(gogoproto.nullable) = false];
repeated InterestScalar interest_scalars = 8 [(gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.Coin utoken_supply = 9 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
Expand All @@ -35,13 +33,6 @@ message AdjustedBorrow {
cosmos.base.v1beta1.DecCoin amount = 2 [(gogoproto.nullable) = false];
}

// CollateralSetting is a collateral setting struct used in the leverage
// module's genesis state.
message CollateralSetting {
string address = 1;
string denom = 2;
}

// Collateral is a collateral struct used in the leverage module's genesis
// state.
message Collateral {
Expand Down
20 changes: 0 additions & 20 deletions proto/umee/leverage/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ service Query {
option (google.api.http).get = "/umee/leverage/v1/reserve_amount";
}

// CollateralSetting queries a borrower's collateral setting (enabled or
// disabled) for a specified uToken denomination.
rpc CollateralSetting(QueryCollateralSettingRequest)
returns (QueryCollateralSettingResponse) {
option (google.api.http).get = "/umee/leverage/v1/collateral_setting";
}

// Collateral queries the collateral amount of a user by token denomination.
// If the denomination is not supplied, all of the user's collateral tokens
// are returned.
Expand Down Expand Up @@ -334,19 +327,6 @@ message QueryReserveAmountResponse {
];
}

// QueryCollateralSettingsRequest defines the request structure for the
// CollateralSetting gRPC service handler.
message QueryCollateralSettingRequest {
string address = 1;
string denom = 2;
}

// QueryCollateralSettingsResponse defines the response structure for the
// CollateralSetting gRPC service handler.
message QueryCollateralSettingResponse {
bool enabled = 1;
}
toteki marked this conversation as resolved.
Show resolved Hide resolved

// QueryCollateralRequest defines the request structure for the Collateral gRPC
// service handler.
message QueryCollateralRequest {
Expand Down
35 changes: 24 additions & 11 deletions proto/umee/leverage/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ service Msg {
// the capital facility.
rpc WithdrawAsset(MsgWithdrawAsset) returns (MsgWithdrawAssetResponse);

// SetCollateral defines a method for users to enable or disable a uToken
// denomination in their wallet for use as collateral.
rpc SetCollateral(MsgSetCollateral) returns (MsgSetCollateralResponse);
// AddCollateral defines a method for users to enable selected uTokens
// as collateral.
rpc AddCollateral(MsgAddCollateral) returns (MsgAddCollateralResponse);

// RemoveCollateral defines a method for users to disable selected uTokens
// as collateral.
rpc RemoveCollateral(MsgRemoveCollateral) returns (MsgRemoveCollateralResponse);
toteki marked this conversation as resolved.
Show resolved Hide resolved

// BorrowAsset defines a method for borrowing coins from the capital facility.
rpc BorrowAsset(MsgBorrowAsset) returns (MsgBorrowAssetResponse);
Expand Down Expand Up @@ -45,12 +49,18 @@ message MsgWithdrawAsset {
cosmos.base.v1beta1.Coin amount = 2 [(gogoproto.nullable) = false];
}

// MsgSetCollateral represents a lender's request to enable or disable
// a uToken type in their possession as collateral.
message MsgSetCollateral {
string borrower = 1;
string denom = 2;
bool enable = 3;
// MsgAddCollateral represents a lender's request to enable selected
// uTokens as collateral.
message MsgAddCollateral {
string borrower = 1;
toteki marked this conversation as resolved.
Show resolved Hide resolved
toteki marked this conversation as resolved.
Show resolved Hide resolved
cosmos.base.v1beta1.Coin coin = 2 [(gogoproto.nullable) = false];
}

// MsgRemoveCollateral represents a lender's request to disable selected
// uTokens as collateral.
message MsgRemoveCollateral {
string borrower = 1;
toteki marked this conversation as resolved.
Show resolved Hide resolved
toteki marked this conversation as resolved.
Show resolved Hide resolved
cosmos.base.v1beta1.Coin coin = 2 [(gogoproto.nullable) = false];
}

// MsgBorrowAsset represents a lender's request to borrow a base asset type
Expand Down Expand Up @@ -82,8 +92,11 @@ message MsgLendAssetResponse {}
// MsgWithdrawAssetResponse defines the Msg/WithdrawAsset response type.
message MsgWithdrawAssetResponse {}

// MsgSetCollateralResponse defines the Msg/SetCollateral response type.
message MsgSetCollateralResponse {}
// MsgAddCollateralResponse defines the Msg/AddCollateral response type.
message MsgAddCollateralResponse {}

// MsgRemoveCollateralResponse defines the Msg/RemoveCollateral response type.
message MsgRemoveCollateralResponse {}

// MsgBorrowAssetResponse defines the Msg/BorrowAsset response type.
message MsgBorrowAssetResponse {}
Expand Down
35 changes: 0 additions & 35 deletions x/leverage/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
GetCmdQueryReserveAmount(),
GetCmdQueryCollateral(),
GetCmdQueryCollateralValue(),
GetCmdQueryCollateralSetting(),
GetCmdQueryExchangeRate(),
GetCmdQueryLendAPY(),
GetCmdQueryBorrowAPY(),
Expand Down Expand Up @@ -289,40 +288,6 @@ func GetCmdQueryReserveAmount() *cobra.Command {
return cmd
}

// GetCmdQueryCollateralSetting creates a Cobra command to query for the collateral
// setting of a specific token denom for an address.
func GetCmdQueryCollateralSetting() *cobra.Command {
cmd := &cobra.Command{
Use: "collateral-setting [addr] [denom]",
Args: cobra.ExactArgs(2),
Short: "Query for the collateral setting of a specific denom for an address",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryCollateralSettingRequest{
Address: args[0],
Denom: args[1],
}

resp, err := queryClient.CollateralSetting(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(resp)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQueryCollateral creates a Cobra command to query for the amount of
// total collateral tokens for a given address.
func GetCmdQueryCollateral() *cobra.Command {
Expand Down
59 changes: 48 additions & 11 deletions x/leverage/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cli

import (
"fmt"
"strconv"
"strings"

"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -28,7 +27,8 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(
GetCmdLendAsset(),
GetCmdWithdrawAsset(),
GetCmdSetCollateral(),
GetCmdAddCollateral(),
GetCmdRemoveCollateral(),
GetCmdBorrowAsset(),
GetCmdRepayAsset(),
GetCmdLiquidate(),
Expand Down Expand Up @@ -103,13 +103,13 @@ func GetCmdWithdrawAsset() *cobra.Command {
return cmd
}

// GetCmdSetCollateral creates a Cobra command to generate or broadcast a
// transaction with a MsgSetCollateral message.
func GetCmdSetCollateral() *cobra.Command {
// GetCmdAddCollateral creates a Cobra command to generate or broadcast a
// transaction with a MsgAddCollateral message.
func GetCmdAddCollateral() *cobra.Command {
cmd := &cobra.Command{
Use: "set-collateral [borrower] [denom] [toggle]",
Args: cobra.ExactArgs(3),
Short: "Enable or disable an asset type to be used as collateral",
Use: "add-collateral [borrower] [coin]",
Args: cobra.ExactArgs(2),
Short: "Add uTokens as collateral",
RunE: func(cmd *cobra.Command, args []string) error {
if err := cmd.Flags().Set(flags.FlagFrom, args[0]); err != nil {
return err
Expand All @@ -120,12 +120,49 @@ func GetCmdSetCollateral() *cobra.Command {
return err
}

toggle, err := strconv.ParseBool(args[2])
coin, err := sdk.ParseCoinNormalized(args[1])
if err != nil {
return err
}
msg := types.NewMsgAddCollateral(clientCtx.GetFromAddress(), coin)
if err = msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}

// GetCmdRemoveCollateral returns a CLI command handler to generate or broadcast a
toteki marked this conversation as resolved.
Show resolved Hide resolved
// transaction with a MsgRemoveCollateral message.
func GetCmdRemoveCollateral() *cobra.Command {
cmd := &cobra.Command{
Use: "remove-collateral [borrower] [coin]",
Args: cobra.ExactArgs(2),
Short: "Remove uTokens from collateral",
RunE: func(cmd *cobra.Command, args []string) error {
if err := cmd.Flags().Set(flags.FlagFrom, args[0]); err != nil {
return err
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return fmt.Errorf("failed to parse toggle: %w", err)
return err
}

msg := types.NewMsgSetCollateral(clientCtx.GetFromAddress(), args[1], toggle)
coin, err := sdk.ParseCoinNormalized(args[1])
if err != nil {
return err
}
msg := types.NewMsgRemoveCollateral(clientCtx.GetFromAddress(), coin)
if err = msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
Expand Down
Loading