Skip to content

Commit

Permalink
Develop cosmos v0.50 upgrade LSM (#454)
Browse files Browse the repository at this point in the history
* chore(cicd): update go version and github release action

* feat(smart-account): add first draft authn authenticator for passkeys

* feat(liquidstake): add new liquidstake module, change cosmos-sdk to lsdm version, fix claim eval payment split
  • Loading branch information
Michael-Ixo authored Nov 27, 2024
1 parent a021f96 commit 529158d
Show file tree
Hide file tree
Showing 82 changed files with 20,099 additions and 500 deletions.
33 changes: 28 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,33 @@ linters:

linters-settings:
revive:
ignore-generated-header: true
severity: warning
rules:
- name: function-result-limit
severity: warning
disabled: false
# limits the number of returns to 4
arguments: [4]
- name: unused-parameter
disabled: true
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unreachable-code
- name: redefines-builtin-id

issues:
exclude-rules:
Expand All @@ -64,8 +85,10 @@ issues:
- linters:
- stylecheck
text: "ST1005:" # punctuation in error messages

max-issues-per-linter: 10000
max-same-issues: 10000

# Enables the use of custom exclude directories and files.
exclude-dirs-use-default: true
# Exclude files with the extension ".pb.gw.go"
Expand Down
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"go.lintOnSave": "workspace",
"go.lintTool": "golangci-lint",
"go.lintTool": "revive",
"go.lintFlags": ["--fast"],
"go.formatTool": "goimports",
"go.useLanguageServer": true,
Expand All @@ -22,5 +22,8 @@
"source.organizeImports": "explicit"
}
},
"rust-analyzer.checkOnSave": false
"rust-analyzer.checkOnSave": false,
"yaml.schemas": {
"https://golangci-lint.run/jsonschema/golangci.jsonschema.json": "file:///Users/michael/dev/ixo/ixo-blockchain/.golangci.yml"
}
}
4 changes: 3 additions & 1 deletion app/blocked.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
liquidstaketypes "github.com/ixofoundation/ixo-blockchain/v4/x/liquidstake/types"
)

var (
// Module accounts that are allowed to receive tokens
allowedReceivingModAcc = map[string]bool{
distrtypes.ModuleName: true,
distrtypes.ModuleName: true,
liquidstaketypes.ModuleName: true,
}
)

