Skip to content

Commit

Permalink
Merge branch 'main' into taztingo/1498-ibc-rate-limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Witkowski committed Nov 7, 2023
2 parents 858d429 + 4aabad2 commit aff5d86
Show file tree
Hide file tree
Showing 13 changed files with 1,622 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

- Bump `bufbuild/buf-setup-action` from 1.27.1 to 1.27.2 ([#1724](https://github.com/provenance-io/provenance/pull/1724))
- Bump `github.com/google/uuid` from 1.3.1 to 1.4.0 ([#1723](https://github.com/provenance-io/provenance/pull/1723))
- Bump `golang.org/x/text` from 0.13.0 to 0.14.0 ([#1735](https://github.com/provenance-io/provenance/pull/1735))

---

Expand Down Expand Up @@ -1285,4 +1286,4 @@ into new 0.40.x base. Minimal unit test coverage and features in place to begin

The Provenance Blockchain was started by Figure Technologies in 2018 using a Hyperledger Fabric derived private network.
A subsequent migration was made to a new internal private network based on the 0.38-0.39 series of Cosmos SDK and
Tendermint. The Provence-IO/Provenance Cosmos SDK derived public network is the
Tendermint. The Provence-IO/Provenance Cosmos SDK derived public network is the
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/tendermint/tendermint v0.34.28
github.com/tendermint/tm-db v0.6.7
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/text v0.13.0
golang.org/x/text v0.14.0
google.golang.org/genproto/googleapis/api v0.0.0-20231009173412-8bfb1ae86b6c
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1495,8 +1495,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
336 changes: 336 additions & 0 deletions x/exchange/spec/01_concepts.md

Large diffs are not rendered by default.

283 changes: 283 additions & 0 deletions x/exchange/spec/02_state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
# Exchange State

The Exchange module manages several things in state.

Big-endian ordering is used for all conversions between numbers and byte arrays.

---
<!-- TOC -->
- [Params](#params)
- [Default Split](#default-split)
- [Specific Denom Split](#specific-denom-split)
- [Markets](#markets)
- [Market Create-Ask Flat Fee](#market-create-ask-flat-fee)
- [Market Create-Bid Flat Fee](#market-create-bid-flat-fee)
- [Market Seller Settlement Flat Fee](#market-seller-settlement-flat-fee)
- [Market Seller Settlement Ratio Fee](#market-seller-settlement-ratio-fee)
- [Market Buyer Settlement Flat Fee](#market-buyer-settlement-flat-fee)
- [Market Buyer Settlement Ratio Fee](#market-buyer-settlement-ratio-fee)
- [Market Inactive Indicator](#market-inactive-indicator)
- [Market User-Settle Indicator](#market-user-settle-indicator)
- [Market Permissions](#market-permissions)
- [Market Create-Ask Required Attributes](#market-create-ask-required-attributes)
- [Market Create-Bid Required Attributes](#market-create-bid-required-attributes)
- [Market Account](#market-account)
- [Market Details](#market-details)
- [Known Market ID](#known-market-id)
- [Last Market ID](#last-market-id)
- [Orders](#orders)
- [Ask Orders](#ask-orders)
- [Bid Orders](#bid-orders)
- [Last Order ID](#last-order-id)
- [Indexes](#indexes)
- [Market to Order](#market-to-order)
- [Owner Address to Order](#owner-address-to-order)
- [Asset Denom to Order](#asset-denom-to-order)
- [Market External ID to Order](#market-external-id-to-order)


## Params

All params entries start with the type byte `0x00` followed by a string identifying the entry type.

Each `<split>` is stored as a `uint16` (2 bytes) in big-endian order.

The byte `0x1E` is used in a few places as a record separator.

See also: [Params](06_params.md#params).


### Default Split

The default split defines the split amount (in basis points) the exchange receives of fees when there is not an applicable specific denom split.

* Key:`0x00 | "split" (5 bytes)`
* Value: `<split (2 bytes)>`


### Specific Denom Split

A specific denom split is a split amount (in basis points) the exchange receives of fees for fees paid in a specific denom.

* Key: `0x00 | "split" (5 bytes) | <denom (string)>`
* Value: `<split (2 bytes)>`

See also: [DenomSplit](06_params.md#denomsplit).


## Markets

Each aspect of a market is stored separately for specific lookup.

Each `<market id>` is a `uint32` (4 bytes) in big-endian order.

Most aspects of a market have keys that start with the type byte `0x01`, followed by the `<market id>` then another type byte.

See also: [Market](03_messages.md#market).


### Market Create-Ask Flat Fee

One entry per configured denom.

* Key: `0x01 | <market id (4 bytes)> | 0x00 | <denom (string)>`
* Value: `<amount (string)>`


### Market Create-Bid Flat Fee

One entry per configured denom.

* Key: `0x01 | <market id (4 bytes)> | 0x01 | <denom (string)>`
* Value: `<amount (string)>`


### Market Seller Settlement Flat Fee

One entry per configured denom.

* Key: `0x01 | <market id (4 bytes)> | 0x02 | <denom (string)>`
* Value: `<amount (string)>`


### Market Seller Settlement Ratio Fee

One entry per configured price:fee denom pair.

* Key: `0x01 | <market id (4 bytes)> | 0x03 | <price denom (string)> | 0x1E | <fee denom (string)>`
* Value: `<price amount (string)> | 0x1E | <fee amount (string)>`

See also: [FeeRatio](03_messages.md#feeratio).


### Market Buyer Settlement Flat Fee

One entry per configured denom.

* Key: `0x01 | <market id (4 bytes)> | 0x04 | <denom (string)>`
* Value: `<amount (string)>`


### Market Buyer Settlement Ratio Fee

One entry per configured price:fee denom pair.

* Key: `0x01 | <market id (4 bytes)> | 0x05 | <price denom (string)> | 0x1E | <fee denom (string)>`
* Value: `<price amount (string)> | 0x1E | <fee amount (string)>`

See also: [FeeRatio](03_messages.md#feeratio).


### Market Inactive Indicator

When a market has `accepting_orders = false`, this state entry will exist.
When it has `accepting_orders = true`, this entry will not exist.

* Key: `0x01 | <market id (4 bytes)> | 0x06`
* Value: `<nil (0 bytes)>`


### Market User-Settle Indicator

When a market has `allow_user_settlement = true`, this state entry will exist.
When it has `allow_user_settlement = false`, this entry will not exist.

* Key: `0x01 | <market id (4 bytes)> | 0x07`
* Value: `<nil (0 bytes)>`


### Market Permissions

When an address has a given permission in a market, the following entry will exist.

* Key: `0x01 | <market id (4 bytes)> | 0x08 | <addr len (1 byte)> | <addr> | <permission type byte (1 byte)>`
* Value: `<nil (0 bytes)>`

The `<permission type byte>` is a single byte as `uint8` with the same values as the enum entries, e.g. `PERMISSION_CANCEL` is `0x03`.

See also: [AccessGrant](03_messages.md#accessgrant) and [Permission](03_messages.md#permission).


### Market Create-Ask Required Attributes

* Key: `0x01 | <market id (4 bytes)> | 0x09 | 0x00`
* Value: `<list of strings separated by 0x1E>`


### Market Create-Bid Required Attributes

* Key: `0x01 | <market id (4 bytes)> | 0x09 | 0x01`
* Value: `<list of strings separated by 0x1E>`


### Market Account

Each market has an associated `MarketAccount` with an address derived from the `market_id`.
Each `MarketAccount` is stored using the `Accounts` module.

+++ https://github.com/provenance-io/provenance/blob/v1.17.0/proto/provenance/exchange/v1/market.proto#L14-L26


### Market Details

The [MarketDetails](03_messages.md#marketdetails) are stored as part of the `MarketAccount` (in the `x/auth` module).


### Known Market ID

These entries are used to indicate that a given market exists.

* Key: `0x07 | <market id (4 bytes)>`
* Value: `<nil (0 bytes)>`


### Last Market ID

This indicates the last market-id that was auto-selected for use.

When a `MsgGovCreateMarketRequest` is processed that has a `market_id` of `0` (zero), the next available market id is auto selected.
Starting with the number after what's in this state entry, each market id is sequentially checked until an available one is found.
The new market gets that id, then this entry is then updated to indicate what that was.

* Key: `0x06`
* Value: `<market id (4 bytes)>`

When a `MsgGovCreateMarketRequest` is processed that has a non-zero `market_id`, this entry is not considered or altered.


## Orders

Each `<order id>` is a `uint64` (8 bytes) in big-endian order.

Orders are stored using the following format:

* Key: `0x02 | <order id (8 bytes)>`
* Value `<order type byte> | protobuf(order type)`

The `<order type byte>` has these possible values:
* `0x00` => Ask Order
* `0x01` => Bid Order


### Ask Orders

* Key: `0x02 | <order id (8 bytes)>`
* Value: `0x00 | protobuf(AskOrder)`

See also: [AskOrder](03_messages.md#askorder).


### Bid Orders

* Key: `0x02 | <order id (8 bytes)>`
* Value: `0x01 | protobuf(BidOrder)`

See also: [BidOrder](03_messages.md#bidorder).


### Last Order ID

Whenever an order is created, this value is looked up and incremented to get the new order's id.
Then this entry is updated to reflect the new order.

* Key: `0x08`
* Value: `<order id (8 bytes)>`


## Indexes

Several index entries are maintained to help facilitate look-ups.

The `<order type byte>` values are the same as those described in [Orders](#orders).


### Market to Order

This index can be used to find orders in a given market.

* Key: `0x03 | <market id (4 bytes)> | <order id (8 bytes)>`
* Value: `<order type byte (1 byte)>`


### Owner Address to Order

This index can be used to find orders with a given buyer or seller.

* Key: `0x04 | <addr len (1 byte)> | <addr> | <order id (8 bytes)>`
* Value: `<order type byte (1 byte)>`


### Asset Denom to Order

This index can be used to find orders involving a given `assets` denom.

* Key: `0x05 | <asset denom> | <order id (8 bytes)>`
* Value: `<order type byte (1 byte)>`


### Market External ID to Order

This index is used to look up orders by their market and external id.

* Key: `0x09 | <market id (4 bytes)> | <external id (string)>`
* Value: `<order id (8 bytes)>`
Loading

0 comments on commit aff5d86

Please sign in to comment.