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

Feature/lend refactor #349

Merged
merged 12 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ func New(
&app.MarketKeeper,
&app.AuctionKeeper,
&app.EsmKeeper,
&app.LendKeeper,
)

app.AuctionKeeper = *auctionkeeper.NewKeeper(
Expand Down
22 changes: 21 additions & 1 deletion proto/comdex/lend/v1beta1/lend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ message LendAsset {
(gogoproto.moretags) = "yaml:\"reward_accumulated\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"
];

uint64 app_id = 10
[(gogoproto.customname) = "AppId", (gogoproto.moretags) = "yaml:\"app_id\""];
}

message BorrowAsset {
Expand Down Expand Up @@ -408,4 +409,23 @@ message ModuleBalanceStats{
(gogoproto.moretags) = "yaml:\"balance\"",
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
}

message BalanceStats{
uint64 asset_id = 1 [
(gogoproto.customname) = "AssetId",
(gogoproto.moretags) = "yaml:\"asset_id\""
];
string amount = 2 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"amount\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"
];
}

message DepositStats{
repeated BalanceStats balance_stats = 1[
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"balance_stats\""
];
}
61 changes: 61 additions & 0 deletions proto/comdex/lend/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,47 @@ message QueryModuleBalanceResponse {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"module_balance\""];
}

message QueryDepositStatsRequest {}

message QueryDepositStatsResponse {
DepositStats DepositStats = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"deposit_stats\""];
}

message QueryUserDepositStatsRequest {}

message QueryUserDepositStatsResponse {
DepositStats UserDepositStats = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"user_deposit_stats\""];
}

message QueryReserveDepositStatsRequest {}

message QueryReserveDepositStatsResponse {
DepositStats ReserveDepositStats = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"reserve_deposit_stats\""];
}

message QueryBuyBackDepositStatsRequest {}

message QueryBuyBackDepositStatsResponse {
DepositStats BuyBackDepositStats = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"buy_back_deposit_stats\""];
}

message QueryBorrowStatsRequest {}

message QueryBorrowStatsResponse {
DepositStats BorrowStats = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"borrow_stats\""];
}

