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

refactor(x/superfluid): improve error handling for AddNewSuperfluidAsset #2473

Merged
merged 2 commits into from
Aug 21, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#2227](https://github.com/osmosis-labs/osmosis/pull/2227) Enable charging fee in base denom for `CreateGauge` and `AddToGauge`.
* [#2283](https://github.com/osmosis-labs/osmosis/pull/2283) x/incentives: refactor `CreateGauge` and `AddToGauge` fees to use txfees denom
* [#2206](https://github.com/osmosis-labs/osmosis/pull/2283) Register all Amino interfaces and concrete types on the authz Amino codec. This will allow the authz module to properly serialize and de-serializes instances using Amino.
* [#2473](https://github.com/osmosis-labs/osmosis/pull/2473) x/superfluid `AddNewSuperfluidAsset` now returns error, if any occurs instead of ignoring it.

#### Golang API breaks

Expand Down
4 changes: 3 additions & 1 deletion app/upgrades/v7/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ func CreateUpgradeHandler(
Denom: "gamm/pool/1",
AssetType: superfluidtypes.SuperfluidAssetTypeLPShare,
}
keepers.SuperfluidKeeper.AddNewSuperfluidAsset(ctx, superfluidAsset)
if err := keepers.SuperfluidKeeper.AddNewSuperfluidAsset(ctx, superfluidAsset); err != nil {
return newVM, err
}

// N.B.: This is left for historic reasons.
// After the v7 upgrade, there was no need for this function anymore so it was removed.
Expand Down
4 changes: 3 additions & 1 deletion x/superfluid/keeper/gov/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (

func HandleSetSuperfluidAssetsProposal(ctx sdk.Context, k keeper.Keeper, ek types.EpochKeeper, p *types.SetSuperfluidAssetsProposal) error {
for _, asset := range p.Assets {
k.AddNewSuperfluidAsset(ctx, asset)
if err := k.AddNewSuperfluidAsset(ctx, asset); err != nil {
return err
}
event := sdk.NewEvent(
types.TypeEvtSetSuperfluidAsset,
sdk.NewAttribute(types.AttributeDenom, asset.Denom),
Expand Down
6 changes: 4 additions & 2 deletions x/superfluid/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,18 @@ func (suite *KeeperTestSuite) SetupGammPoolsAndSuperfluidAssets(multipliers []sd
for _, pool := range pools {
denom := gammtypes.GetPoolShareDenom(pool.GetId())

suite.App.SuperfluidKeeper.AddNewSuperfluidAsset(suite.Ctx, types.SuperfluidAsset{
err := suite.App.SuperfluidKeeper.AddNewSuperfluidAsset(suite.Ctx, types.SuperfluidAsset{
Denom: denom,
AssetType: types.SuperfluidAssetTypeLPShare,
})
suite.Require().NoError(err)

// register a LP token as a superfluid asset
suite.App.SuperfluidKeeper.AddNewSuperfluidAsset(suite.Ctx, types.SuperfluidAsset{
err = suite.App.SuperfluidKeeper.AddNewSuperfluidAsset(suite.Ctx, types.SuperfluidAsset{
Denom: denom,
AssetType: types.SuperfluidAssetTypeLPShare,
})
suite.Require().NoError(err)

denoms = append(denoms, denom)
poolIds = append(poolIds, pool.GetId())
Expand Down
4 changes: 2 additions & 2 deletions x/superfluid/keeper/superfluid_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ func (k Keeper) UnriskAdjustOsmoValue(ctx sdk.Context, amount sdk.Dec) sdk.Dec {
return amount.Quo(sdk.OneDec().Sub(minRiskFactor))
}

func (k Keeper) AddNewSuperfluidAsset(ctx sdk.Context, asset types.SuperfluidAsset) {
func (k Keeper) AddNewSuperfluidAsset(ctx sdk.Context, asset types.SuperfluidAsset) error {
// initialize osmo equivalent multipliers
epochIdentifier := k.GetEpochIdentifier(ctx)
currentEpoch := k.ek.GetEpochInfo(ctx, epochIdentifier).CurrentEpoch
_ = osmoutils.ApplyFuncIfNoError(ctx, func(ctx sdk.Context) error {
return osmoutils.ApplyFuncIfNoError(ctx, func(ctx sdk.Context) error {
k.SetSuperfluidAsset(ctx, asset)
err := k.UpdateOsmoEquivalentMultipliers(ctx, asset, currentEpoch)
return err
Expand Down
3 changes: 2 additions & 1 deletion x/superfluid/keeper/unpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ func (suite *KeeperTestSuite) TestUnpool() {
poolShareOut := bankKeeper.GetBalance(ctx, poolJoinAcc, poolDenom)

// register a LP token as a superfluid asset
superfluidKeeper.AddNewSuperfluidAsset(ctx, types.SuperfluidAsset{
err = superfluidKeeper.AddNewSuperfluidAsset(ctx, types.SuperfluidAsset{
Denom: poolDenom,
AssetType: types.SuperfluidAssetTypeLPShare,
})
suite.Require().NoError(err)

// whitelist designated pools
// this should be done via `RunForkLogic` at upgrade
Expand Down