-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c9573c
commit 66dfe2d
Showing
9 changed files
with
225 additions
and
202 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 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
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,74 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmos/gaia/v22/x/lsm/types" | ||
) | ||
|
||
// InitGenesis sets lsm information for genesis | ||
func (k Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) { | ||
// | ||
// Set the total liquid staked tokens | ||
k.SetTotalLiquidStakedTokens(ctx, data.TotalLiquidStakedTokens) | ||
|
||
// Set each tokenize share record, as well as the last tokenize share record ID | ||
latestID := uint64(0) | ||
for _, tokenizeShareRecord := range data.TokenizeShareRecords { | ||
if err := k.AddTokenizeShareRecord(ctx, tokenizeShareRecord); err != nil { | ||
panic(err) | ||
} | ||
if tokenizeShareRecord.Id > latestID { | ||
latestID = tokenizeShareRecord.Id | ||
} | ||
} | ||
if data.LastTokenizeShareRecordId < latestID { | ||
panic("Tokenize share record specified with ID greater than the latest ID") | ||
} | ||
k.SetLastTokenizeShareRecordID(ctx, data.LastTokenizeShareRecordId) | ||
|
||
// Set the tokenize shares locks for accounts that have disabled tokenizing shares | ||
// The lock can either be in status LOCKED or LOCK_EXPIRING | ||
// If it is in status LOCK_EXPIRING, the unlocking must also be queued | ||
for _, tokenizeShareLock := range data.TokenizeShareLocks { | ||
address, err := k.authKeeper.AddressCodec().StringToBytes(tokenizeShareLock.Address) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
switch tokenizeShareLock.Status { | ||
case types.TOKENIZE_SHARE_LOCK_STATUS_LOCKED.String(): | ||
k.AddTokenizeSharesLock(ctx, address) | ||
|
||
case types.TOKENIZE_SHARE_LOCK_STATUS_LOCK_EXPIRING.String(): | ||
completionTime := tokenizeShareLock.CompletionTime | ||
|
||
authorizations := k.GetPendingTokenizeShareAuthorizations(ctx, completionTime) | ||
authorizations.Addresses = append(authorizations.Addresses, sdk.AccAddress(address).String()) | ||
|
||
k.SetPendingTokenizeShareAuthorizations(ctx, completionTime, authorizations) | ||
k.SetTokenizeSharesUnlockTime(ctx, address, completionTime) | ||
|
||
default: | ||
panic(fmt.Sprintf("Unsupported tokenize share lock status %s", tokenizeShareLock.Status)) | ||
} | ||
} | ||
} | ||
|
||
func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState { | ||
params, err := k.GetParams(ctx) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return &types.GenesisState{ | ||
Params: params, | ||
TokenizeShareRecords: k.GetAllTokenizeShareRecords(ctx), | ||
LastTokenizeShareRecordId: k.GetLastTokenizeShareRecordID(ctx), | ||
TotalLiquidStakedTokens: k.GetTotalLiquidStakedTokens(ctx), | ||
TokenizeShareLocks: k.GetAllTokenizeSharesLocks(ctx), | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package simulation | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"math/rand" | ||
|
||
sdkmath "cosmossdk.io/math" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
"github.com/cosmos/cosmos-sdk/types/simulation" | ||
|
||
"github.com/cosmos/gaia/v22/x/lsm/types" | ||
) | ||
|
||
// Simulation parameter constants | ||
const ( | ||
ValidatorBondFactor = "validator_bond_factor" | ||
GlobalLiquidStakingCap = "global_liquid_staking_cap" | ||
ValidatorLiquidStakingCap = "validator_liquid_staking_cap" | ||
) | ||
|
||
// getGlobalLiquidStakingCap returns randomized GlobalLiquidStakingCap between 0-1. | ||
func getGlobalLiquidStakingCap(r *rand.Rand) sdkmath.LegacyDec { | ||
return simulation.RandomDecAmount(r, sdkmath.LegacyOneDec()) | ||
} | ||
|
||
// getValidatorLiquidStakingCap returns randomized ValidatorLiquidStakingCap between 0-1. | ||
func getValidatorLiquidStakingCap(r *rand.Rand) sdkmath.LegacyDec { | ||
return simulation.RandomDecAmount(r, sdkmath.LegacyOneDec()) | ||
} | ||
|
||
// getValidatorBondFactor returns randomized ValidatorBondCap between -1 and 300. | ||
func getValidatorBondFactor(r *rand.Rand) sdkmath.LegacyDec { | ||
return sdkmath.LegacyNewDec(int64(simulation.RandIntBetween(r, -1, 300))) | ||
} | ||
|
||
// RandomizedGenState generates a random GenesisState for lsm | ||
func RandomizedGenState(simState *module.SimulationState) { | ||
// params | ||
var ( | ||
validatorBondFactor sdkmath.LegacyDec | ||
globalLiquidStakingCap sdkmath.LegacyDec | ||
validatorLiquidStakingCap sdkmath.LegacyDec | ||
) | ||
|
||
simState.AppParams.GetOrGenerate(ValidatorBondFactor, &validatorBondFactor, simState.Rand, func(r *rand.Rand) { validatorBondFactor = getValidatorBondFactor(r) }) | ||
|
||
simState.AppParams.GetOrGenerate(GlobalLiquidStakingCap, &globalLiquidStakingCap, simState.Rand, func(r *rand.Rand) { globalLiquidStakingCap = getGlobalLiquidStakingCap(r) }) | ||
|
||
simState.AppParams.GetOrGenerate(ValidatorLiquidStakingCap, &validatorLiquidStakingCap, simState.Rand, func(r *rand.Rand) { validatorLiquidStakingCap = getValidatorLiquidStakingCap(r) }) | ||
|
||
params := types.NewParams( | ||
validatorBondFactor, | ||
globalLiquidStakingCap, | ||
validatorLiquidStakingCap, | ||
) | ||
|
||
lsmGenesis := types.NewGenesisState(params, nil, 0, sdkmath.ZeroInt(), nil) | ||
|
||
bz, err := json.MarshalIndent(&lsmGenesis.Params, "", " ") | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Printf("Selected randomly generated lsm parameters:\n%s\n", bz) | ||
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(lsmGenesis) | ||
} |
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,25 @@ | ||
package types | ||
|
||
import "cosmossdk.io/math" | ||
|
||
func NewGenesisState( | ||
params Params, | ||
tsr []TokenizeShareRecord, | ||
recordId uint64, | ||
liquidStakeTokens math.Int, | ||
locks []TokenizeShareLock, | ||
) *GenesisState { | ||
return &GenesisState{ | ||
Params: params, | ||
TokenizeShareRecords: tsr, | ||
LastTokenizeShareRecordId: recordId, | ||
TotalLiquidStakedTokens: liquidStakeTokens, | ||
TokenizeShareLocks: locks, | ||
} | ||
} | ||
|
||
func DefaultGenesisState() *GenesisState { | ||
return &GenesisState{ | ||
Params: DefaultParams(), | ||
} | ||
} |
Oops, something went wrong.