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: ecocredit ORM proto definitions #700

Merged
merged 34 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
36a7b10
feat: ORM state proto defs
technicallyty Jan 24, 2022
00480f6
fix: index
technicallyty Jan 24, 2022
c53b2d3
chore: reorder
technicallyty Jan 24, 2022
7f694f1
chore: address review & split marketplace
technicallyty Jan 24, 2022
c392289
chore: create JOIN table for issuers
technicallyty Jan 24, 2022
be30441
Update proto/regen/ecocredit/v1beta1/state.proto
technicallyty Jan 25, 2022
f50c27c
Update proto/regen/ecocredit/v1beta1/state.proto
technicallyty Jan 25, 2022
a36230a
chore: review comments
technicallyty Jan 25, 2022
af8de09
Merge branch 'ty/eco_orm' of https://github.com/regen-network/regen-l…
technicallyty Jan 25, 2022
153c823
Update proto/regen/ecocredit/v1beta1/state.proto
technicallyty Jan 25, 2022
4aa6d84
Merge branch 'ty/eco_orm' of https://github.com/regen-network/regen-l…
technicallyty Jan 25, 2022
468d8c3
feat: marketplace indexes
technicallyty Jan 25, 2022
f950fa2
feat: user/basket credit balances and fixes
technicallyty Jan 25, 2022
329961a
feat: batch sequence and batch supply
technicallyty Jan 25, 2022
3c2e291
Update proto/regen/ecocredit/v1beta1/state.proto
technicallyty Jan 25, 2022
186884c
Update proto/regen/ecocredit/v1beta1/state.proto
technicallyty Jan 25, 2022
b716048
chore: move basket messages to own directory
technicallyty Jan 25, 2022
0a15e19
chore: use batch id's to save space
technicallyty Jan 25, 2022
5e2a0c2
merge
technicallyty Jan 25, 2022
015aa9a
chore: use batch id in basket balance
technicallyty Jan 25, 2022
40bbe1e
feat: add retired tracking to batch supply
technicallyty Jan 25, 2022
a40947c
chore: remove credit type sequence
technicallyty Jan 25, 2022
9716b94
Update proto/regen/ecocredit/v1beta1/state.proto
technicallyty Jan 25, 2022
0d812f7
Update proto/regen/ecocredit/v1beta1/state.proto
technicallyty Jan 25, 2022
dbaa3b8
chore: use project_id for batch seq, use bytes for addr in eco balance
technicallyty Jan 25, 2022
2aaa7e7
Merge branch 'ty/eco_orm' of https://github.com/regen-network/regen-l…
technicallyty Jan 25, 2022
d4af6e9
Merge branch 'master' into ty/eco_orm
technicallyty Jan 25, 2022
e4b4d91
Update proto/regen/ecocredit/v1beta1/state.proto
technicallyty Jan 25, 2022
a431406
Merge branch 'ty/eco_orm' of https://github.com/regen-network/regen-l…
technicallyty Jan 25, 2022
09d4ee4
Update proto/regen/ecocredit/v1beta1/baskets/state.proto
technicallyty Jan 25, 2022
6049a6c
Apply suggestions from code review
technicallyty Jan 25, 2022
22491e9
feat: add expiration and askdenom table
technicallyty Jan 26, 2022
1bc8162
Merge branch 'ty/eco_orm' of https://github.com/regen-network/regen-l…
technicallyty Jan 26, 2022
f5c3d3d
feat: add expiration index
technicallyty Jan 26, 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
98 changes: 98 additions & 0 deletions proto/regen/ecocredit/v1beta1/marketplace/state.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
syntax = "proto3";

package regen.ecocredit.v1beta1.marketplace;

import "cosmos/orm/v1alpha1/orm.proto";
import "cosmos/base/v1beta1/coin.proto";

// SellOrder represents the information for a sell order.
message SellOrder {

option (cosmos.orm.v1alpha1.table) = {
id: 1,
primary_key: {fields: "order_id"}
index: {id: 1 fields: "batch_denom"}
technicallyty marked this conversation as resolved.
Show resolved Hide resolved
index: {id: 2 fields: "owner"}
};
technicallyty marked this conversation as resolved.
Show resolved Hide resolved

// order_id is the unique ID of sell order.
uint64 order_id = 1;

// owner is the address of the owner of the credits being sold.
string owner = 2;

// batch_denom is the credit batch being sold.
string batch_denom = 3;

// quantity is the quantity of credits being sold.
string quantity = 4;

// ask_price is the price the seller is asking for each unit of the
// batch_denom. Each credit unit of the batch will be sold for at least the
// ask_price or more.
cosmos.base.v1beta1.Coin ask_price = 5;

// disable_auto_retire disables auto-retirement of credits which allows a
// buyer to disable auto-retirement in their buy order enabling them to
// resell the credits to another buyer.
bool disable_auto_retire = 6;
}

