Skip to content

Commit

Permalink
Merge branch 'master' into ty/856-update_sell_orders
Browse files Browse the repository at this point in the history
  • Loading branch information
technicallyty authored Mar 25, 2022
2 parents 1d78af2 + 955e8be commit 0f17d79
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 308 deletions.
21 changes: 3 additions & 18 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,9 @@ module.exports = {
'/modules/ecocredit/01_concepts',
'/modules/ecocredit/02_state',
'/modules/ecocredit/03_messages',
'/modules/ecocredit/04_events',
'/modules/ecocredit/05_client',
{
title: 'Protobuf - Core',
path: 'https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1',
},
{
title: 'Protobuf - Basket',
path: 'https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.basket.v1',
},
{
title: 'Protobuf - Marketplace',
path: 'https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1',
},
'/modules/ecocredit/04_queries',
'/modules/ecocredit/05_events',
'/modules/ecocredit/06_client',
],
},
{
Expand All @@ -157,10 +146,6 @@ module.exports = {
'/modules/data/03_messages',
'/modules/data/04_events',
'/modules/data/05_client',
{
title: 'Protobuf',
path: 'https://buf.build/regen/regen-ledger/docs/main/regen.data.v1',
},
],
},
],
Expand Down
112 changes: 68 additions & 44 deletions x/ecocredit/spec/01_concepts.md

Large diffs are not rendered by default.

124 changes: 21 additions & 103 deletions x/ecocredit/spec/02_state.md
Original file line number Diff line number Diff line change
@@ -1,111 +1,29 @@
# State

