-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update concepts and state * update block * update gov specs * update govs * update messages spec --------- Co-authored-by: GnaD13 <cpt.meoz@gmail.com>
- Loading branch information
Showing
5 changed files
with
65 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,44 @@ | ||
# multi-staking-module | ||
|
||
The multi-staking-module is a module that allows the cosmos-sdk staking system to support many types of token | ||
The multi-staking-module is a module that allows the cosmos-sdk staking system to support many types of coin | ||
|
||
## Features | ||
|
||
- Staking with many diffrent type of tokens | ||
- Staking with many diffrent type of coins | ||
- Bond denom selection via Gov proposal | ||
- A validator can only be delegated using its bonded denom | ||
- All user usecases of the sdk staking module | ||
- A validator can only be delegated using with one type of coin | ||
- All usecases of the sdk staking module | ||
|
||
## Multi staking design | ||
|
||
Given the fact that several core sdk modules such as distribution or slashing is dependent on the sdk staking module, we design the multi staking module as a wrapper around the sdk staking module so that there's no need to replace the sdk staking module and its related modules. | ||
|
||
The mechanism of this module is that it still uses the sdk staking module for all the logic related to staking. But since the sdk staking module doesn't allow multiple bond token/denom, in order to support such feature, the multi-staking module will convert (lock and mint) those different bond token/denom into the one token/denom that is used by the sdk staking module and then stake with the converted token/denom. | ||
The mechanism of this module is that it still uses the sdk staking module for all the logic related to staking. But since the sdk staking module doesn't allow delegate with different types of coin, in order to support such feature, the multi-staking module will convert (lock and mint) those different coin into the one bond coin that is used by the sdk staking module and then stake with the converted bond coin. | ||
|
||
![design](https://hackmd.io/_uploads/B1BduYEh6.png) | ||
|
||
## Concepts and Terms | ||
|
||
### Sdk bond token | ||
### Bond coin | ||
|
||
Bond coin is the only coin that the sdk staking module accepts for delegation. In our design, the bond coin is just a virtual coin used only in the sdk staking layer, serving no other purposes than that. No user accounts are allowed to access to the bond coin. | ||
|
||
Since there're many bond denom/token stake-able via the multi-staking module but only one denom/token used by the underlying sdk staking module, let's refer to the former as `bond token/denom` and the latter as `sdkbond token/denom`. | ||
### Multistaking coin | ||
|
||
### Delegation | ||
Multistaking coin refers to the instance of coin that is used to delegate via the multi-staking module. | ||
|
||
Each delegation from a `delegator A` is actually reprensented in the form of a `sdk delegation` which refers to the delegation happened at the sdk staking module layer. In other words, there's little to no logic related to the actual delegation system (validator power distr, slashing, distributing rewards...) happens at the `multi-staking module` layer as well as delegation data being stored at `multi-staking module` store. | ||
It is represented by this [struct](../types/multi_staking.pb.go), which is almost identical to the bank coin, except that it has an additional field called `bond weight`. | ||
|
||
### Intermediary Account | ||
### Bond Weight | ||
|
||
For each delegation from a `delegator A`, the underlying `sdk delegation` will be created and managed DIRECTLY by an unique `intermediary account C` instead of the `delegator A`, meaning that the `sdk delegation` will have the `intermediary account` as its delegator. The `delegator A` though, via messages of the multi-staking module can still dictate what `intermediary account C` on what to do with the `sdk delegation` so that `delegator A` still have full controll over the delegation. However, delegators aren't actually aware of the `intermediary account`. All logic related to `intermediary acocunt` is considered internal logic of the module and thus concealed from `delegator`. | ||
Each `multistaking coin` instance is associated with a `bond weight`. The `bond weight` value shows the conversion ratio to `bond coin` of that `multistaking coin` instance. It's different than the `bond weight` value set by government prop which specifies the current global `bond weight` value of that type of coin rather than `bond weight` value for a specific instance of `multistaking coin`. | ||
|
||
The `intermediary account` is also where the `bond token` from `delegator` is locked and the `sdkbond token` is minted to, the minted `sdkbond token` will then be used to create the `sdk delegation`. | ||
We mentioned above that for each delegation the multi-staking will lock the `multistaking coin` and mint a calculated ammount of `bond token`. The calculation here is a multiplication: minted bond token ammount = multistaking coin amount * bond weight. | ||
|
||
### Bond Token Weight | ||
### Multistaking lock | ||
|
||
Each `bond token` is associated with a `bond token weight`. This `bond token weight` is specified via the gov proposal in which the `bond token` is accepted. | ||
`MultistakingLock` is used to keep tracks of the multi-staking coin that is locked for each delegation. `MultistakingLock` contains `LockID` refering to delegation ID (delegator, validator) of the corresponding delegation, and `MultistakingCoin` refering to the instance of `multistaking coin` that is locked. | ||
|
||
We mentioned above that for each delegation the multi-staking will lock the `bond token` and mint a calculated ammount of `sdkbond token`. The calculation here is a multiplication : minted sdkbond token ammount = bond token amount * bond token weight. | ||
### Multistaking unlock | ||
|
||
`MultistakingUnlock` is used to keep tracks of the multi-staking coin that is unlocking for each unbonding delegation. `MultistakingUnLock` contains `UnLockID` refering to unbonding delegation ID (delegator, validator) of the corresponding unbonding delegation, and `Entries` refering to the instances of `multistaking coin` that is unlocking. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
# Begin-Block | ||
# End-Block | ||
|
||
## Complete Unbonding Delegations | ||
|
||
Check if there's any completed unbonding delegations. | ||
If so, for each of the unbonding delegation: | ||
### Calculate total `UnbondedAmount` | ||
|
||
* Get the `delegator account` from `IntermediaryDelegator` store. | ||
* Retrieve `matureUnbondingDelegations` which is the array of all `UnbondingDelegations` that complete in this block | ||
|
||
* Update `CompletedDelegations`. | ||
### Staking module EndBlock | ||
|
||
# End-Block | ||
* Call `Staking` module `EndBlock` to `CompleteUnbonding` | ||
|
||
## Complete Unbonding Delegations | ||
### MultiStaking module EndBlock | ||
|
||
* Iterate over `matureUnbondingDelegations` which was retrieve above | ||
|
||
Check if there's any entries in `CompletedDelegations`. | ||
If so, for each entry: | ||
* For each iteration, we will: | ||
|
||
* Calculate the amount of `bond token` to be unlocked. | ||
* Calculate amount of `unlockedCoin` that will be return to user by multiply the amount of `unbonded coin` and `bonded weight` | ||
|
||
* Send the calculated amount of `bond token` from `IntermediaryAccount` to `delegator` | ||
* Burn the `remainingCoin` that remain on the `Lock` after send `unlockedCoin` to user | ||
|
||
* Update `DVPairSDKBondCoins`. | ||
* Delete `UnlockEntry`. | ||
|
||
* Delete the entry in `CompletetedDelegations`. | ||