Skip to content

Commit

Permalink
Merge pull request #279 from irisnet/cyl/mt_spec_md
Browse files Browse the repository at this point in the history
update mt spec docs:
  • Loading branch information
zhangyelong authored Mar 11, 2022
2 parents 03a461a + b027030 commit 02b2a81
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 0 deletions.
38 changes: 38 additions & 0 deletions modules/mt/spec/01_state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# State

## MT

MT defines the tokenData of multi token, mainly including ID, owner, and supply. MT can be transferred through `TransferMT`, or you can edit `MetaData` information through `EditMT` transaction. The name of the collection and the id of mt identify the unique assets in the system. The `MT` Interface inherits the MT struct and includes getter functions for the asset data. It also includes a Stringer function in order to print the struct. The interface may change if tokenData is moved to its own module as it might no longer be necessary for the flexibility of an interface.

```go
// MT multi token interface
type MT interface {
GetID() string
GetSupply() uint64
GetData() []byte
}
```

## Collection

As all MTs belong to a specific `Collection`, however, considering the performance issue, we did not store the structure, but used `{denomID}/{tokenID}` as the key to identify each mt ’s own collection, use `{denom}` as the key to store the object array of mt in the current collection, which is convenient for statistics and query. Collection is defined as follows:

```go
// Collection defines a type of collection
type Collection struct {
Denom *Denom `json:"denom"`
Mts []MT `json:"mts"`
}
```

## Balance

Balance is a data structure specifically designed for MT owned by statistical model owners. The ownership of an MT is set initially when an MT is minted and needs to be updated every time there's a transfer or when an MT is burned,defined as follows:

```go
// Balance defines multi token balance for owners
type Balance struct {
MtId string `json:"mt_id"`
Amount uint64 `json:"amount"`
}
```
131 changes: 131 additions & 0 deletions modules/mt/spec/02_messages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Messages

## MsgIssueDenom

This message defines a type of mt, there can be multiple mt of the same type

| **Field** | **Type** | **Description** |
|:-----------------|:---------|:---------------------------------------------------------------------------------------------------------------------------------------|
| Name | `string` | The name of the asset class. |
| Data | `bytes` | data is the app specific metadata of the MT class. Optional | |
| Sender | `string` | The account address of the user sending the MT. By default it is __not__ required that the sender is also the owner of the MT. |

```go
// MsgIssueDenom defines an SDK message for creating a new denom.
type MsgIssueDenom struct {
Name string
Data []byte
Sender string
}
```

## MsgTransferDenom

This message is used by the owner of the MT classification to transfer the ownership of the MT classification to others

| **Field** | **Type** | **Description** |
|:----------|:---------|:----------------------------------------------------------------------------------------|
| ID | `string` | The unique ID of the Denom being transferred. |
| Sender | `string` | The account address of the user sending the Denom. |
| Recipient | `string` | The account address who will receive the Denom as a result of the transfer transaction. |

```go
// MsgTransferDenom defines an SDK message for transferring an denom to recipient.
type MsgTransferDenom struct {
Id string
Sender string
Recipient string
}
```

## MsgMintMT

This message type is used for minting new tokens. If a new `MT` is minted under a new `Denom`, a new `Collection` will also be created, otherwise the `MT` is added to the existing `Collection`. If a new `MT` is minted by a new account, a new `Owner` is created, otherwise the `MT` `ID` is added to the existing `Owner`'s `IDCollection`. By default, anyone can execute this Message type. **It is highly recommended that a custom handler is made to restrict use of this Message type to prevent unintended use.**

| **Field** | **Type** | **Description** |
|:----------|:---------|:-------------------------------------------------------------------------------------------|
| Id | `string` | The unique ID of the MT being minted. |
| DenomId | `string` | The unique ID of the denomination. |
| Amount | `uint64` | The Amount of the MT being minted. |
| Data | `bytes` | The data of the MT. |
| Sender | `string` | The sender of the Message. |
| Recipient | `string` | The recipient of the new MT. |

```go
// MsgMintMT defines an SDK message for creating a new MT.
type MsgMintMT struct {
Id string
DenomId string
Amount uint64
Data []byte
Sender string
Recipient string
}
```

## MsgEditMT

This message type allows the `Data` to be updated. **It is highly recommended that a custom handler is made to restrict use of this Message type to prevent unintended use.**

| **Field** | **Type** | **Description** |
|:----------|:---------|:-----------------------------------------------------------------------------------------------------------------|
| Id | `string` | The unique ID of the MT being edited. |
| DenomId | `string` | The unique ID of the denomination, necessary as multiple denominations are able to be represented on each chain. |
| Data | `bytes` | The data of the MT. |
| Sender | `string` | The creator of the message. |

```go
// MsgEditMT defines an SDK message for editing an MT.
type MsgEditMT struct {
Id string
DenomId string
Data []byte
Sender string
}
```

## MsgTransferMT

This is the most commonly expected MsgType to be supported across chains. While each application specific blockchain will have very different adoption of the `MsgMintMT`, `MsgBurnMT` and `MsgEditMT` it should be expected that most chains support the ability to transfer ownership of the MT asset. The exception to this would be non-transferable MTs that might be attached to reputation or some asset which should not be transferable. It still makes sense for this to be represented as an MT because there are common queries which will remain relevant to the MT type even if non-transferable. This Message will fail if the MT does not exist.

