Skip to content

Commit

Permalink
feat: ecocredit ORM proto definitions (#700)
Browse files Browse the repository at this point in the history
* feat: ORM state proto defs

* fix: index

* chore: reorder

* chore: address review & split marketplace

* chore: create JOIN table for issuers

* Update proto/regen/ecocredit/v1beta1/state.proto

Co-authored-by: Aaron Craelius <aaron@regen.network>

* Update proto/regen/ecocredit/v1beta1/state.proto

Co-authored-by: Aaron Craelius <aaron@regen.network>

* chore: review comments

* Update proto/regen/ecocredit/v1beta1/state.proto

Co-authored-by: Aaron Craelius <aaron@regen.network>

* feat: marketplace indexes

* feat: user/basket credit balances and fixes

* feat: batch sequence and batch supply

* Update proto/regen/ecocredit/v1beta1/state.proto

Co-authored-by: Aaron Craelius <aaron@regen.network>

* Update proto/regen/ecocredit/v1beta1/state.proto

Co-authored-by: Aaron Craelius <aaron@regen.network>

* chore: move basket messages to own directory

* chore: use batch id's to save space

* chore: use batch id in basket balance

* feat: add retired tracking to batch supply

* chore: remove credit type sequence

* Update proto/regen/ecocredit/v1beta1/state.proto

Co-authored-by: Aaron Craelius <aaron@regen.network>

* Update proto/regen/ecocredit/v1beta1/state.proto

Co-authored-by: Aaron Craelius <aaron@regen.network>

* chore: use project_id for batch seq, use bytes for addr in eco balance

* Update proto/regen/ecocredit/v1beta1/state.proto

Co-authored-by: Aaron Craelius <aaron@regen.network>

* Update proto/regen/ecocredit/v1beta1/baskets/state.proto

Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Cory <cjlevinson@gmail.com>

* feat: add expiration and askdenom table

* feat: add expiration index

Co-authored-by: technicallyty <48813565+tytech3@users.noreply.github.com>
Co-authored-by: Aaron Craelius <aaron@regen.network>
Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com>
Co-authored-by: Cory <cjlevinson@gmail.com>
  • Loading branch information
5 people authored Jan 26, 2022
1 parent 26cb432 commit 6699a38
Show file tree
Hide file tree
Showing 3 changed files with 337 additions and 13 deletions.
22 changes: 22 additions & 0 deletions proto/regen/ecocredit/v1beta1/baskets/state.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";

package regen.ecocredit.v1beta1.baskets;

import "cosmos/orm/v1alpha1/orm.proto";

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

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

// batch_id is the id of the credit batch
uint64 batch_id = 2;

// balance is the amount of ecocredits held in the basket
string balance = 3;
}
129 changes: 129 additions & 0 deletions proto/regen/ecocredit/v1beta1/marketplace/state.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
syntax = "proto3";

package regen.ecocredit.v1beta1.marketplace;

import "cosmos/orm/v1alpha1/orm.proto";
import "cosmos/base/v1beta1/coin.proto";
import "google/protobuf/timestamp.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"}
index: {id: 2 fields: "owner"}
index: {id: 3 fields: "expiration"}
};

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

// expiration is an optional timestamp when the sell order expires. When the
// expiration time is reached, the sell order is removed from state.
google.protobuf.Timestamp expiration = 7 [ (gogoproto.stdtime) = true ];
}

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

option (cosmos.orm.v1alpha1.table) = {
id: 2,
primary_key: {fields: "buy_order_id"}
index: {id: 1 fields: "buyer"}
index: {id: 2 fields: "expiration"}
};

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

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

// expiration is the optional timestamp when the buy order expires. When the
// expiration time is reached, the buy order is removed from state.
google.protobuf.Timestamp expiration = 8 [ (gogoproto.stdtime) = true ];
}

// AskDenom represents the information for an ask denom.
message AskDenom {

option (cosmos.orm.v1alpha1.table) = {
id: 3,
primary_key: {fields: "denom"}
index: {id: 1 fields: "display_denom"}
};

// denom is the denom to allow (ex. ibc/GLKHDSG423SGS)
string denom = 1;

// display_denom is the denom to display to the user and is informational
string display_denom = 2;

// exponent is the exponent that relates the denom to the display_denom and is
// informational
uint32 exponent = 3;
}
199 changes: 186 additions & 13 deletions proto/regen/ecocredit/v1beta1/state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,198 @@ 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"}
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"}
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 an auto-incrementing integer to succinctly identify the batch
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: 1,
primary_key: {fields: "abbreviation"}
};
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;
}

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

// project_id is the id of the project
string project_id = 1;

// next_id is the sequence number for the project
uint64 next_id = 2;
}

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

// address is the address of the credit holder
bytes address = 1;

// batch_id is the id of the credit batch
uint64 batch_id = 2;

// tradable is the tradable amount of credits
string tradable = 3;

// retired is the retired amount of credits
string retired = 4;
}

// BatchSequence tracks the sequence number for batches within a project
message BatchSequence {
option (cosmos.orm.v1alpha1.table) = {
id: 9,
primary_key: {fields: "project_id"}
};

// project_id is the id of the project for a batch
string project_id = 1;

// 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: 10,
primary_key: {fields: "id"}
};

// the type of credit (e.g. carbon, biodiversity, etc)
string name = 1;
// id is the id of the batch
uint64 id = 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;
// tradable_amount is the total number of tradable credits in the credit batch.
// Some of the issued credits may be cancelled and will be removed from
// tradable_amount and tracked in amount_cancelled. tradable_amount + retired_amount +
// amount_cancelled will always sum to the original credit issuance amount.
string tradable_amount = 2;

// the measurement unit (e.g. kg, ton, etc)
string unit = 3;
// retired_amount is the total amount of credits that have been retired from the credit batch.
string retired_amount = 3;

// the decimal precision
uint32 precision = 4;
// 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 = 4;
}

0 comments on commit 6699a38

Please sign in to comment.