Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signaling prop in upgrade #1092

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) {
v18.CreateUpgradeHandler(
app.mm,
app.configurator,
app.StakeibcKeeper,
app.BankKeeper,
app.GovKeeper,
app.RecordsKeeper,
app.StakeibcKeeper,
),
)

Expand Down
12 changes: 11 additions & 1 deletion app/upgrades/v18/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package v18

import sdk "github.com/cosmos/cosmos-sdk/types"
import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)

var (
UpgradeName = "v18"
Expand All @@ -17,6 +20,13 @@ var (
// Terra chain ID for delegation changes in progress
TerraChainId = "phoenix-1"

// Prop 228 info
Strd = "ustrd"
Prop228ProposalId = uint64(228)
Prop228SendAmount = sdkmath.NewInt(9_000_000_000_000)
IncentiveProgramAddress = "stride1tlxk4as9sgpqkh42cfaxqja0mdj6qculqshy0gg3glazmrnx3y8s8gsvqk"
StrideFoundationAddress_F4 = "stride1yz3mp7c2m739nftfrv5r3h6j64aqp95f3degpf"

// Get Initial Redemption Rates for Unbonding Records Migration
RedemptionRatesAtTimeOfProp = map[string]sdk.Dec{
"comdex-1": sdk.MustNewDecFromStr("1.204404927372203376"),
Expand Down
46 changes: 43 additions & 3 deletions app/upgrades/v18/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

recordskeeper "github.com/Stride-Labs/stride/v17/x/records/keeper"
Expand All @@ -20,8 +23,10 @@ import (
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
stakeibcKeeper stakeibckeeper.Keeper,
bankKeeper bankkeeper.Keeper,
govKeeper govkeeper.Keeper,
recordsKeeper recordskeeper.Keeper,
stakeibcKeeper stakeibckeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Starting upgrade v18...")
Expand All @@ -47,6 +52,12 @@ func CreateUpgradeHandler(
return vm, errorsmod.Wrapf(err, "unable to update unbonding records")
}

ctx.Logger().Info(fmt.Sprintf("Checking on prop %d status...", Prop228ProposalId))
if err := ExecuteProp228IfPassed(ctx, bankKeeper, govKeeper); err != nil {
ctx.Logger().Error(fmt.Sprintf("Failed to check on or execute prop %d: %s",
Prop228ProposalId, err.Error()))
}

return mm.RunMigrations(ctx, configurator, vm)
}
}
Expand Down Expand Up @@ -151,9 +162,9 @@ func UpdateUnbondingRecords(
"unable to find host zone with chain-id %s", hostZoneUnbonding.HostZoneId)
}

redemptionRateDuringProp := redemptionRatesAtTimeOfProp[hostZoneUnbonding.HostZoneId]
redemptionRateAtTimeOfProp := redemptionRatesAtTimeOfProp[hostZoneUnbonding.HostZoneId]
redemptionRateDuringUpgrade := hostZone.RedemptionRate
recordRedemptionRate = redemptionRateDuringProp.Add(redemptionRateDuringUpgrade).Quo(sdk.NewDec(2))
recordRedemptionRate = redemptionRateAtTimeOfProp.Add(redemptionRateDuringUpgrade).Quo(sdk.NewDec(2))
}

// now update all userRedemptionRecords by using the redemption rate to set the native token amount
Expand Down Expand Up @@ -182,3 +193,32 @@ func UpdateUnbondingRecords(
}
return nil
}

// Executes the bank send for prop 228 if it passed
func ExecuteProp228IfPassed(ctx sdk.Context, bk bankkeeper.Keeper, gk govkeeper.Keeper) error {
// Grab proposal from gov store
proposal, found := gk.GetProposal(ctx, Prop228ProposalId)
if !found {
return fmt.Errorf("Prop %d not found", Prop228ProposalId)
}

// Check if it passed - if it didn't do nothing
if proposal.Status != govtypes.ProposalStatus_PROPOSAL_STATUS_PASSED {
ctx.Logger().Info(fmt.Sprintf("Prop %d did not pass", Prop228ProposalId))
return nil
}
ctx.Logger().Info(fmt.Sprintf("Prop %d passed - executing corresponding bank send", Prop228ProposalId))

// Transfer from incentive program address to F4
fromAddress, err := sdk.AccAddressFromBech32(IncentiveProgramAddress)
if err != nil {
return errorsmod.Wrap(err, "invalid prop sender address")
}

toAddress, err := sdk.AccAddressFromBech32(StrideFoundationAddress_F4)
if err != nil {
return errorsmod.Wrap(err, "invalid prop recipient address")
}

return bk.SendCoins(ctx, fromAddress, toAddress, sdk.NewCoins(sdk.NewCoin(Strd, Prop228SendAmount)))
}