Skip to content

Commit

Permalink
feat: Add credit types (#424)
Browse files Browse the repository at this point in the history
+Adds credit types which includes type name, unit type (kg, tonne, etc), and precision (currently locked @ 6).
+Adds query to get all credit types on CLI and grpc/http
+Updates CreateClass tx command to include credit class arg
+Adds tests for validating the credit type params
-removes per-class precision setting functionality

Closes: #424
  • Loading branch information
technicallyty committed Aug 9, 2021
1 parent 7b7d2f8 commit abe42b2
Show file tree
Hide file tree
Showing 26 changed files with 1,346 additions and 1,186 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* add dates as top level fields in credit batches (#393)
* add project location as field in credit batches (#394)
* use dec wrapper for decimal operations (#435)
* add credit types to credit class (#424)
* add params for an allowlist of permissioned credit designers (#425)

## [1.0.0] - 2021-04-13
Expand Down
78 changes: 33 additions & 45 deletions docs/modules/ecocredit/protobuf.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [regen/ecocredit/v1alpha1/types.proto](#regen/ecocredit/v1alpha1/types.proto)
- [BatchInfo](#regen.ecocredit.v1alpha1.BatchInfo)
- [ClassInfo](#regen.ecocredit.v1alpha1.ClassInfo)
- [CreditType](#regen.ecocredit.v1alpha1.CreditType)
- [GenesisState](#regen.ecocredit.v1alpha1.GenesisState)
- [Params](#regen.ecocredit.v1alpha1.Params)

Expand All @@ -24,8 +25,8 @@
- [QueryBatchInfoResponse](#regen.ecocredit.v1alpha1.QueryBatchInfoResponse)
- [QueryClassInfoRequest](#regen.ecocredit.v1alpha1.QueryClassInfoRequest)
- [QueryClassInfoResponse](#regen.ecocredit.v1alpha1.QueryClassInfoResponse)
- [QueryPrecisionRequest](#regen.ecocredit.v1alpha1.QueryPrecisionRequest)
- [QueryPrecisionResponse](#regen.ecocredit.v1alpha1.QueryPrecisionResponse)
- [QueryCreditTypesRequest](#regen.ecocredit.v1alpha1.QueryCreditTypesRequest)
- [QueryCreditTypesResponse](#regen.ecocredit.v1alpha1.QueryCreditTypesResponse)
- [QuerySupplyRequest](#regen.ecocredit.v1alpha1.QuerySupplyRequest)
- [QuerySupplyResponse](#regen.ecocredit.v1alpha1.QuerySupplyResponse)

Expand All @@ -46,8 +47,6 @@
- [MsgSend](#regen.ecocredit.v1alpha1.MsgSend)
- [MsgSend.SendCredits](#regen.ecocredit.v1alpha1.MsgSend.SendCredits)
- [MsgSendResponse](#regen.ecocredit.v1alpha1.MsgSendResponse)
- [MsgSetPrecision](#regen.ecocredit.v1alpha1.MsgSetPrecision)
- [MsgSetPrecisionResponse](#regen.ecocredit.v1alpha1.MsgSetPrecisionResponse)

- [Msg](#regen.ecocredit.v1alpha1.Msg)

Expand Down Expand Up @@ -209,6 +208,26 @@ ClassInfo represents the high-level on-chain information for a credit class.
| designer | [string](#string) | | designer is the designer of the credit class. |
| issuers | [string](#string) | repeated | issuers are the approved issuers of the credit class. |
| metadata | [bytes](#bytes) | | metadata is any arbitrary metadata to attached to the credit class. |
| credit_type | [CreditType](#regen.ecocredit.v1alpha1.CreditType) | | credit_type describes the type of credit (e.g. carbon, biodiversity), as well as unit and precision. |






<a name="regen.ecocredit.v1alpha1.CreditType"></a>

### CreditType
CreditType defines the measurement unit/precision of a certain credit type
(e.g. carbon, biodiversity...)


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | the type of credit (e.g. carbon, biodiversity, etc) |
| abbreviation | [string](#string) | | abbreviation is a 1-3 character uppercase abbreviation of the CreditType name, used in batch denominations within the CreditType. It must be unique. |
| unit | [string](#string) | | the measurement unit (e.g. kg, ton, etc) |
| precision | [uint32](#uint32) | | the decimal precision |



Expand Down Expand Up @@ -242,6 +261,7 @@ use with the x/params module.
| credit_class_fee | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | credit_class_fee is the fixed fee charged on creation of a new credit class |
| allowed_class_designers | [string](#string) | repeated | allowed_class_designers is an allowlist defining the addresses with the required permissions to create credit classes |
| allowlist_enabled | [bool](#bool) | | allowlist_enabled is a param that enables/disables the allowlist for credit creation |
| credit_types | [CreditType](#regen.ecocredit.v1alpha1.CreditType) | repeated | credit_types is a list of definitions for credit types |



Expand Down Expand Up @@ -356,30 +376,25 @@ QueryClassInfoResponse is the Query/ClassInfo request type.



<a name="regen.ecocredit.v1alpha1.QueryPrecisionRequest"></a>
<a name="regen.ecocredit.v1alpha1.QueryCreditTypesRequest"></a>

### QueryPrecisionRequest
QueryPrecisionRequest is the Query/Precision request type.
### QueryCreditTypesRequest
QueryCreditTypesRequest is the Query/Credit_Types request type


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| batch_denom | [string](#string) | | batch_denom is the unique ID of credit batch to query. |




<a name="regen.ecocredit.v1alpha1.QueryCreditTypesResponse"></a>


<a name="regen.ecocredit.v1alpha1.QueryPrecisionResponse"></a>

### QueryPrecisionResponse
QueryPrecisionResponse is the Query/Precision response type.
### QueryCreditTypesResponse
QueryCreditTypesRequest is the Query/Credit_Types response type


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| max_decimal_places | [uint32](#uint32) | | max_decimal_places is the maximum number of decimal places that can be used to represent some quantity of credits. It is an experimental feature to concretely explore an idea proposed in https://github.com/cosmos/cosmos-sdk/issues/7113. |
| credit_types | [CreditType](#regen.ecocredit.v1alpha1.CreditType) | repeated | list of credit types |



Expand Down Expand Up @@ -434,7 +449,7 @@ Msg is the regen.ecocredit.v1alpha1 Query service.
| BatchInfo | [QueryBatchInfoRequest](#regen.ecocredit.v1alpha1.QueryBatchInfoRequest) | [QueryBatchInfoResponse](#regen.ecocredit.v1alpha1.QueryBatchInfoResponse) | BatchInfo queries for information on a credit batch. |
| Balance | [QueryBalanceRequest](#regen.ecocredit.v1alpha1.QueryBalanceRequest) | [QueryBalanceResponse](#regen.ecocredit.v1alpha1.QueryBalanceResponse) | Balance queries the balance (both tradable and retired) of a given credit batch for a given account. |
| Supply | [QuerySupplyRequest](#regen.ecocredit.v1alpha1.QuerySupplyRequest) | [QuerySupplyResponse](#regen.ecocredit.v1alpha1.QuerySupplyResponse) | Supply queries the tradable and retired supply of a credit batch. |
| Precision | [QueryPrecisionRequest](#regen.ecocredit.v1alpha1.QueryPrecisionRequest) | [QueryPrecisionResponse](#regen.ecocredit.v1alpha1.QueryPrecisionResponse) | Precision queries the number of decimal places that can be used to represent credits in a batch. See Tx/SetPrecision for more details. |
| CreditTypes | [QueryCreditTypesRequest](#regen.ecocredit.v1alpha1.QueryCreditTypesRequest) | [QueryCreditTypesResponse](#regen.ecocredit.v1alpha1.QueryCreditTypesResponse) | CreditTypes returns the list of allowed types that credit classes can have. See Types/CreditType for more details. |

<!-- end services -->

Expand Down Expand Up @@ -555,6 +570,7 @@ MsgCreateClass is the Msg/CreateClass request type.
| designer | [string](#string) | | designer is the address of the account which designed the credit class. The designer has special permissions to change the list of issuers and perform other administrative operations. |
| issuers | [string](#string) | repeated | issuers are the account addresses of the approved issuers. |
| metadata | [bytes](#bytes) | | metadata is any arbitrary metadata to attached to the credit class. |
| credit_type | [string](#string) | | credit_type describes the type of credit (e.g. "carbon", "biodiversity"). |



Expand Down Expand Up @@ -665,33 +681,6 @@ MsgSendResponse is the Msg/Send response type.




<a name="regen.ecocredit.v1alpha1.MsgSetPrecision"></a>

### MsgSetPrecision
MsgRetire is the Msg/SetPrecision request type.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| issuer | [string](#string) | | issuer is the address of the batch issuer. |
| batch_denom | [string](#string) | | batch_denom is the unique ID of the credit batch. |
| max_decimal_places | [uint32](#uint32) | | max_decimal_places is the new maximum number of decimal places that can be used to represent some quantity of credits. It is an experimental feature to concretely explore an idea proposed in https://github.com/cosmos/cosmos-sdk/issues/7113. |






<a name="regen.ecocredit.v1alpha1.MsgSetPrecisionResponse"></a>

### MsgSetPrecisionResponse
MsgRetire is the Msg/SetPrecision response type.





<!-- end messages -->

<!-- end enums -->
Expand All @@ -711,7 +700,6 @@ Msg is the regen.ecocredit.v1alpha1 Msg service.
| Send | [MsgSend](#regen.ecocredit.v1alpha1.MsgSend) | [MsgSendResponse](#regen.ecocredit.v1alpha1.MsgSendResponse) | Send sends tradable credits from one account to another account. Sent credits can either be tradable or retired on receipt. |
| Retire | [MsgRetire](#regen.ecocredit.v1alpha1.MsgRetire) | [MsgRetireResponse](#regen.ecocredit.v1alpha1.MsgRetireResponse) | Retire retires a specified number of credits in the holder's account. |
| Cancel | [MsgCancel](#regen.ecocredit.v1alpha1.MsgCancel) | [MsgCancelResponse](#regen.ecocredit.v1alpha1.MsgCancelResponse) | Cancel removes a number of credits from the holder's account and also deducts them from the tradable supply, effectively cancelling their issuance on Regen Ledger |
| SetPrecision | [MsgSetPrecision](#regen.ecocredit.v1alpha1.MsgSetPrecision) | [MsgSetPrecisionResponse](#regen.ecocredit.v1alpha1.MsgSetPrecisionResponse) | SetPrecision allows an issuer to increase the decimal precision of a credit batch. It is an experimental feature to concretely explore an idea proposed in https://github.com/cosmos/cosmos-sdk/issues/7113. The number of decimal places allowed for a credit batch is determined by the original number of decimal places used with calling CreatBatch. SetPrecision allows the number of allowed decimal places to be increased, effectively making the supply more granular without actually changing any balances. It allows asset issuers to be able to issue an asset without needing to think about how many subdivisions are needed upfront. While it may not be relevant for credits which likely have a fairly stable market value, I wanted to experiment a bit and this serves as a proof of concept for a broader bank redesign where say for instance a coin like the ATOM or XRN could be issued in its own units rather than micro or nano-units. Instead an operation like SetPrecision would allow trading in micro, nano or pico in the future based on market demand. Arbitrary, unbounded precision is not desirable because this can lead to spam attacks (like sending 0.000000000000000000000000000001 coins). This is effectively fixed precision so under the hood it is still basically an integer, but the fixed precision can be increased so its more adaptable long term than just an integer. |

<!-- end services -->

Expand Down
29 changes: 10 additions & 19 deletions proto/regen/ecocredit/v1alpha1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ service Query {
"/regen/ecocredit/v1alpha1/batch_info/{batch_denom}/supply";
}

// Precision queries the number of decimal places that can be used to
// represent credits in a batch. See Tx/SetPrecision for more details.
rpc Precision(QueryPrecisionRequest) returns (QueryPrecisionResponse) {
// CreditTypes returns the list of allowed types that credit classes can have.
// See Types/CreditType for more details.
rpc CreditTypes(QueryCreditTypesRequest) returns (QueryCreditTypesResponse) {
option (google.api.http).get =
"/regen/ecocredit/v1alpha1/batches/{batch_denom}/precision";
"/regen/ecocredit/v1alpha1/credit-types";
}
}

Expand Down Expand Up @@ -113,20 +113,11 @@ message QuerySupplyResponse {
[ (gogoproto.moretags) = "yaml:\"retired_supply\"" ];
}

// QueryPrecisionRequest is the Query/Precision request type.
message QueryPrecisionRequest {
// QueryCreditTypesRequest is the Query/Credit_Types request type
message QueryCreditTypesRequest {}

// batch_denom is the unique ID of credit batch to query.
string batch_denom = 1 [ (gogoproto.moretags) = "yaml:\"batch_denom\"" ];
}

// QueryPrecisionResponse is the Query/Precision response type.
message QueryPrecisionResponse {

// max_decimal_places is the maximum number of decimal places that can be used
// to represent some quantity of credits. It is an experimental feature
// to concretely explore an idea proposed in
// https://github.com/cosmos/cosmos-sdk/issues/7113.
uint32 max_decimal_places = 1
[ (gogoproto.moretags) = "yaml:\"max_decimal_places\"" ];
// QueryCreditTypesRequest is the Query/Credit_Types response type
message QueryCreditTypesResponse {
// list of credit types
repeated CreditType credit_types = 1;
}
47 changes: 4 additions & 43 deletions proto/regen/ecocredit/v1alpha1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,6 @@ service Msg {
// deducts them from the tradable supply, effectively cancelling their
// issuance on Regen Ledger
rpc Cancel(MsgCancel) returns (MsgCancelResponse);

// SetPrecision allows an issuer to increase the decimal precision of a credit
// batch. It is an experimental feature to concretely explore an idea proposed
// in https://github.com/cosmos/cosmos-sdk/issues/7113. The number of decimal
// places allowed for a credit batch is determined by the original number of
// decimal places used with calling CreatBatch. SetPrecision allows the number
// of allowed decimal places to be increased, effectively making the supply
// more granular without actually changing any balances. It allows asset
// issuers to be able to issue an asset without needing to think about how
// many subdivisions are needed upfront. While it may not be relevant for
// credits which likely have a fairly stable market value, I wanted to
// experiment a bit and this serves as a proof of concept for a broader bank
// redesign where say for instance a coin like the ATOM or XRN could be issued
// in its own units rather than micro or nano-units. Instead an operation like
// SetPrecision would allow trading in micro, nano or pico in the future based
// on market demand. Arbitrary, unbounded precision is not desirable because
// this can lead to spam attacks (like sending
// 0.000000000000000000000000000001 coins). This is effectively fixed
// precision so under the hood it is still basically an integer, but the fixed
// precision can be increased so its more adaptable long term than just an
// integer.
rpc SetPrecision(MsgSetPrecision) returns (MsgSetPrecisionResponse);
}

// MsgCreateClass is the Msg/CreateClass request type.
Expand All @@ -67,6 +45,9 @@ message MsgCreateClass {

// metadata is any arbitrary metadata to attached to the credit class.
bytes metadata = 3;

// credit_type describes the type of credit (e.g. "carbon", "biodiversity").
string credit_type = 4;
}

// MsgCreateClassResponse is the Msg/CreateClass response type.
Expand Down Expand Up @@ -246,24 +227,4 @@ message MsgCancel {
}

// MsgCancelResponse is the Msg/Cancel response type.
message MsgCancelResponse {}

// MsgRetire is the Msg/SetPrecision request type.
message MsgSetPrecision {

// issuer is the address of the batch issuer.
string issuer = 1;

// batch_denom is the unique ID of the credit batch.
string batch_denom = 2 [ (gogoproto.moretags) = "yaml:\"batch_denom\"" ];

// max_decimal_places is the new maximum number of decimal places that can be
// used to represent some quantity of credits. It is an experimental
// feature to concretely explore an idea proposed in
// https://github.com/cosmos/cosmos-sdk/issues/7113.
uint32 max_decimal_places = 3
[ (gogoproto.moretags) = "yaml:\"max_decimal_places\"" ];
}

// MsgRetire is the Msg/SetPrecision response type.
message MsgSetPrecisionResponse {}
message MsgCancelResponse {}
23 changes: 23 additions & 0 deletions proto/regen/ecocredit/v1alpha1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ message ClassInfo {

// metadata is any arbitrary metadata to attached to the credit class.
bytes metadata = 4;

// credit_type describes the type of credit (e.g. carbon, biodiversity), as well as unit and precision.
CreditType credit_type = 5;
}

// BatchInfo represents the high-level on-chain information for a credit batch.
Expand Down Expand Up @@ -83,10 +86,30 @@ message Params {
// allowlist_enabled is a param that enables/disables the allowlist for credit
// creation
bool allowlist_enabled = 3;

// credit_types is a list of definitions for credit types
repeated CreditType credit_types = 4;
}

// GenesisState defines the state of the ecocredit module that is needed at genesis
message GenesisState {
// Params contains the updateable global parameters for use with the x/params module
Params params = 1 [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"params\""];
}

// CreditType defines the measurement unit/precision of a certain credit type
// (e.g. carbon, biodiversity...)
message CreditType {
// the type of credit (e.g. carbon, biodiversity, etc)
string name = 1;

// abbreviation is a 1-3 character uppercase abbreviation of the CreditType
// name, used in batch denominations within the CreditType. It must be unique.
string abbreviation = 2;

// the measurement unit (e.g. kg, ton, etc)
string unit = 3;

// the decimal precision
uint32 precision = 4;
}
16 changes: 7 additions & 9 deletions x/ecocredit/client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func QueryCmd(name string) *cobra.Command {
QueryBatchInfoCmd(),
QueryBalanceCmd(),
QuerySupplyCmd(),
QueryPrecisionCmd(),
QueryCreditTypesCmd(),
)
return cmd
}
Expand Down Expand Up @@ -109,20 +109,18 @@ func QuerySupplyCmd() *cobra.Command {
})
}

func QueryPrecisionCmd() *cobra.Command {
func QueryCreditTypesCmd() *cobra.Command {
return qflags(&cobra.Command{
Use: "precision [batch_denom]",
Short: "Retrieve the maximum length of the fractional part of credits in the given batch",
Long: "Retrieve the maximum length of the fractional part of credits in the given batch. The precision tells what is the minimum unit of a credit.\nExample: a decimal number 12.345 has fractional part length equal 3. A precision=5 means that the minimum unit we can trade is 0.00001",
Args: cobra.ExactArgs(1),
Use: "types",
Short: "Retrieve the list of credit types",
Long: "Retrieve the list of credit types that contains the type name, measurement unit and precision",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
c, ctx, err := mkQueryClient(cmd)
if err != nil {
return err
}
res, err := c.Precision(cmd.Context(), &ecocredit.QueryPrecisionRequest{
BatchDenom: args[0],
})
res, err := c.CreditTypes(cmd.Context(), &ecocredit.QueryCreditTypesRequest{})
return print(ctx, res, err)
},
})
Expand Down
Loading

0 comments on commit abe42b2

Please sign in to comment.