Initia — Technical Analysis of Initia’s mstaking Module

BlueStake
7 min readJun 14, 2024

--

The Initia blockchain introduces a sophisticated staking module known as mstaking, which offers several innovative features compared to the traditional staking mechanisms found in the Cosmos SDK.

This article explores the technical aspects of Initia's staking module, highlighting its unique functionalities and innovations.

Disclaimer: The information contained in this article and the resources available do not constitute financial advice and should not be construed as such.

What is Initia?

Initia redefines the multi-chain network experience by seamlessly integrating architecture, product, and economic systems. It offers a comprehensive blockchain solution that enhances how networks operate and interact, making it a prime example of a network designed for interwoven rollups.

Initia integrates a foundational Layer 1 blockchain with a bespoke Layer 2 infrastructure, creating a cohesive ecosystem of modular networks. This setup enables secure scaling through the OPinit Stack, which supports various virtual machines (VMs) like EVM, MoveVM, and WasmVM. The integration of these VMs allows for diverse smart contract deployments, ensuring flexibility and adaptability across different blockchain applications.

The key advantages of Initia include enhanced scalability, interoperability, and economic alignment among users, developers, and application-specific chains. By harmonizing the economic interests of different stakeholders within the blockchain ecosystem, Initia fosters a collaborative and efficient network environment.

Initia’s ecosystem includes several innovative products designed to streamline user interaction and reduce entry barriers. These products include InitiaScan, a multi-chain explorer with VM-specific tools and information; Initia App, a centralized platform for all things related to Initia; Initia Usernames, a blockchain-wide on-chain identity system; and Initia Wallet, a dedicated wallet designed for navigating the expansive Initia ecosystem.

By offering these integrated solutions, Initia enhances the overall blockchain experience, making it more user-friendly and efficient for both developers and end-users. For more detailed information, you can explore their GitHub repository and official documentation.

Overview of Initia’s mstaking Module

Initia’s mstaking module is designed to provide a robust, scalable, and user-friendly staking experience. It integrates closely with Initia's economic and governance systems to ensure optimal security and efficiency. Key innovations include enhanced staking rewards, integrated liquidity mechanisms, and a modular design that supports various virtual machines (VMs).

Key Features

1. Enhanced Staking Rewards:

  • Inflation-Controlled Rewards: Rewards for staking are generated through a controlled inflation mechanism, ensuring sustainable token distribution.
  • Transaction Fees: Validators earn transaction fees in addition to inflation rewards, providing a comprehensive incentive model.

2. Integrated Liquidity Mechanisms:

  • Enshrined Liquidity: Direct integration with liquidity pools, enabling stakers to earn additional rewards through liquidity provision. This involves staking INIT tokens or whitelisted INIT-X LP tokens from InitiaDEX, combining staking rewards with swap fees and yield from LP tokens.
  • InitiaDEX Integration: Seamless trading and liquidity management through Initia’s decentralized exchange.
  • Diversified Security: By allowing staking of LP tokens, the network reduces reliance on the volatility of solo INIT, thereby enhancing overall network security.

3. Modular and VM-Agnostic Design:

  • Support for Multiple VMs: Compatibility with MoveVM, EVM, and WasmVM, allowing for diverse smart contract deployments.
  • Optimistic Rollups: Enhanced scalability and efficiency for Layer 2 applications through the OPinit Stack.

Technical Implementation

The following sections provide a deeper look into the technical implementation of the mstaking module, with specific focus on voting power calculation and reward distribution.

Voting Power Calculation

The voting power of validators is a critical component of the staking module, ensuring that those with a higher stake have a proportional influence on the network.

func CalculateVotingPower(tokens sdk.Coins, weights sdk.DecCoins) (math.Int, sdk.Coins) {
totalVotingPower := math.ZeroInt()
votingPowers := make(sdk.Coins, 0, len(weights))
for _, weight := range weights {
votingPower := weight.Amount.MulInt(tokens.AmountOf(weight.Denom)).TruncateInt()

if votingPower.IsPositive() {
votingPowers = append(votingPowers, sdk.NewCoin(weight.Denom, votingPower))
totalVotingPower = totalVotingPower.Add(votingPower)
}
}

return totalVotingPower, votingPowers
}