// BuyOrder represents the information for a buy order.
message BuyOrder {

option (cosmos.orm.v1alpha1.table) = {
id: 2,
primary_key: {fields: "buy_order_id"}
technicallyty marked this conversation as resolved.
Show resolved Hide resolved
index: {id: 1 fields: "buyer"}
};
technicallyty marked this conversation as resolved.
Show resolved Hide resolved

// Selection defines a buy order selection.
message Selection {

// sum defines the type of selection.
oneof sum {
// sell_order_id is the sell order ID against which the buyer is trying to buy.
// When sell_order_id is set, this is known as a direct buy order because it
// is placed directly against a specific sell order.
uint64 sell_order_id = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be a list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think that would be out of the scope of this PR. this structure was copied from existing proto defs. so i believe this concern would warrant its own issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why a list?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaronc to select multiple orders to fill.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this model is just based on buying from a specific sell order. it's not a batch operation. it's like a shopping cart where you buy one product from one vendor


// TODO: once we have filters defined for baskets, we can enable filtered
// buy orders which will involve full double-sided batch order matching
//
// filter selects credits to buy based upon the specified filter criteria.
// Filter filter = 2;
}
}

// buy_order_id is the unique ID of buy order.
uint64 buy_order_id = 1;

// buyer is the address that created the buy order
string buyer = 2;

// selection is the buy order selection.
Selection selection = 3;

// quantity is the quantity of credits to buy. If the quantity of credits
// available is less than this amount the order will be partially filled
// unless disable_partial_fill is true.
string quantity = 4;

// bid price is the bid price for this buy order. A credit unit will be
// settled at a purchase price that is no more than the bid price. The
// buy order will fail if the buyer does not have enough funds available
// to complete the purchase.
cosmos.base.v1beta1.Coin bid_price = 5;

// disable_auto_retire allows auto-retirement to be disabled. If it is set to true
// the credits will not auto-retire and can be resold assuming that the
// corresponding sell order has auto-retirement disabled. If the sell order
// hasn't disabled auto-retirement and the buy order tries to disable it,
// that buy order will fail.
bool disable_auto_retire = 6;

// disable_partial_fill disables the default behavior of partially filling
// buy orders if the requested quantity is not available.
bool disable_partial_fill = 7;
}
technicallyty marked this conversation as resolved.
Show resolved Hide resolved
225 changes: 225 additions & 0 deletions proto/regen/ecocredit/v1beta1/state.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
syntax = "proto3";

package regen.ecocredit.v1beta1;

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

// ClassInfo represents the high-level on-chain information for a credit class.
message ClassInfo {

option (cosmos.orm.v1alpha1.table) = {
id: 1,
primary_key: {fields: "class_id"}
technicallyty marked this conversation as resolved.
Show resolved Hide resolved
index: {id: 1 fields: "admin"}
index: {id: 2 fields: "credit_type"}
};

// class_id is the unique ID of credit class.
string class_id = 1;

// admin is the admin of the credit class.
string admin = 2;

// 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), as well as unit and precision.
CreditType credit_type = 4;
}

// ClassIssuers is a JOIN table for Class Info that stores the credit class issuers
message ClassIssuer {
option (cosmos.orm.v1alpha1.table) = {
id: 2,
primary_key: {fields: "class_id,issuer"}
};

// class_id is the unique ID of credit class.
string class_id = 1;

// issuer is the approved issuer of the credit class.
string issuer = 2;
}

// ProjectInfo represents the high-level on-chain information for a project.
message ProjectInfo {

option (cosmos.orm.v1alpha1.table) = {
id: 3,
primary_key: {fields: "project_id"}
technicallyty marked this conversation as resolved.
Show resolved Hide resolved
index: {id: 1 fields: "issuer"}
index: {id: 2 fields: "class_id"}
};

// project_id is the unique ID of the project.
string project_id = 1;

// class_id is the unique ID of credit class for this project.
string class_id = 2;

// issuer is the issuer of the credit batches for this project.
string issuer = 3;

// project_location is the location of the project.
// Full documentation can be found in MsgCreateProject.project_location.
string project_location = 4;

// metadata is any arbitrary metadata attached to the project.
bytes metadata = 5;
}

