Skip to content

Commit

Permalink
Merge pull request #1051 from Kava-Labs/dl-upgrade-cdp-types
Browse files Browse the repository at this point in the history
Upgrade CDP types to v0.44
  • Loading branch information
drklee3 authored Nov 16, 2021
2 parents 631f00f + e796f0c commit 10a7262
Show file tree
Hide file tree
Showing 36 changed files with 14,866 additions and 2,566 deletions.
805 changes: 769 additions & 36 deletions docs/core/proto-docs.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/spf13/cast v1.3.1
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.0
Expand Down
51 changes: 51 additions & 0 deletions proto/kava/cdp/v1beta1/cdp.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
syntax = "proto3";
package kava.cdp.v1beta1;

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

option go_package = "github.com/kava-labs/kava/x/cdp/types";
option (gogoproto.goproto_getters_all) = false;

// CDP defines the state of a single collateralized debt position.
message CDP {
uint64 id = 1 [(gogoproto.customname) = "ID"];
bytes owner = 2 [
(cosmos_proto.scalar) = "cosmos.AddressBytes",
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"
];
string type = 3;
cosmos.base.v1beta1.Coin collateral = 4 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin principal = 5 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin accumulated_fees = 6 [(gogoproto.nullable) = false];
google.protobuf.Timestamp fees_updated = 7 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
string interest_factor = 8 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

// Deposit defines an amount of coins deposited by an account to a cdp
message Deposit {
uint64 cdp_id = 1 [(gogoproto.customname) = "CdpID"];
string depositor = 2 [
(cosmos_proto.scalar) = "cosmos.AddressBytes",
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"
];
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false];
}

// TotalPrincipal defines the total principal of a given collateral type
message TotalPrincipal {
string collateral_type = 1;
cosmos.base.v1beta1.Coin amount = 2 [(gogoproto.nullable) = false];
}

// TotalCollateral defines the total collateral of a given collateral type
message TotalCollateral {
string collateral_type = 1;
cosmos.base.v1beta1.Coin amount = 2 [(gogoproto.nullable) = false];
}
138 changes: 138 additions & 0 deletions proto/kava/cdp/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
syntax = "proto3";
package kava.cdp.v1beta1;

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

option go_package = "github.com/kava-labs/kava/x/cdp/types";

// GenesisState defines the cdp module's genesis state.
message GenesisState {
// params defines all the paramaters of the module.
Params params = 1 [(gogoproto.nullable) = false];

repeated CDP cdps = 2
[(gogoproto.customname) = "CDPs", (gogoproto.castrepeated) = "CDPs", (gogoproto.nullable) = false];
repeated Deposit deposits = 3 [(gogoproto.castrepeated) = "Deposits", (gogoproto.nullable) = false];
uint64 starting_cdp_id = 4 [(gogoproto.customname) = "StartingCdpID"];
string debt_denom = 5;
string gov_denom = 6;
repeated GenesisAccumulationTime previous_accumulation_times = 7
[(gogoproto.castrepeated) = "GenesisAccumulationTimes", (gogoproto.nullable) = false];
repeated GenesisTotalPrincipal total_principals = 8
[(gogoproto.castrepeated) = "GenesisTotalPrincipals", (gogoproto.nullable) = false];
}

// Params defines the parameters for the cdp module.
message Params {
repeated CollateralParam collateral_params = 1
[(gogoproto.castrepeated) = "CollateralParams", (gogoproto.nullable) = false];
DebtParam debt_param = 2 [(gogoproto.nullable) = false];

cosmos.base.v1beta1.Coin global_debt_limit = 3 [(gogoproto.nullable) = false];
string surplus_auction_threshold = 4 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string surplus_auction_lot = 5 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string debt_auction_threshold = 6 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string debt_auction_lot = 7 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
bool circuit_breaker = 8;
}