| **Field** | **Type** | **Description** |
|:----------|:---------|:---------------------------------------------------------------------------------------------------------------------------------|
| ID | `string` | The unique ID of the MT being transferred. |
| DenomId | `string` | The unique ID of the denomination, necessary as multiple denominations are able to be represented on each chain. |
| Amount | `uint64` | The Amount of the MT being transferred. |
| Data | `string` | The data of the MT. |
| Sender | `string` | The account address of the user sending the MT. By default it is __not__ required that the sender is also the owner of the MT. |
| Recipient | `string` | The account address who will receive the MT as a result of the transfer transaction. |

```go
// MsgTransferMT defines an SDK message for transferring an MT to recipient.
type MsgTransferMT struct {
Id string
DenomId string
Amount uint64
Sender string
Recipient string
}
```

### MsgBurnMT

This message type is used for burning tokens which destroys.

| **Field** | **Type** | **Description** |
|:----------|:---------|:---------------------------------------------------|
| Id | `string` | The ID of the Token. |
| DenomId | `string` | The Denom ID of the Token. |
| Amount | `uint64` | The Amount of the MT being burning. |
| Sender | `string` | The account address of the user burning the token. |

```go
// MsgBurnMT defines an SDK message for burning an MT.
type MsgBurnMT struct {
Id string
DenomId string
Amount uint64
Sender string
}
```

66 changes: 66 additions & 0 deletions modules/mt/spec/03_events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Events

The mt module emits the following events:

## Handlers

### MsgIssueDenom

| Type | Attribute Key | Attribute Value |
|:------------|:--------------|:-----------------|
| issue_denom | denom_id | {mtDenomID} |
| issue_denom | denom_name | {mtDenomName} |
| issue_denom | owner | {senderAddress} |
| message | module | mt |
| message | sender | {senderAddress} |

### MsgTransferDenom

| Type | Attribute Key | Attribute Value |
|:---------------|:--------------|:-------------------|
| transfer_denom | denom_id | {mtDenomID} |
| transfer_denom | recipient | {recipientAddress} |
| message | module | mt |
| message | sender | {senderAddress} |

### MsgMintMT

| Type | Attribute Key | Attribute Value |
|:---------|:--------------|:-------------------|
| mint_mt | mt_id | {mtID} |
| mint_mt | denom_id | {mtDenomID} |
| mint_mt | amount | {mintAmount} |
| mint_mt | supply | {mtSupply} |
| mint_mt | recipient | {recipientAddress} |
| message | module | mt |
| message | sender | {senderAddress} |

### MsgEditMT

| Type | Attribute Key | Attribute Value |
|:---------|:--------------|:----------------|
| edit_mt | mt_id | {mtID} |
| edit_mt | denom_id | {mtDenomID} |
| message | module | mt |
| message | sender | {senderAddress} |

### MsgTransferMT

| Type | Attribute Key | Attribute Value |
|:-------------|:--------------|:-------------------|
| transfer_mt | mt_id | {mtID} |
| transfer_mt | denom_id | {mtDenomID} |
| transfer_mt | amount | {transferAmount} |
| transfer_mt | recipient | {recipientAddress} |
| message | module | mt |
| message | sender | {senderAddress} |

### MsgBurnMTs

| Type | Attribute Key | Attribute Value |
|:---------|:--------------|:----------------|
| burn_mt | mt_id | {mtID} |
| burn_mt | denom_id | {mtDenomID} |
| burn_mt | amount | {burnAmount} |
| message | module | mt |
| message | sender | {senderAddress} |
3 changes: 3 additions & 0 deletions modules/mt/spec/04_future_improvements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Future Improvements

Inter-Blockchain Communication will need to develop its own Message types that allow MTs to be transferred across chains. Making sure that spec is able to support the MTs created by this module should be easy. What might be more complicated is a transfer that includes optional tokenData so that a receiving chain has the option of parsing and storing it instead of making IBC queries when that data needs to be accessed (assuming that information stays up to date).
31 changes: 31 additions & 0 deletions modules/mt/spec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
order: 0
title: MT Overview
parent:
title: "MT"
-->

# MT Specification

## Overview

A structure that manage multiple token types. A single deployed contract may include any combination of fungible tokens, non-fungible tokens or other configurations (e.g. semi-fungible tokens).

This standard was first developed on Ethereum within the ERC-1155 and the subsequent EIP of the same name.The ERC-1155 standard addressed some of the restrictions of Ethereum regarding storage costs and semi-fungible assets.

## Contents

1. **[State](./01_state.md)**
- [MT](./01_state.md#MT)
- [Collection](./01_state.md#Collection)
- [Balance](./01_state.md#Balance)
1. **[Messages](./02_messages.md)**
- [Issue Denom](./02_messages.md#MsgIssueDenom)
- [Transfer Denom](./02_messages.md#MsgTransferDenom)
- [Mint MT](./02_messages.md#MsgMintMT)
- [Edit MT](./02_messages.md#MsgEditMT)
- [Transfer MT](./02_messages.md#MsgTransferMT)
- [Burn MT](./02_messages.md#MsgBurnMT)
1. **[Events](./03_events.md)**
- [Handlers](03_events.md#Handlers)
1. **[Future Improvements](./04_future_improvements.md)**

0 comments on commit 02b2a81

Please sign in to comment.