-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from realiotech/add-asset-spec
feat!: Draft asset module spec
- Loading branch information
Showing
11 changed files
with
241 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<!-- | ||
order: 4 | ||
--> | ||
|
||
# Messages | ||
|
||
The asset module exposes the following messages: | ||
|
||
## MessageCreateToken | ||
|
||
```go | ||
type MsgCreateToken struct { | ||
Creator string | ||
Manager string | ||
Name string | ||
Symbol string | ||
Decimal string | ||
ExcludedPrivileges []string | ||
AddNewPrivileges bool | ||
} | ||
``` | ||
|
||
`MessageCreateToken` allows a whitelisted account to create a token with custom configuration. | ||
|
||
## MessageAllocateToken | ||
|
||
```go | ||
type MsgAllocateToken struct { | ||
Manager string | ||
TokenID string | ||
Balances []Balance | ||
VestingBalances []VestingAccount | ||
} | ||
``` | ||
|
||
`MessageAllocateToken` can only be executed by the token manager once after their token is successfully created. It will allocate tokens (either vesting or liquid) to the list of accounts sepecifed in the message. | ||
|
||
## MessageAssignPrivilege | ||
|
||
```go | ||
type MsgAssignPrivilege struct { | ||
Manager string | ||
TokenID string | ||
AssignedTo []string | ||
Privilege string | ||
} | ||
``` | ||
|
||
`MessageAssignPrivilege` allows the token manager to assign a privilege to the chosen addresses. This message will fail if the privilege is in the list of `ExcludedPrivileges` specified when creating the token. | ||
|
||
## MessageUnassignPrivilege | ||
|
||
```go | ||
type MsgUnassignPrivilege struct { | ||
Manager string | ||
TokenID string | ||
UnassignedFrom []string | ||
Privilege string | ||
} | ||
``` | ||
|
||
`MessageUnassignPrivilege` allows the token manager to unassign a privilege from the chosen addresses. | ||
|
||
## MessageDisablePrivilege | ||
|
||
```go | ||
type MsgDisablePrivilege struct { | ||
Manager string | ||
TokenID string | ||
DisabledPrivilege string | ||
} | ||
``` | ||
|
||
`MessageDisablePrivilege` allows the token manager to disable a privilege permanently, it will also unassigns all the accounts with that privilege. | ||
|
||
## MessageExecutePrivilege | ||
|
||
```go | ||
type PrivilegeMsg interface { | ||
NeedPrivilege() string | ||
} | ||
|
||
type MsgExecutePrivilege struct { | ||
Address string | ||
TokenID string | ||
PrivilegeMsg PrivilegeMsg | ||
} | ||
``` | ||
|
||
`PrivilegeMsg` allows privileged accounts to execute logic of its privilege. For that reason, it has different implementations defined by each types of privilege instead of the `Asset Module`. These implementations and the logic to handle them are registered into the module via `RegisterPrivilege` method. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- | ||
order: 5 | ||
--> | ||
|
||
# Gov proposals | ||
|
||
The asset module supports the following types of gov proposals: | ||
|
||
## TokenCreatorWhitelistProposal | ||
|
||
This proposal allows the community to decide on what addresses are allowed to create token via the asset module. | ||
|
||
These types of proposals is implemented as sdk.msg with respective handling methods following `gov.v1beta` standard. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<!-- | ||
order: 6 | ||
--> | ||
|
||
# Logic | ||
|
||
This file describes the core logics in this module. | ||
|
||
## Token creation process | ||
|
||
This process is triggered by `MsgCreateToken`. | ||
|
||
Validation: | ||
|
||
- Check if `Creator` is whitelisted. We only allow some certain accounts to create tokens, these accounts is determined via gov proposal. | ||
- Check if the token with the same denom has already existed. | ||
|
||
Flow: | ||
|
||
1. The denom for the token will be derived from `Creator` and `Symbol` with the format of `asset/{Creator}/{Symbol}` | ||
2. Save the token basic information (name, symbol, decimal and description) in the x/bank metadata store | ||
3. Save the token management info (`Manager`, `ExcludedPrivileges` and `AddNewPrivilege`) in the x/asset store. | ||
|
||
Note that here we prefixed the token denom with the manager address in order to allow many different creators to create token with the same symbol, differentiate their denom by including in their creator. | ||
|
||
## Register a privilege | ||
|
||
To intergrate with the `asset module` Each type of privilege has to implement this interface | ||
|
||
```go | ||
type Privilege interface { | ||
RegisterInterfaces() | ||
MsgHandler() MsgHandler | ||
QueryHandler() QueryHandler | ||
CLI() *cobra.Command | ||
} | ||
|
||
type MsgHandler func(context Context, privMsg PrivilegeMsg) error | ||
|
||
type QueryHandler func(context Context, privQuery PrivilegeQuery) error | ||
``` | ||
|
||
This interface provides all the functionality necessary for a privilege, including a message handler, query handler and cli | ||
|
||
All the `PrivilegeMsg` of a privilege should return the name of that privilege when called `NeedPrivilege()`. A message handler should handle all the `PrivilegeMsg` of that privilege. | ||
|
||
When adding a `Privilege`, we calls `PrivilegeManager.AddPrivilege()` in `app.go` which inturn maps all the `PrivilegeMsg` of that privilege to its `MsgHandler`. This mapping logic will later be used when running a `MsgExecutePrivilege` | ||
|
||
## Flow of MsgExecutePrivilege | ||
|
||
This process is triggered by the `MsgExecutePrivilege`. | ||
|
||
Validation: | ||
|
||
- Checks if the token specified in the msg exists. | ||
- Checks if the privilege is supported. | ||
- Checks if the `Msg.Address` has the corresponding `Privilege` specified by `PrivilegeMsg.NeedPrivilege()` | ||
|
||
Flow: | ||
|
||
- Prepare store for the privilege of the token via `MakePrivilegeStore(privilege name, token denom)`. That store is the only store accessable by the privilege's `MsgHandler`. | ||
- `PrivilegeManager` routes the `PrivilegeMsg` to the its `MsgHandler`. | ||
- `MsgHandler` now handles the `PrivilegeMsg`. |
Oops, something went wrong.