// DebtParam defines governance params for debt assets
message DebtParam {
string denom = 1;
string reference_asset = 2;
string conversion_factor = 3 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string debt_floor = 4 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

// CollateralParam defines governance parameters for each collateral type within the cdp module
message CollateralParam {
string denom = 1;
string type = 2;
string liquidation_ratio = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
cosmos.base.v1beta1.Coin debt_limit = 4 [(gogoproto.nullable) = false];
string stability_fee = 5 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string auction_size = 6 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string liquidation_penalty = 7 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string spot_market_id = 8 [(gogoproto.customname) = "SpotMarketID"];
string liquidation_market_id = 9 [(gogoproto.customname) = "LiquidationMarketID"];
string keeper_reward_percentage = 10 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string check_collateralization_index_count = 11 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string conversion_factor = 12 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

// GenesisAccumulationTime defines the previous distribution time and its corresponding denom
message GenesisAccumulationTime {
string collateral_type = 1;
google.protobuf.Timestamp previous_accumulation_time = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
string interest_factor = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

// GenesisTotalPrincipal defines the total principal and its corresponding collateral type
message GenesisTotalPrincipal {
string collateral_type = 1;
string total_principal = 2 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
147 changes: 147 additions & 0 deletions proto/kava/cdp/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
syntax = "proto3";
package kava.cdp.v1beta1;

import "kava/cdp/v1beta1/genesis.proto";
import "kava/cdp/v1beta1/cdp.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/auth/v1beta1/auth.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/kava-labs/kava/x/cdp/types";

// Query defines the gRPC querier service for cdp module
service Query {
// Params queries all parameters of the cdp module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/kava/cdp/v1beta1/params";
}

// Accounts queries the CDP module accounts.
rpc Accounts(QueryAccountsRequest) returns (QueryAccountsResponse) {
option (google.api.http).get = "/kava/cdp/v1beta1/accounts";
};

// TotalPrincipal queries the total principal of a given collateral type.
rpc TotalPrincipal(QueryTotalPrincipalRequest) returns (QueryTotalPrincipalResponse) {
option (google.api.http).get = "/kava/cdp/v1beta1/totalPrincipal";
};

// TotalCollateral queries the total collateral of a given collateral type.
rpc TotalCollateral(QueryTotalCollateralRequest) returns (QueryTotalCollateralResponse) {
option (google.api.http).get = "/kava/cdp/v1beta1/totalCollateral";
};

// Cdps queries all active CDPs.
rpc Cdps(QueryCdpsRequest) returns (QueryCdpsResponse) {
option (google.api.http).get = "/kava/cdp/v1beta1/cdps";
};

// Cdp queries a CDP with the input owner address and collateral type.
rpc Cdp(QueryCdpRequest) returns (QueryCdpResponse) {
option (google.api.http).get = "/kava/cdp/v1beta1/cdps/{owner}/{collateral_type}";
};

// Deposits queries deposits associated with the CDP owned by an address for a collateral type.
rpc Deposits(QueryDepositsRequest) returns (QueryDepositsResponse) {
option (google.api.http).get = "/kava/cdp/v1beta1/cdps/deposits/{owner}/{collateral_type}";
};
}

// QueryParamsRequest defines the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse defines the response type for the Query/Params RPC method.
message QueryParamsResponse {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

Params params = 1 [(gogoproto.nullable) = false];
}

// QueryAccountsRequest defines the request type for the Query/Accounts RPC method.
message QueryAccountsRequest {}

// QueryAccountsResponse defines the response type for the Query/Accounts RPC method.
message QueryAccountsResponse {
repeated cosmos.auth.v1beta1.ModuleAccount accounts = 1 [(gogoproto.nullable) = false];
}

// QueryCdpRequest defines the request type for the Query/Cdp RPC method.
message QueryCdpRequest {
string collateral_type = 1;
string owner = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// QueryCdpResponse defines the response type for the Query/Cdp RPC method.
message QueryCdpResponse {
CDPResponse cdp = 1 [(gogoproto.nullable) = false];
}

// QueryCdpsRequest is the params for a filtered CDP query, the request type for the Query/Cdps RPC method.
message QueryCdpsRequest {
string collateral_type = 1;
string owner = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
uint64 id = 3 [(gogoproto.customname) = "ID"];
// sdk.Dec as a string
string ratio = 4;

cosmos.base.query.v1beta1.PageRequest pagination = 5;
}

// QueryCdpsResponse defines the response type for the Query/Cdps RPC method.
message QueryCdpsResponse {
repeated CDPResponse cdps = 1 [(gogoproto.castrepeated) = "CDPResponses", (gogoproto.nullable) = false];

cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryDepositsRequest defines the request type for the Query/Deposits RPC method.
message QueryDepositsRequest {
string collateral_type = 1;
string owner = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// QueryDepositsResponse defines the response type for the Query/Deposits RPC method.
message QueryDepositsResponse {
repeated Deposit deposits = 1 [(gogoproto.castrepeated) = "Deposits", (gogoproto.nullable) = false];
}

// QueryTotalPrincipalRequest defines the request type for the Query/TotalPrincipal RPC method.
message QueryTotalPrincipalRequest {
string collateral_type = 1;
}

// QueryTotalPrincipalResponse defines the response type for the Query/TotalPrincipal RPC method.
message QueryTotalPrincipalResponse {
repeated TotalPrincipal total_principal = 1
[(gogoproto.castrepeated) = "TotalPrincipals", (gogoproto.nullable) = false];
}

// QueryTotalCollateralRequest defines the request type for the Query/TotalCollateral RPC method.
message QueryTotalCollateralRequest {
string collateral_type = 1;
}

// QueryTotalCollateralResponse defines the response type for the Query/TotalCollateral RPC method.
message QueryTotalCollateralResponse {
repeated TotalCollateral total_collateral = 1
[(gogoproto.castrepeated) = "TotalCollaterals", (gogoproto.nullable) = false];
}

// CDPResponse defines the state of a single collateralized debt position.
message CDPResponse {
uint64 id = 1 [(gogoproto.customname) = "ID"];
string owner = 2;
string type = 3;
cosmos.base.v1beta1.Coin collateral = 4 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin principal = 5 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin accumulated_fees = 6 [(gogoproto.nullable) = false];
google.protobuf.Timestamp fees_updated = 7 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
string interest_factor = 8;
cosmos.base.v1beta1.Coin collateral_value = 9 [(gogoproto.nullable) = false];
string collateralization_ratio = 10;
}
Loading

0 comments on commit 10a7262

Please sign in to comment.