service Query {
rpc QueryLends(QueryLendsRequest) returns (QueryLendsResponse) {
option (google.api.http).get = "/comdex/lend/v1beta1/lends";
Expand Down Expand Up @@ -303,5 +344,25 @@ service Query {
rpc QueryModuleBalance(QueryModuleBalanceRequest) returns (QueryModuleBalanceResponse) {
option (google.api.http).get = "/comdex/lend/v1beta1/module_balance/{pool_id}";
};

rpc QueryDepositStats(QueryDepositStatsRequest) returns (QueryDepositStatsResponse) {
option (google.api.http).get = "/comdex/lend/v1beta1/deposit_stats";
}

rpc QueryUserDepositStats(QueryUserDepositStatsRequest) returns (QueryUserDepositStatsResponse) {
option (google.api.http).get = "/comdex/lend/v1beta1/user_deposit_stats";
}

rpc QueryReserveDepositStats(QueryReserveDepositStatsRequest) returns (QueryReserveDepositStatsResponse) {
option (google.api.http).get = "/comdex/lend/v1beta1/reserve_deposit_stats";
}

rpc QueryBuyBackDepositStats(QueryBuyBackDepositStatsRequest) returns (QueryBuyBackDepositStatsResponse) {
option (google.api.http).get = "/comdex/lend/v1beta1/buy_back_deposit_stats";
}

rpc QueryBorrowStats(QueryBorrowStatsRequest) returns (QueryBorrowStatsResponse) {
option (google.api.http).get = "/comdex/lend/v1beta1/borrow_stats";
}
}

5 changes: 3 additions & 2 deletions proto/comdex/lend/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ message MsgLend {
uint64 asset_id = 2;
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false];
uint64 pool_id = 4;
uint64 app_id = 5;
}

message MsgWithdraw {
Expand All @@ -62,7 +63,7 @@ message MsgBorrow {
string borrower = 1;
uint64 lend_id = 2;
uint64 pair_id = 3;
bool is_stable_borrow =4;
bool is_stable_borrow = 4;
cosmos.base.v1beta1.Coin amount_in = 5 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin amount_out = 6 [(gogoproto.nullable) = false];
}
Expand Down Expand Up @@ -93,7 +94,7 @@ message MsgCloseBorrow {

message MsgFundModuleAccounts {
string moduleName = 1;
uint64 assetId =2;
uint64 assetId = 2;
string lender = 3;
cosmos.base.v1beta1.Coin amount = 4 [(gogoproto.nullable) = false];
}
Expand Down
19 changes: 19 additions & 0 deletions proto/comdex/liquidation/v1beta1/locked_vault.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package comdex.liquidation.v1beta1;

import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/comdex-official/comdex/x/liquidation/types";
option (gogoproto.equal_all) = false;
Expand Down Expand Up @@ -95,6 +96,24 @@ message LockedVault {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"interest_accumulated\"",
(gogoproto.nullable) = false];
oneof kind {
BorrowMetaData borrow_meta_data = 19;
}
}

message BorrowMetaData {
uint64 lending_id = 1;
bool is_stable_borrow = 2;
string stable_borrow_rate = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"stable_borrow_rate\""
];
cosmos.base.v1beta1.Coin bridged_asset_amount = 7 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"bridged_asset_amount\"",
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
}

message LockedVaultToAppMapping {
Expand Down
155 changes: 155 additions & 0 deletions x/lend/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func GetQueryCmd() *cobra.Command {
queryAssetRatesStats(),
QueryAssetStats(),
QueryModuleBalance(),
queryDepositStats(),
queryUserDepositStats(),
queryReserveDepositStats(),
queryBuyBackDepositStats(),
queryBorrowStats(),
)

return cmd
Expand Down Expand Up @@ -691,3 +696,153 @@ func QueryModuleBalance() *cobra.Command {
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

func queryDepositStats() *cobra.Command {
cmd := &cobra.Command{
Use: "deposit-stats",
Short: "Query deposit stats",
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(ctx)

res, err := queryClient.QueryDepositStats(
context.Background(),
&types.QueryDepositStatsRequest{},
)
if err != nil {
return err
}

return ctx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "deposit-stats")

return cmd
}

func queryUserDepositStats() *cobra.Command {
cmd := &cobra.Command{
Use: "user-deposit-stats",
Short: "Query user deposit stats",
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(ctx)

res, err := queryClient.QueryUserDepositStats(
context.Background(),
&types.QueryUserDepositStatsRequest{},
)
if err != nil {
return err
}

return ctx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "user-deposit-stats")

return cmd
}

func queryReserveDepositStats() *cobra.Command {
cmd := &cobra.Command{
Use: "reserve-deposit-stats",
Short: "Query reserve deposit stats",
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(ctx)

res, err := queryClient.QueryReserveDepositStats(
context.Background(),
&types.QueryReserveDepositStatsRequest{},
)
if err != nil {
return err
}

return ctx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "reserve-deposit-stats")

return cmd
}

func queryBuyBackDepositStats() *cobra.Command {
cmd := &cobra.Command{
Use: "buy-back-deposit-stats",
Short: "Query reserve deposit stats",
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(ctx)

res, err := queryClient.QueryBuyBackDepositStats(
context.Background(),
&types.QueryBuyBackDepositStatsRequest{},
)
if err != nil {
return err
}

return ctx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "buy-back-deposit-stats")

return cmd
}

func queryBorrowStats() *cobra.Command {
cmd := &cobra.Command{
Use: "borrow-stats",
Short: "Query borrow stats",
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(ctx)

res, err := queryClient.QueryBorrowStats(
context.Background(),
&types.QueryBorrowStatsRequest{},
)
if err != nil {
return err
}

return ctx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "borrow-stats")

return cmd
}
13 changes: 9 additions & 4 deletions x/lend/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ func GetTxCmd() *cobra.Command {

func txLend() *cobra.Command {
cmd := &cobra.Command{
Use: "lend [Asset_Id] [Amount] [Pool_Id]",
Use: "lend [Asset_Id] [Amount] [Pool_Id] [App_Id]",
Short: "lend a whitelisted asset",
Args: cobra.ExactArgs(3),
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

pair, err := strconv.ParseUint(args[0], 10, 64)
assetId, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}
Expand All @@ -67,7 +67,12 @@ func txLend() *cobra.Command {
return err
}

msg := types.NewMsgLend(ctx.GetFromAddress().String(), pair, asset, pool)
appId, err := strconv.ParseUint(args[3], 10, 64)
if err != nil {
return err
}

msg := types.NewMsgLend(ctx.GetFromAddress().String(), assetId, asset, pool, appId)

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