Whitelisting and Reward Weights

LP tokens must be whitelisted through Initia L1 governance to be eligible for staking rewards. The process involves a whitelist proposal, including the LP token's reward_weight. This ensures that only approved tokens participate in the staking process, maintaining network security and integrity.

Inflation-Controlled Rewards
Inflation is a primary mechanism for generating staking rewards. On Initia, rewards are distributed based on an inflation schedule, with each whitelisted LP token assigned a reward_weight.

The inflation rate determines the total number of new tokens created, which are then distributed to stakers based on their proportional reward_weight. This inflation rate can be adjusted via governance proposals, ensuring flexibility and adaptability.

// AllocateTokens handles distribution of the collected fees
// bondedVotes is a list of (validator address, validator voted on last block flag) for all
// validators in the bonded set.
func (k Keeper) AllocateTokens(ctx context.Context, totalPreviousPower int64, bondedVotes []abci.VoteInfo) error {
...

rewardWeights, rewardWeightMap, weightsSum := k.LoadRewardWeights(ctx, params)
validators, bondedTokens, bondedTokensSum, err := k.LoadBondedTokens(ctx, bondedVotes, rewardWeightMap)
if err != nil {
return err
}

// allocate rewards proportionally to reward power
for _, rewardWeight := range rewardWeights {
poolFraction := rewardWeight.Weight.Quo(weightsSum)
poolReward := feesCollected.MulDecTruncate(voteMultiplier).MulDecTruncate(poolFraction)

poolDenom := rewardWeight.Denom
poolSize := bondedTokensSum[poolDenom]

for _, bondedTokens := range bondedTokens[poolDenom] {
validator := validators[bondedTokens.ValAddr]

amountFraction := math.LegacyNewDecFromInt(bondedTokens.Amount).QuoInt(poolSize)
reward := poolReward.MulDecTruncate(amountFraction)

err = k.AllocateTokensToValidatorPool(ctx, validator, poolDenom, reward)
if err != nil {
return err
}

remaining = remaining.Sub(reward)
}
}

// allocate community funding
feePool.CommunityPool = feePool.CommunityPool.Add(remaining...)
return k.FeePool.Set(ctx, feePool)
}

Governance and Security Integration

Initia’s staking module integrates closely with its governance system, enabling dynamic adjustments and maintaining network security through community participation.