Expand Down
18 changes: 18 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ import (
epochstypes "github.com/ixofoundation/ixo-blockchain/v4/x/epochs/types"
iidmodulekeeper "github.com/ixofoundation/ixo-blockchain/v4/x/iid/keeper"
iidtypes "github.com/ixofoundation/ixo-blockchain/v4/x/iid/types"
liquidstakekeeper "github.com/ixofoundation/ixo-blockchain/v4/x/liquidstake/keeper"
liquidstaketypes "github.com/ixofoundation/ixo-blockchain/v4/x/liquidstake/types"
mintkeeper "github.com/ixofoundation/ixo-blockchain/v4/x/mint/keeper"
minttypes "github.com/ixofoundation/ixo-blockchain/v4/x/mint/types"
"github.com/ixofoundation/ixo-blockchain/v4/x/smart-account/authenticator"
Expand Down Expand Up @@ -147,6 +149,7 @@ type AppKeepers struct {
AuthenticatorManager *authenticator.AuthenticatorManager
EpochsKeeper *epochskeeper.Keeper
MintKeeper *mintkeeper.Keeper
LiquidStakeKeeper liquidstakekeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -540,6 +543,7 @@ func NewAppKeepers(
authenticator.NewPartitionedAnyOf(appKeepers.AuthenticatorManager),
authenticator.NewPartitionedAllOf(appKeepers.AuthenticatorManager),
authenticator.NewCosmwasmAuthenticator(appKeepers.ContractKeeper, appKeepers.AccountKeeper, appCodec),
authenticator.NewAuthnVerification(appKeepers.AccountKeeper),
})

smartAccountKeeper := smartaccountkeeper.NewKeeper(
Expand All @@ -551,6 +555,18 @@ func NewAppKeepers(
)
appKeepers.SmartAccountKeeper = &smartAccountKeeper

appKeepers.LiquidStakeKeeper = liquidstakekeeper.NewKeeper(
appCodec,
appKeepers.keys[liquidstaketypes.StoreKey],
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.StakingKeeper,
appKeepers.DistrKeeper,
appKeepers.SlashingKeeper,
bApp.MsgServiceRouter(),
govModAddress,
)

// GOV Keeper
// =============================
// Register the proposal types
Expand Down Expand Up @@ -663,6 +679,7 @@ func (appKeepers *AppKeepers) SetupHooks() {
epochstypes.NewMultiEpochHooks(
// insert epoch hooks receivers here
appKeepers.MintKeeper.Hooks(),
appKeepers.LiquidStakeKeeper.Hooks(),
),
)

Expand Down Expand Up @@ -745,5 +762,6 @@ func KVStoreKeys() []string {
claimsmoduletypes.StoreKey,
smartaccounttypes.StoreKey,
epochstypes.StoreKey,
liquidstaketypes.StoreKey,
}
}
2 changes: 2 additions & 0 deletions app/keepers/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
entityclient "github.com/ixofoundation/ixo-blockchain/v4/x/entity/client"
"github.com/ixofoundation/ixo-blockchain/v4/x/epochs"
"github.com/ixofoundation/ixo-blockchain/v4/x/iid"
"github.com/ixofoundation/ixo-blockchain/v4/x/liquidstake"
"github.com/ixofoundation/ixo-blockchain/v4/x/mint"
smartaccount "github.com/ixofoundation/ixo-blockchain/v4/x/smart-account"
"github.com/ixofoundation/ixo-blockchain/v4/x/token"
Expand Down Expand Up @@ -88,4 +89,5 @@ var AppModuleBasics = module.NewBasicManager(
claims.AppModuleBasic{},
smartaccount.AppModuleBasic{},
epochs.AppModuleBasic{},
liquidstake.AppModuleBasic{},
)
7 changes: 7 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import (
epochstypes "github.com/ixofoundation/ixo-blockchain/v4/x/epochs/types"
iidmodule "github.com/ixofoundation/ixo-blockchain/v4/x/iid"
iidtypes "github.com/ixofoundation/ixo-blockchain/v4/x/iid/types"
"github.com/ixofoundation/ixo-blockchain/v4/x/liquidstake"
liquidstaketypes "github.com/ixofoundation/ixo-blockchain/v4/x/liquidstake/types"
"github.com/ixofoundation/ixo-blockchain/v4/x/mint"
minttypes "github.com/ixofoundation/ixo-blockchain/v4/x/mint/types"
smartaccount "github.com/ixofoundation/ixo-blockchain/v4/x/smart-account"
Expand All @@ -90,6 +92,7 @@ var moduleAccountPermissions = map[string][]string{
icatypes.ModuleName: nil,
icqtypes.ModuleName: nil,
wasmtypes.ModuleName: {authtypes.Burner},
liquidstaketypes.ModuleName: {authtypes.Minter, authtypes.Burner},

// Custom ixo module accounts
bondstypes.BondsMintBurnAccount: {authtypes.Minter, authtypes.Burner},
Expand Down Expand Up @@ -142,6 +145,7 @@ func appModules(
claimsmodule.NewAppModule(app.ClaimsKeeper, app.GetSubspace(claimsmoduletypes.ModuleName)),
smartaccount.NewAppModule(*app.SmartAccountKeeper),
epochs.NewAppModule(*app.EpochsKeeper),
liquidstake.NewAppModule(app.LiquidStakeKeeper),
}
}

Expand Down Expand Up @@ -242,6 +246,7 @@ func OrderBeginBlockers() []string {
entitytypes.ModuleName,
tokentypes.ModuleName,
claimsmoduletypes.ModuleName,
liquidstaketypes.ModuleName,
}
}

Expand Down Expand Up @@ -285,6 +290,7 @@ func OrderEndBlockers() []string {
tokentypes.ModuleName,
bondstypes.ModuleName,
claimsmoduletypes.ModuleName,
liquidstaketypes.ModuleName,
}
}

