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 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
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 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 All @@ -647,6 +648,7 @@ func New(
&app.CollectorKeeper,
&app.TokenmintKeeper,
&app.EsmKeeper,
&app.LendKeeper,
)

app.CollectorKeeper = *collectorkeeper.NewKeeper(
Expand Down
53 changes: 53 additions & 0 deletions proto/comdex/auction/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,50 @@ message QueryAuctionParamResponse {
[ (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"auction_params\"" ];
}

message QueryDutchLendAuctionRequest {
uint64 app_id = 1;
uint64 auction_mapping_id = 2;
uint64 auction_id = 3;
bool history = 4;
}

message QueryDutchLendAuctionResponse {
DutchAuction auction = 1
[ (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"auction\"" ];
}

message QueryDutchLendAuctionsRequest {
uint64 app_id = 1;
bool history = 2;
cosmos.base.query.v1beta1.PageRequest pagination = 3
[ (gogoproto.moretags) = "yaml:\"pagination\"" ];
}

message QueryDutchLendAuctionsResponse {
repeated DutchAuction auctions = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"auctions\""
];
cosmos.base.query.v1beta1.PageResponse pagination = 2
[ (gogoproto.moretags) = "yaml:\"pagination\"" ];
}

message QueryDutchLendBiddingsRequest {
string bidder = 1;
uint64 app_id = 2;
bool history = 3;
}

message QueryDutchLendBiddingsResponse {
string bidder = 1 [
(gogoproto.moretags) = "yaml:\"bidder\""
];
repeated DutchBiddings biddings = 2 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"biddings\""
];
}


service Query {
rpc QuerySurplusAuction(QuerySurplusAuctionRequest) returns (QuerySurplusAuctionResponse) {
Expand Down Expand Up @@ -241,4 +285,13 @@ service Query {
rpc QueryAuctionParams(QueryAuctionParamRequest) returns (QueryAuctionParamResponse) {
option (google.api.http).get = "/comdex/auction/v1beta1/auctionparams/{app_id}";
}
rpc QueryDutchLendAuction(QueryDutchLendAuctionRequest) returns (QueryDutchLendAuctionResponse) {
option (google.api.http).get = "/comdex/auction/v1beta1/dutchlendauction/{app_id}/{auction_mapping_id}/{auction_id}/{history}";
}
rpc QueryDutchLendAuctions(QueryDutchLendAuctionsRequest) returns (QueryDutchLendAuctionsResponse) {
option (google.api.http).get = "/comdex/auction/v1beta1/dutchlendauctions/{app_id}/{history}";
}
rpc QueryDutchLendBiddings(QueryDutchLendBiddingsRequest) returns (QueryDutchLendBiddingsResponse) {
option (google.api.http).get = "/comdex/auction/v1beta1/dutchlendbiddings/{bidder}/{app_id}/{history}";
}
}
63 changes: 39 additions & 24 deletions proto/comdex/auction/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,62 @@ import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/comdex-official/comdex/x/auction/types";
option (gogoproto.equal_all) = false;
option (gogoproto.equal_all) = false;
option (gogoproto.goproto_getters_all) = false;


message MsgPlaceSurplusBidRequest {
uint64 auction_id = 1;
string bidder = 2;
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false];
uint64 app_id =4;
uint64 auction_mapping_id =5;
uint64 auction_id = 1;
string bidder = 2;
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false];
uint64 app_id = 4;
uint64 auction_mapping_id = 5;
}

message MsgPlaceSurplusBidResponse {}

message MsgPlaceDebtBidRequest {
uint64 auction_id = 1;
string bidder = 2;
cosmos.base.v1beta1.Coin bid = 3 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin expectedUserToken = 4 [(gogoproto.nullable) = false];
uint64 app_id =5;
uint64 auction_mapping_id =6;
uint64 auction_id = 1;
string bidder = 2;
cosmos.base.v1beta1.Coin bid = 3 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin expectedUserToken = 4 [(gogoproto.nullable) = false];
uint64 app_id = 5;
uint64 auction_mapping_id = 6;
}

message MsgPlaceDebtBidResponse {}

message MsgPlaceDutchBidRequest {
uint64 auction_id = 1;
string bidder = 2;
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false];
string max= 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"max\""];
uint64 app_id =5;
uint64 auction_mapping_id =6;
uint64 auction_id = 1;
string bidder = 2;
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false];
string max = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"max\""];
uint64 app_id = 5;
uint64 auction_mapping_id = 6;
}

message MsgPlaceDutchBidResponse {}

message MsgPlaceDutchLendBidRequest {
uint64 auction_id = 1;
string bidder = 2;
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false];
string max = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"max\""];
uint64 app_id = 5;
uint64 auction_mapping_id = 6;
}

message MsgPlaceDutchLendBidResponse {}

service Msg {
rpc MsgPlaceSurplusBid(MsgPlaceSurplusBidRequest) returns (MsgPlaceSurplusBidResponse);
rpc MsgPlaceDebtBid(MsgPlaceDebtBidRequest) returns (MsgPlaceDebtBidResponse);
rpc MsgPlaceDutchBid(MsgPlaceDutchBidRequest) returns (MsgPlaceDutchBidResponse);
rpc MsgPlaceSurplusBid(MsgPlaceSurplusBidRequest) returns (MsgPlaceSurplusBidResponse);
rpc MsgPlaceDebtBid(MsgPlaceDebtBidRequest) returns (MsgPlaceDebtBidResponse);
rpc MsgPlaceDutchBid(MsgPlaceDutchBidRequest) returns (MsgPlaceDutchBidResponse);
rpc MsgPlaceDutchLendBid(MsgPlaceDutchLendBidRequest) returns (MsgPlaceDutchLendBidResponse);
}
25 changes: 24 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 @@ -174,6 +175,9 @@ message Extended_Pair {
(gogoproto.customname) = "AssetOutPoolId",
(gogoproto.moretags) = "yaml:\"asset_out_pool_id\""
];

uint64 min_usd_value_left = 6 [
(gogoproto.moretags) = "yaml:\"min_usd_value_left\"" ];
}

message AssetToPairMapping{
Expand Down Expand Up @@ -408,4 +412,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 = 4 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"bridged_asset_amount\"",
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
}

message LockedVaultToAppMapping {
Expand Down
8 changes: 8 additions & 0 deletions x/auction/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
if err4 != nil {
return
}
err5 := k.LendDutchActivator(ctx)
Fixed Show fixed Hide fixed

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
if err5 != nil {
return
}
err6 := k.RestartLendDutch(ctx)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
if err6 != nil {
return
}
}
4 changes: 4 additions & 0 deletions x/auction/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func GetQueryCmd() *cobra.Command {
queryDutchBiddings(),
queryProtocolStats(),
queryAuctionParams(),
queryDutchLendAuction(),
queryDutchLendAuctions(),
queryDutchLendBiddings(),
)

return cmd
Expand All @@ -45,6 +48,7 @@ func GetTxCmd() *cobra.Command {
txPlaceSurplusBid(),
txPlaceDebtBid(),
txPlaceDutchBid(),
txPlaceDutchLendBid(),
)

return cmd
Expand Down
Loading