// Tally iterates over the votes and updates the tally of a proposal based on the voting power of the
// voters
func (keeper Keeper) Tally(ctx context.Context, params customtypes.Params, proposal customtypes.Proposal) (quorumReached, passed bool, burnDeposits bool, tallyResults v1.TallyResult, err error) {
weights, err := keeper.sk.GetVotingPowerWeights(ctx)
if err != nil {
return false, false, false, tallyResults, err
}

results := make(map[v1.VoteOption]math.LegacyDec)
...

// fetch all the bonded validators, insert them into currValidators
err = keeper.sk.IterateBondedValidatorsByPower(ctx, func(validator stakingtypes.ValidatorI) (stop bool, err error) {
valAddr, err := keeper.sk.ValidatorAddressCodec().StringToBytes(validator.GetOperator())
...

votingPower, _ := stakingtypes.CalculateVotingPower(validator.GetBondedTokens(), weights)
stakedVotingPower = stakedVotingPower.Add(votingPower)

return false, nil
})
...

err = keeper.Votes.Walk(ctx, rng, func(key collections.Pair[uint64, sdk.AccAddress], vote v1.Vote) (bool, error) {
...

valAddrStr := sdk.ValAddress(voter.Bytes()).String()
if val, ok := currValidators[valAddrStr]; ok {
val.Vote = vote.Options
currValidators[valAddrStr] = val
}

// iterate over all delegations from voter, deduct from any delegated-to validators
err = keeper.sk.IterateDelegations(ctx, voter, func(delegation stakingtypes.DelegationI) (stop bool, err error) {
valAddrStr := delegation.GetValidatorAddr()

if val, ok := currValidators[valAddrStr]; ok {
// There is no need to handle the special case that validator address equal to voter address.
// Because voter's voting power will tally again even if there will deduct voter's voting power from validator.
val.DelegatorDeductions = val.DelegatorDeductions.Add(delegation.GetShares()...)
currValidators[valAddrStr] = val

// votingPower = delegation shares * bonded / total shares * denom weight
votingPower := math.LegacyZeroDec()
for _, share := range delegation.GetShares() {
votingPower = votingPower.Add(
share.Amount.
MulInt(val.BondedTokens.AmountOf(share.Denom)).
Quo(val.DelegatorShares.AmountOf(share.Denom)).
Mul(weights.AmountOf(share.Denom)),
)
}

for _, option := range vote.Options {
subPower := votingPower.Mul(math.LegacyMustNewDecFromStr(option.Weight))
results[option.Option] = results[option.Option].Add(subPower)
}
totalVotingPower = totalVotingPower.Add(votingPower)
}

return false, nil
})
...

return false, keeper.Votes.Remove(ctx, collections.Join(vote.ProposalId, voter))
})
if err != nil {
return false, false, false, tallyResults, err
}

// iterate over the validators again to tally their voting power
for _, val := range currValidators {
...

sharesAfterDeductions := val.DelegatorShares.Sub(val.DelegatorDeductions)
votingPower := math.LegacyZeroDec()
for _, share := range sharesAfterDeductions {
votingPower = votingPower.Add(
share.Amount.
MulInt(val.BondedTokens.AmountOf(share.Denom)).
Quo(val.DelegatorShares.AmountOf(share.Denom)).
Mul(weights.AmountOf(share.Denom)),
)
}

for _, option := range val.Vote {
subPower := votingPower.Mul(math.LegacyMustNewDecFromStr(option.Weight))
results[option.Option] = results[option.Option].Add(subPower)
}
totalVotingPower = totalVotingPower.Add(votingPower)
}

...

if results[v1.OptionYes].Quo(totalVotingPower.Sub(results[v1.OptionAbstain])).GT(threshold) {
return true, true, false, tallyResults, nil
}

// If more than 1/2 of non-abstaining voters vote No, proposal fails
return true, false, false, tallyResults, nil
}

Liquidity Integration with InitiaDEX

InitiaDEX allows for seamless integration of staking and liquidity provision, enabling stakers to earn additional rewards through a combination of staking yields and liquidity pool (LP) fees.

Users can stake either INIT tokens or whitelisted INIT-X LP tokens, enhancing network security by reducing reliance on the volatility of solo INIT tokens.

The process involves several steps:

  1. Adding Liquidity: Users can add liquidity to InitiaDEX by depositing tokens into liquidity pools. This action mints LP tokens, which represent a share of the pool and can be staked for additional rewards.
  2. Staking LP Tokens: Once liquidity is added, the LP tokens can be staked through the mstaking module. These tokens must be whitelisted via a governance proposal to be eligible for staking rewards. This ensures only approved tokens contribute to network security and liquidity.
  3. Calculating and Claiming Rewards: Stakers earn rewards based on their proportional share of the staked LP tokens. Rewards are calculated using the inflation rate and the reward_weight assigned to each whitelisted LP token. These rewards are distributed periodically, and users can claim them through InitiaDEX.
  4. Enhanced Security: By incorporating LP tokens into the staking mechanism, InitiaDEX diversifies the assets contributing to network security, reducing dependency on the volatility of INIT tokens alone. This multi-asset staking approach strengthens the overall stability and security of the Initia blockchain.

The integration of staking with liquidity provision not only boosts rewards for participants but also enhances the liquidity and security of the network, making InitiaDEX a vital component of the Initia ecosystem.

Conclusion

Initia’s mstaking module represents a significant advancement over traditional staking mechanisms found in the Cosmos SDK. By incorporating inflation-controlled rewards, governance integration, and enhanced liquidity mechanisms, Initia provides a comprehensive and flexible staking experience. The support for multiple VMs and the innovative use of optimistic rollups further position Initia as a leading blockchain platform in the evolving multi-chain ecosystem.

For more detailed information, you can refer to the Initia GitHub repository​.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

BlueStake
BlueStake

Written by BlueStake

Enterprise-grade validator. Highly secure and reliable infrastructure, distributed across various datacenters and monitored 24/7.

No responses yet

Write a response