Skip to content

Commit

Permalink
v19 superfluid fix (#6190)
Browse files Browse the repository at this point in the history
* Fix v18 handler

* Synth denom

* update changelog

---------

Co-authored-by: devbot-wizard <[email protected]>
  • Loading branch information
ValarDragon and devbot-wizard authored Aug 28, 2023
1 parent 3cfae57 commit 5509514
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
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

0 comments on commit 5509514

Please sign in to comment.