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

v19 superfluid fix #6190

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### State Breaking

### Bug Fixes
* [#6190](https://github.com/osmosis-labs/osmosis/pull/6190) v19 upgrade handler superfluid fix

### Misc Improvements

### Minor improvements & Bug Fixes

### Security

## v18.0.0

### Misc Improvements
Expand Down
4 changes: 2 additions & 2 deletions app/upgrades/v19/constants.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v18
package v19

import (
"github.com/osmosis-labs/osmosis/v19/app/upgrades"
Expand All @@ -7,7 +7,7 @@ import (
)

// UpgradeName defines the on-chain upgrade name for the Osmosis v18 upgrade.
const UpgradeName = "v18"
const UpgradeName = "v19"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
Expand Down
8 changes: 5 additions & 3 deletions app/upgrades/v19/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package v18
package v19

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

gammtypes "github.com/osmosis-labs/osmosis/v19/x/gamm/types"

"github.com/osmosis-labs/osmosis/v19/app/keepers"
"github.com/osmosis-labs/osmosis/v19/app/upgrades"
)
Expand Down Expand Up @@ -34,6 +36,6 @@ func CreateUpgradeHandler(
}

func resetSuperfluidSumtree(keepers *keepers.AppKeepers, ctx sdk.Context, id uint64) {
// denom := gammtypes.GetPoolShareDenom(id)
// keepers.LockupKeeper.RebuildAccumulationStoreForDenom(ctx, denom)
denom := gammtypes.GetPoolShareDenom(id)
keepers.LockupKeeper.RebuildSuperfluidAccumulationStoresForDenom(ctx, denom)
}
32 changes: 32 additions & 0 deletions x/lockup/keeper/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,38 @@ func (k Keeper) RebuildAccumulationStoreForDenom(ctx sdk.Context, denom string)
k.writeDurationValuesToAccumTree(ctx, denom, mapDurationToAmount)
}

func (k Keeper) RebuildSuperfluidAccumulationStoresForDenom(ctx sdk.Context, denom string) {
superfluidPrefix := denom + "/super"
superfluidStorePrefix := accumulationStorePrefix(superfluidPrefix)
k.clearKeysByPrefix(ctx, superfluidStorePrefix)

accumulationStoreEntries := make(map[string]map[time.Duration]sdk.Int)
locks := k.GetLocksDenom(ctx, denom)
for _, lock := range locks {
synthLock, found, err := k.GetSyntheticLockupByUnderlyingLockId(ctx, lock.ID)
if err != nil || !found {
continue
}

var curDurationMap map[time.Duration]sdk.Int
if durationMap, ok := accumulationStoreEntries[synthLock.SynthDenom]; ok {
curDurationMap = durationMap
} else {
curDurationMap = make(map[time.Duration]sdk.Int)
}
newAmt := lock.Coins.AmountOf(denom)
if curAmt, ok := curDurationMap[synthLock.Duration]; ok {
newAmt = newAmt.Add(curAmt)
}
curDurationMap[synthLock.Duration] = newAmt
accumulationStoreEntries[synthLock.SynthDenom] = curDurationMap
}

for synthDenom, durationMap := range accumulationStoreEntries {
k.writeDurationValuesToAccumTree(ctx, synthDenom, durationMap)
}
}

func (k Keeper) ClearAccumulationStores(ctx sdk.Context) {
k.clearKeysByPrefix(ctx, types.KeyPrefixLockAccumulation)
}
Expand Down