// BatchInfo represents the high-level on-chain information for a credit batch.
message BatchInfo {

option (cosmos.orm.v1alpha1.table) = {
id: 4,
primary_key: {fields: "id", auto_increment: true}
index: {fields: "batch_denom", unique: true}
index: {id: 1 fields: "project_id"}
index: {id: 2 fields: "start_date"}
};

// id is a an incrementing integer to identify the batch
technicallyty marked this conversation as resolved.
Show resolved Hide resolved
uint64 id = 1;

// project_id is the unique ID of the project this batch belongs to.
string project_id = 2;

// batch_denom is the unique ID of credit batch.
string batch_denom = 3;

// metadata is any arbitrary metadata attached to the credit batch.
bytes metadata = 5;

// start_date is the beginning of the period during which this credit batch
// was quantified and verified.
google.protobuf.Timestamp start_date = 6 [ (gogoproto.stdtime) = true ];

// end_date is the end of the period during which this credit batch was
// quantified and verified.
google.protobuf.Timestamp end_date = 7 [ (gogoproto.stdtime) = true ];
}

// CreditType defines the measurement unit/precision of a certain credit type
// (e.g. carbon, biodiversity...)
message CreditType {
option (cosmos.orm.v1alpha1.table) = {
id: 5,
primary_key: {fields: "abbreviation"}
};

// 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;
}

// CreditTypeSequence stores and increments the sequence number for credit types
message CreditTypeSequence {
aaronc marked this conversation as resolved.
Show resolved Hide resolved
option (cosmos.orm.v1alpha1.table) = {
id: 6,
primary_key: {fields: "abbreviation"}
};

string abbreviation = 1;

uint64 id = 2;
}

// ProjectSequence stores and increments the sequence number for projects
message ProjectSequence {
option (cosmos.orm.v1alpha1.table) = {
id: 7,
primary_key: {fields: "project_id"}
};

string project_id = 1;

uint64 id = 2;
technicallyty marked this conversation as resolved.
Show resolved Hide resolved
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need it? This could be easily done with a simple counter (no need to store the project_id in value).

Copy link
Contributor Author

@technicallyty technicallyty Jan 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the format of the project id, when auto-generated, is classID + sequence number. looking at it again, i think actually the project_id field should be class_id. but in any case, the 2 fields are needed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be class_id

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, so ProjectSequence is a type for a key.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@technicallyty if you will be updating the project_id field, let's update the message documentation as well.


// EcocreditBalance stores each users credit balance
message EcocreditBalance {
option (cosmos.orm.v1alpha1.table) = {
id: 8,
primary_key: {fields: "address,batch_denom"}
};

// address is the address of the credit holder
string address = 1;
Copy link
Member

@aaronc aaronc Jan 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use bytes/sdk.AccAddress

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we be using cosmos scalars? or just change to bytes for now


// batch_denom is the denom of the credit batch
string batch_denom = 2;

message CreditBalance {
string tradable = 1;
string retired = 2;
}

// balance is the balance of both tradable and retired credits
CreditBalance balance = 3;
technicallyty marked this conversation as resolved.
Show resolved Hide resolved
}

// BasketBalance stores the amount of credits from a batch in a basket
message BasketBalance {
option (cosmos.orm.v1alpha1.table) = {
id: 9,
primary_key: {fields: "basket_denom,batch_denom"}
};

// basket_denom is the denom of the basket
string basket_denom = 1;

// batch_denom is the denom of the batch
string batch_denom = 2;
technicallyty marked this conversation as resolved.
Show resolved Hide resolved

// balance is the amount of ecocredits held in the basket
string balance = 3;
}
technicallyty marked this conversation as resolved.
Show resolved Hide resolved

// BatchSequence tracks the sequence number for batches within a class
technicallyty marked this conversation as resolved.
Show resolved Hide resolved
message BatchSequence {
option (cosmos.orm.v1alpha1.table) = {
id: 10,
technicallyty marked this conversation as resolved.
Show resolved Hide resolved
primary_key: {fields: "class_id"}
};

// class_id is the id of the class for a batch
uint64 class_id = 1;
technicallyty marked this conversation as resolved.
Show resolved Hide resolved

// num_batches is a sequence number incrementing on each issued batch
uint64 num_batches = 2;
}

// BatchSupply tracks the supply of a credit batch
message BatchSupply {
option (cosmos.orm.v1alpha1.table) = {
id: 11,
technicallyty marked this conversation as resolved.
Show resolved Hide resolved
primary_key: {fields: "batch_denom"}
};

// batch_denom is the denom of the batch
string batch_denom = 1;

// total_amount is the total number of active credits in the credit batch.
// Some of the issued credits may be cancelled and will be removed from
// total_amount and tracked in amount_cancelled. total_amount and
// amount_cancelled will always sum to the original credit issuance amount.
string total_amount = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are we tracking retired amount? That's different from cancelled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it wasn't tracked in the original design. i can split the supply into tradable and retired

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// cancelled_amount is the number of credits in the batch that have been
// cancelled, effectively undoing the issuance. The sum of total_amount and
// amount_cancelled will always equal the original credit issuance amount.
string cancelled_amount = 3;
}