Expand Down Expand Up @@ -334,6 +340,7 @@ func OrderInitGenesis() []string {
tokentypes.ModuleName,
entitytypes.ModuleName,
claimsmoduletypes.ModuleName,
liquidstaketypes.ModuleName,
}
}

Expand Down
67 changes: 62 additions & 5 deletions app/upgrades/v4/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v4

import (
"cosmossdk.io/math"
store "cosmossdk.io/store/types"
circuittypes "cosmossdk.io/x/circuit/types"
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
Expand All @@ -9,27 +10,82 @@ import (
ibchooks "github.com/cosmos/ibc-apps/modules/ibc-hooks/v8/types"
"github.com/ixofoundation/ixo-blockchain/v4/app/upgrades"
epochstypes "github.com/ixofoundation/ixo-blockchain/v4/x/epochs/types"
liquidstaketypes "github.com/ixofoundation/ixo-blockchain/v4/x/liquidstake/types"
minttypes "github.com/ixofoundation/ixo-blockchain/v4/x/mint/types"
smartaccounttypes "github.com/ixofoundation/ixo-blockchain/v4/x/smart-account/types"
)

// UpgradeName defines the on-chain upgrade name for the Ixo v4 upgrade.
// TODO: need details below!!

const (
// UpgradeName defines the on-chain upgrade name for the Ixo v4 upgrade.
UpgradeName = "Dominia"

// BlockMaxBytes is the max bytes for a block, 10mb (current 22020096)
BlockMaxBytes = int64(10000000)
// CONSENSUS PARAMS
// -------------------------------------------------
// BlockMaxBytes is the max bytes for a block, 30mb (current 22020096)
BlockMaxBytes = int64(30000000)
// BlockMaxGas is the max gas allowed in a block (current 200000000)
BlockMaxGas = int64(300000000)
BlockMaxGas = int64(400000000)

// GOV PARAMS
// -------------------------------------------------
// Normal proposal deposit is 10k ixo, make expedited proposal deposit 3x
ExpeditedProposalDeposit = 30000000000
MinInitialDepositRatio = "0.100000000000000000"

// SMART ACCOUNT PARAMS
// -------------------------------------------------
// MaximumUnauthenticatedGas for smart account transactions to verify the fee payer
MaximumUnauthenticatedGas = uint64(250_000)
// IsSmartAccountActive is used for the smart account circuit breaker, smartaccounts are activated for v4
IsSmartAccountActive = false
IsSmartAccountActive = true
// CircuitBreakerController is a DAODAO address, used only to deactivate the smart account module
// https://daodao.zone/dao/osmo1wn58hxkv0869ua7qmz3gvek3sz773l89a778fjqvenl6anwuhgnq6ks7kl/home
CircuitBreakerController = "ixo1kqmtxkggcqa9u34lnr6shy0euvclgatw4f9zz5"
)

var (
// LIQUID STAKE PARAMS
// -------------------------------------------------
// total weights must be 10000
WhitelistedValidators = []liquidstaketypes.WhitelistedValidator{
{
ValidatorAddress: "ixovaloper1n8yrmeatsk74dw0zs95ess9sgzptd6thzncf20",
TargetWeight: math.NewIntFromUint64(5000),
},
{
ValidatorAddress: "ixovaloper1n8yrmeatsk74dw0zs95ess9sgzptd6thzncf20",
TargetWeight: math.NewIntFromUint64(5000),
},
}
// LSMUnstakeFeeRate is the Unstake Fee Rate. (note the fee amount stays as staked amount in proxy account, it is not
// instaked and transferred to the FeeAccountAddress)
LSMUnstakeFeeRate = math.LegacyNewDecWithPrec(3333, 4) // "0.333300000000000000"
// LSMAutocompoundFeeRate is the fee rate for auto redelegating the stake rewards.
LSMAutocompoundFeeRate = math.LegacyNewDecWithPrec(3333, 4) // "0.333300000000000000"
// LSMWhitelistAdminAddress is the address of the whitelist admin, who is allowed to add/remove whitelisted validators,
// pause/unpause the liquid stake module, and set the weighted rewards receivers.
LSMWhitelistAdminAddress = "ixo1kqmtxkggcqa9u34lnr6shy0euvclgatw4f9zz5"
// LSMWeightedRewardsReceivers is the list of weighted rewards receivers who will recieve the staking rewards based
// on their weights.
LSMWeightedRewardsReceivers = []liquidstaketypes.WeightedAddress{}
// LSMFeeAccountAddress is the address of the fee account, which will receive the autocompound fees.
LSMFeeAccountAddress = "ixo1kqmtxkggcqa9u34lnr6shy0euvclgatw4f9zz5"

// STAKING PARAMS
// -------------------------------------------------
// The ValidatorBondFactor dictates the cap on the liquid shares
// for a validator - determined as a multiple to their validator bond
// (e.g. ValidatorBondShares = 1000, BondFactor = 250 -> LiquidSharesCap: 250,000)
// ValidatorBondFactor of -1 indicates that it's disabled
ValidatorBondFactor = math.LegacyNewDecFromInt(math.NewInt(-1))
// GlobalLiquidStakingCap represents a cap on the portion of stake that
// comes from liquid staking providers for a specific validator
ValidatorLiquidStakingCap = math.LegacyOneDec() // 100%
// GlobalLiquidStakingCap represents the percentage cap on
// the portion of a chain's total stake can be liquid
GlobalLiquidStakingCap = math.LegacyOneDec() // 100%
)

var Upgrade = upgrades.Upgrade{
Expand All @@ -41,6 +97,7 @@ var Upgrade = upgrades.Upgrade{
minttypes.StoreKey,
epochstypes.StoreKey,
ibchooks.StoreKey,
liquidstaketypes.StoreKey,
// Add circuittypes as per 0.47 to 0.50 upgrade handler
// https://github.com/cosmos/cosmos-sdk/blob/b7d9d4c8a9b6b8b61716d2023982d29bdc9839a6/simapp/upgrades.go#L21
circuittypes.ModuleName,
Expand Down
65 changes: 65 additions & 0 deletions app/upgrades/v4/lsm_migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package v4

import (
"context"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// keeper contains the staking keeper functions required for the migration
type keeper interface {
GetAllDelegations(ctx context.Context) ([]stakingtypes.Delegation, error)
GetAllValidators(ctx context.Context) ([]stakingtypes.Validator, error)
SetDelegation(ctx context.Context, delegation stakingtypes.Delegation) error
SetValidator(ctx context.Context, validator stakingtypes.Validator) error
RefreshTotalLiquidStaked(ctx context.Context) error
}

// Peforms migration for adding LSM support after v0.45.16-ics, since it was removed in cosmos-sdk-lsm v0.50:
// - Setting each validator's ValidatorBondShares and LiquidShares to 0
// - Setting each delegation's ValidatorBond field to false
// - Calculating the total liquid staked by summing the delegations from ICA accounts
func migrateCosmosLSMModule(ctx sdk.Context, k keeper) error {

ctx.Logger().Info("Staking LSM Migration: Migrating validators")
MigrateValidators(ctx, k)

ctx.Logger().Info("Staking LSM Migration: Migrating delegations")
MigrateDelegations(ctx, k)

// This is not needed
// ctx.Logger().Info("Staking LSM Migration: Migrating UBD entries")
// if err := MigrateUBDEntries(ctx, store, cdc); err != nil {
// return err
// }

ctx.Logger().Info("Staking LSM Migration: Calculating total liquid staked")
return k.RefreshTotalLiquidStaked(ctx)
}

// Set each validator's ValidatorBondShares and LiquidShares to 0
func MigrateValidators(ctx sdk.Context, k keeper) {
validators, err := k.GetAllValidators(ctx)
if err != nil {
panic(err)
}
for _, validator := range validators {
validator.ValidatorBondShares = math.LegacyZeroDec()
validator.LiquidShares = math.LegacyZeroDec()
k.SetValidator(ctx, validator)
}
}

// Set each delegation's ValidatorBond field to false
func MigrateDelegations(ctx sdk.Context, k keeper) {
delegations, err := k.GetAllDelegations(ctx)
if err != nil {
panic(err)
}
for _, delegation := range delegations {
delegation.ValidatorBond = false
k.SetDelegation(ctx, delegation)
}
}
Loading

0 comments on commit 529158d

Please sign in to comment.