The `ecocredit` module uses the Cosmos SDK's `KVStore` directly for credit batch balances and supplies and the `orm` package (an abstraction over the `KVStore`) for table storage of credit type sequences, credit classes, and credit batches.
The `ecocredit` module uses the `orm` package as an abstraction layer over the `KVStore` that enables the creation of database tables with primary and secondary keys. The tables used within the ecocredit module are defined in the proto files available on [Buf Schema Registry](https://buf.build/regen/regen-ledger).

## Tradable Balance
## Ecocredit Core

`TradableBalance` is the tradable balance of a credit batch.
- [BatchBalance](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#regen.ecocredit.v1.BatchBalance)
- [BatchInfo](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#regen.ecocredit.v1.BatchInfo)
- [BatchSequence](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#regen.ecocredit.v1.BatchSequence)
- [BatchSupply](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#regen.ecocredit.v1.BatchSupply)
- [ClassInfo](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#regen.ecocredit.v1.ClassInfo)
- [ClassIssuer](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#regen.ecocredit.v1.ClassIssuer)
- [ClassSequence](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#regen.ecocredit.v1.ClassSequence)
- [CreditType](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#regen.ecocredit.v1.CreditType)

`TradableBalance` is stored directly in the `KVStore`:
## Basket Submodule

`0x0 | byte(address length) | []byte(address) | []byte(denom) --> []byte(amount)`
- [Basket](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.basket.v1#regen.ecocredit.basket.v1.Basket)
- [BasketBalance](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.basket.v1#regen.ecocredit.basket.v1.BasketBalance)
- [BasketCredit](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.basket.v1#regen.ecocredit.basket.v1.BasketCredit)
- [DateCriteria](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.basket.v1#regen.ecocredit.basket.v1.DateCriteria)

## Tradable Supply
## Marketplace Submodule

`TradableSupply` is the tradable supply of a credit batch.

`TradableSupply` is stored directly in the `KVStore`:

`0x1 | []byte(denom) --> []byte(amount)`

## Retired Balance

`RetiredBalance` is the retired balance of a credit batch.

`RetiredBalance` is stored directly in the `KVStore`:

`0x2 | byte(address length) | []byte(address) | []byte(denom) --> []byte(amount)`

## Retired Supply

`RetiredSupply` is the retired supply of a credit batch.

`RetiredSupply` is stored directly in the `KVStore`:

`0x3 | []byte(denom) --> []byte(amount)`

## Credit Type Sequence Table

`CreditTypeSeq` associates a sequence number with a credit type abbreviation.

The sequence number is incremented on a per credit type basis, and it exists for the purpose of providing a sequence number for the credit class ID. A credit class ID is the combination of a credit type abbreviation and a sequence number (e.g. `C01` is the ID for the first "carbon" credit class).

The `creditTypeSeqTable` stores `CreditTypeSeq`:

`0x4 | []byte(Abbreviation) -> ProtocolBuffer(CreditTypeSeq)`

+++ https://github.com/regen-network/regen-ledger/blob/50eaceda5eabc5970effe491f0d58194852718c9/proto/regen/ecocredit/v1alpha1/types.proto#L112-L122

## Class Info Table

The `classInfoTable` stores `ClassInfo`:

`0x5 | []byte(ClassId) -> ProtocolBuffer(ClassInfo)`

+++ https://github.com/regen-network/regen-ledger/blob/50eaceda5eabc5970effe491f0d58194852718c9/proto/regen/ecocredit/v1alpha1/types.proto#L11-L31

## Batch Info Table

The `batchInfoTable` stores `BatchInfo`:

`0x6 | []byte(BatchId) -> ProtocolBuffer(BatchInfo)`

+++ https://github.com/regen-network/regen-ledger/blob/50eaceda5eabc5970effe491f0d58194852718c9/proto/regen/ecocredit/v1alpha1/types.proto#L33-L72

## Project Info Table

The `projectInfoTable` stores `ProjectInfo`:

`0x10 | []byte(ProjectId) -> ProtocolBuffer(ProjectInfo)`

+++ https://github.com/regen-network/regen-ledger/blob/50eaceda5eabc5970effe491f0d58194852718c9/proto/regen/ecocredit/v1alpha1/types.proto#L33-L72

## Sell Order Table

The `sellOrderTable` stores `SellOrder`:

`0x20 | []byte(OrderId) -> ProtocolBuffer(SellOrder)`

+++ https://github.com/regen-network/regen-ledger/blob/081ae071b159b397b4c10837804b69137295e3af/proto/regen/ecocredit/v1alpha1/types.proto#L122-L146

#### Sell Order Sequence Table

The `sellOrderTable` uses a persistent unique key generator called `Sequence`:

`OrderId`: `0x21 | 0x1 -> BigEndian`

The `0x1` is a fixed key to read/write data to the storage layer.

## Buy Order Table

The `buyOrderTable` stores `BuyOrder`:

`0x25 | []byte(BuyOrderId) -> ProtocolBuffer(BuyOrder)`

+++ https://github.com/regen-network/regen-ledger/blob/081ae071b159b397b4c10837804b69137295e3af/proto/regen/ecocredit/v1alpha1/types.proto#L148-L196

#### Buy Order Sequence Table

The `buyOrderTable` uses a persistent unique key generator called `Sequence`:

`BuyOrderId`: `0x26 | 0x1 -> BigEndian`

The `0x1` is a fixed key to read/write data to the storage layer.

## Ask Denom Table

The `askDenomTable` stores `AskDenom`:

`0x30 | []byte(Denom) -> ProtocolBuffer(AskDenom)`

+++ https://github.com/regen-network/regen-ledger/blob/081ae071b159b397b4c10837804b69137295e3af/proto/regen/ecocredit/v1alpha1/types.proto#L198-L210
- [AllowedDenom](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#regen.ecocredit.marketplace.v1.AllowedDenom)
- [BatchSelector](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#regen.ecocredit.marketplace.v1.BatchSelector)
- [BuyOrder](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#regen.ecocredit.marketplace.v1.BuyOrder)
- [BuyOrder.Selection](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#regen.ecocredit.marketplace.v1.BuyOrder.Selection)
- [ClassSelector](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#regen.ecocredit.marketplace.v1.ClassSelector)
152 changes: 18 additions & 134 deletions x/ecocredit/spec/03_messages.md
Original file line number Diff line number Diff line change
@@ -1,143 +1,27 @@
# Msg Service

## MsgCreateClass
The ecocredit module provides a message service for interacting with the state of the ecocredit module. The messages are defined in the proto files available on [Buf Schema Registry](https://buf.build/regen/regen-ledger).

`MsgCreateClass` creates a new credit class with a credit class admin, an approved list of issuers, optional metadata, and a credit type. The party signing this transaction is the credit admin.
For examples on how to interact with state using the `regen` binary, see [regen tx ecocredit](../../commands/regen_tx_ecocredit.md).

+++ https://github.com/regen-network/regen-ledger/tree/f2def5cf4e33c85aa4f336bc3430914d9bed791b/proto/regen/ecocredit/v1alpha2/tx.proto#L92-L105
## Ecocredit Core

### Validation:
- [CreateClass](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#CreateClass)
- [CreateProject](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#CreateProject)
- [CreateBatch](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#CreateBatch)
- [Send](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#Send)
- [Retire](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#Retire)
- [Cancel](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#Cancel)

- `admin` must ba a valid address, and their signature must be present in the transaction
- if the `allowlist_enabled` paramater is set to `true`, `admin` must be on the list of approved credit class creators (the `allowed_class_creators` parameter)
- `issuers` must not be empty and all addresses must be valid addresses
- `credit_type` (the name of the credit type) must not be empty and on the list of approved credit types (the `credit_types` parameter)
- `metadata` must be less than or equal to 256 bytes
## Basket Submodule

## MsgCreateProject
- [Create](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.basket.v1#Create)
- [Put](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.basket.v1#Put)
- [Take](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.basket.v1#Take)

`MsgCreateProject` creates a new project with a credit class ID, issuer, project location, and optional metadata. The party signing this transaction must be a valid issuer of the project's credit class.
## Marketplace Submodule

+++ https://github.com/regen-network/regen-ledger/tree/f2def5cf4e33c85aa4f336bc3430914d9bed791b/proto/regen/ecocredit/v1alpha2/tx.proto#L113-L140

### Validation:

- `issuer` must ba a valid address
- `class_id` must be a valid credit class ID
- `project_location` must be a valid location
- `project_id` if provided, must be a valid project ID
- `metadata` must be less than or equal to 256 bytes

## MsgCreateBatch

`MsgCreateBatch` creates a new batch of credits for an existing credit class. This will create a new batch denom with a fixed supply. Issued credits can be distributed to recipients in either tradable or retired form. The message must be signed by an approved issuer of the desired credit class.

The message must specify the receiver of the batch of credits as well as the number of units to issue in this batch and metadata.

In order to support use cases when credits are to be immediately retired upon issuance, for each account to be issued credits, both an amount of tradeable and retired credit units can be specified.

+++ https://github.com/regen-network/regen-ledger/tree/f2def5cf4e33c85aa4f336bc3430914d9bed791b/proto/regen/ecocredit/v1alpha2/tx.proto#L149-L196

### Validation:

- `issuer` must ba a valid address, and their signature must be present in the transaction
- `issuer` must be on the list of approved `issuers` for the given credit class
- `project_id` must be a valid project ID
- `recipient` must ba a valid address
- `tradable_amount` must not be negative
- `retired_amount` must not be negative
- if `retired_amount` is positive, `retirement_location` must be a valid location
- `metadata` must be less than or equal to 256 bytes
- `start_date` must be a valid date
- `end_date` must be a valid date

## MsgSend

`Send` sends tradable credits from one account to another account. Sent credits can either be tradable or retired on receipt.

+++ https://github.com/regen-network/regen-ledger/tree/f2def5cf4e33c85aa4f336bc3430914d9bed791b/proto/regen/ecocredit/v1alpha2/tx.proto#L205-L243

### Validation:

- `sender` must ba a valid address, and their signature must be present in the transaction
- `recipient` must ba a valid address
- `credits` must not be empty
- `batch_denom` must be a valid batch denomination
- `tradable_amount` must not be negative
- `retired_amount` must not be negative
- if `retired_amount` is positive, `retirement_location` must be a valid location

## MsgRetire

`Retire` retires a specified number of credits in the holder's account.

+++ https://github.com/regen-network/regen-ledger/tree/f2def5cf4e33c85aa4f336bc3430914d9bed791b/proto/regen/ecocredit/v1alpha2/tx.proto#L248-L275

### Validation:

- `holder` must ba a valid address, and their signature must be present in the transaction
- `credits` must not be empty
- `batch_denom` must be a valid batch denomination
- `amount` must be positive
- `location` must be a valid location

## MsgCancel

`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.

+++ https://github.com/regen-network/regen-ledger/tree/f2def5cf4e33c85aa4f336bc3430914d9bed791b/proto/regen/ecocredit/v1alpha2/tx.proto#L280-L300

### Validation:

- `holder` must ba a valid address, and their signature must be present in the transaction
- `credits` must not be empty
- `batch_denom` must be a valid batch denomination
- `amount` must be positive

## MsgSell

`Sell` creates one or more sell orders (i.e. sell orders are created in batches).

+++ https://github.com/regen-network/regen-ledger/tree/f2def5cf4e33c85aa4f336bc3430914d9bed791b/proto/regen/ecocredit/v1alpha2/tx.proto#L353-L385

### Validation:

- `owner` must ba a valid address, and their signature must be present in the transaction
- `batch_denom` must be a valid credit batch denom
- `quantity` must be a positive decimal
- `ask_price` must be a positive integer

## MsgUpdateSellOrders

`UpdateSellOrders` updates one or more sell orders (i.e. sell orders are updated in batches).

+++ https://github.com/regen-network/regen-ledger/tree/f2def5cf4e33c85aa4f336bc3430914d9bed791b/proto/regen/ecocredit/v1alpha2/tx.proto#L394-L419

### Validation:

- `owner` must ba a valid address, and their signature must be present in the transaction
- `new_quantity` must be a positive decimal
- `new_ask_price` must be a positive integer

## MsgBuy

`MsgBuy` creates one or more buy orders (i.e. buy orders are created in batches).

+++ https://github.com/regen-network/regen-ledger/tree/f2def5cf4e33c85aa4f336bc3430914d9bed791b/proto/regen/ecocredit/v1alpha2/tx.proto#L424-L483

### Validation:

- `buyer` must ba a valid address, and their signature must be present in the transaction
- `quantity` must be a positive decimal
- `bid_price` must be a positive integer

## MsgAllowAskDenom

`AllowAskDenom` is a governance operation which authorizes a new ask denom to be used in sell orders.

+++ https://github.com/regen-network/regen-ledger/tree/f2def5cf4e33c85aa4f336bc3430914d9bed791b/proto/regen/ecocredit/v1alpha2/tx.proto#L494-L508

### Validation:

- `root_address` must be the address of the governance module
- `denom` must be a valid denom
- [Sell](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#Sell)
- [UpdateSellOrders](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#UpdateSellOrders)
- [Buy](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#Buy)
- [AllowAskDenom](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#AllowAskDenom)
7 changes: 0 additions & 7 deletions x/ecocredit/spec/04_events.md

This file was deleted.

38 changes: 38 additions & 0 deletions x/ecocredit/spec/04_queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Query Service

The ecocredit module provides a query service for querying the state of the ecocredit module. The queries are defined in the proto files available on [Buf Schema Registry](https://buf.build/regen/regen-ledger).

For examples on how to query state using gRPC and REST, see the [ecocredit client](06_client.md) documentation, and for examples using the `regen` binary, see [regen query ecocredit](../../commands/regen_query_ecocredit.html).

## Ecocredit Core

- [Classes](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#Classes)
- [ClassInfo](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#ClassInfo)
- [ClassIssuers](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#ClassIssuers)
- [Projects](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#Projects)
- [ProjectInfo](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#ProjectInfo)
- [Batches](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#Batches)
- [BatchesByClass](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#BatchesByClass)
- [BatchInfo](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#BatchInfo)
- [Balance](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#Balance)
- [Supply](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#Supply)
- [CreditTypes](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#CreditTypes)
- [Params](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.v1#Params)

## Basket Submodule

- [Basket](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.basket.v1#Basket)
- [Baskets](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.basket.v1#Baskets)
- [BasketBalance](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.basket.v1#BasketBalance)
- [BasketBalances](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.basket.v1#BasketBalances)

## Marketplace Submodule

- [SellOrder](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#SellOrder)
- [SellOrders](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#SellOrders)
- [SellOrdersByBatchDenom](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#SellOrdersByBatchDenom)
- [SellOrdersByAddress](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#SellOrdersByAddress)
- [BuyOrder](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#BuyOrder)
- [BuyOrders](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#BuyOrders)
- [BuyOrdersByAddress](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#BuyOrdersByAddress)
- [AllowedDenoms](https://buf.build/regen/regen-ledger/docs/main/regen.ecocredit.marketplace.v1#AllowedDenoms)
Loading

0 comments on commit 0f17d79

Please sign in to comment.