Skip to content

Commit

Permalink
Merge branch 'main' into adam/v0.50.x-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed May 21, 2024
2 parents 62141e5 + 15952dd commit 7c213f8
Show file tree
Hide file tree
Showing 17 changed files with 793 additions and 89 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### State Breaking

* [#8169](https://github.com/osmosis-labs/osmosis/pull/8169) Support non-pool assets in superfluid staking.
* [#8274](https://github.com/osmosis-labs/osmosis/pull/8274) SDK v50 and Comet v0.38 upgrade

### State Compatible

* [#8128](https://github.com/osmosis-labs/osmosis/pull/8128) Cache the result for poolmanager.GetPoolModule
* [#8253](https://github.com/osmosis-labs/osmosis/pull/8253) Update gogoproto to v1.4.11 and golang.org/x/exp to
* [#8148](https://github.com/osmosis-labs/osmosis/pull/8148) Remove the deserialization time for GetDefaultTakerFee()
* [#8274](https://github.com/osmosis-labs/osmosis/pull/8274) SDK v50 and Comet v0.38 upgrade


## v25.0.0

Expand Down
2 changes: 1 addition & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.SuperfluidKeeper = superfluidkeeper.NewKeeper(
appKeepers.keys[superfluidtypes.StoreKey], appKeepers.GetSubspace(superfluidtypes.ModuleName),
*appKeepers.AccountKeeper, appKeepers.BankKeeper, appKeepers.StakingKeeper, appKeepers.DistrKeeper, appKeepers.EpochsKeeper, appKeepers.LockupKeeper, appKeepers.GAMMKeeper, appKeepers.IncentivesKeeper,
lockupkeeper.NewMsgServerImpl(appKeepers.LockupKeeper), appKeepers.ConcentratedLiquidityKeeper, appKeepers.PoolManagerKeeper, appKeepers.ValidatorSetPreferenceKeeper)
lockupkeeper.NewMsgServerImpl(appKeepers.LockupKeeper), appKeepers.ConcentratedLiquidityKeeper, appKeepers.PoolManagerKeeper, appKeepers.ValidatorSetPreferenceKeeper, appKeepers.TwapKeeper)

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
Expand Down
3 changes: 3 additions & 0 deletions proto/osmosis/superfluid/superfluid.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ message SuperfluidAsset {
// AssetType indicates whether the superfluid asset is a native token or an lp
// share
SuperfluidAssetType asset_type = 2;
// For non-osmo native assets, we need a pool_id osmo/asset to determine the
// twap of the asset
uint64 price_pool_id = 3;
}

// SuperfluidIntermediaryAccount takes the role of intermediary between LP token
Expand Down
6 changes: 5 additions & 1 deletion x/superfluid/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"strconv"
"strings"

appparams "github.com/osmosis-labs/osmosis/v25/app/params"

"github.com/spf13/cobra"
flag "github.com/spf13/pflag"

Expand Down Expand Up @@ -211,8 +213,10 @@ func parseSetSuperfluidAssetsArgsToContent(cmd *cobra.Command) (govtypesv1beta1.
assetType = types.SuperfluidAssetTypeLPShare
} else if strings.HasPrefix(asset, cltypes.ConcentratedLiquidityTokenPrefix) {
assetType = types.SuperfluidAssetTypeConcentratedShare
} else if asset == appparams.BaseCoinUnit {
return nil, fmt.Errorf("invalid asset type: %s", asset)
} else {
return nil, fmt.Errorf("Invalid asset prefix: %s", asset)
assetType = types.SuperfluidAssetTypeNative
}

superfluidAssets = append(superfluidAssets, types.SuperfluidAsset{
Expand Down
32 changes: 24 additions & 8 deletions x/superfluid/keeper/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import (
"errors"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"

"github.com/osmosis-labs/osmosis/osmomath"

"github.com/osmosis-labs/osmosis/osmoutils"
cl "github.com/osmosis-labs/osmosis/v25/x/concentrated-liquidity"
"github.com/osmosis-labs/osmosis/v25/x/concentrated-liquidity/model"
Expand Down Expand Up @@ -149,10 +152,23 @@ func (k Keeper) UpdateOsmoEquivalentMultipliers(ctx sdk.Context, asset types.Sup
return k.updateConcentratedOsmoEquivalentMultiplier(cacheCtx, asset, newEpochNumber)
})
} else if asset.AssetType == types.SuperfluidAssetTypeNative {
// TODO: Consider deleting superfluid asset type native
k.Logger(ctx).Error("unsupported superfluid asset type")
return errors.New("SuperfluidAssetTypeNative is unsupported")
bondDenom, err := k.sk.BondDenom(ctx)
if err != nil {
return err
}
if asset.Denom == bondDenom {
// The bond denom should be locked via x/lockup and not superfluid
return errors.New("osmo should not be a superfluid asset. It can be staked natively")
}
// get the twap price of the native asset in osmo
startTime := k.ek.GetEpochInfo(ctx, k.GetEpochIdentifier(ctx)).StartTime
price, err := k.twapk.GetArithmeticTwapToNow(ctx, asset.PricePoolId, bondDenom, asset.Denom, startTime)
if err != nil {
return sdkerrors.Wrap(err, "failed to get twap price")
}
k.SetOsmoEquivalentMultiplier(ctx, newEpochNumber, asset.Denom, osmomath.NewDec(1).Quo(price))
}

return nil
}

Expand All @@ -170,10 +186,6 @@ func (k Keeper) updateConcentratedOsmoEquivalentMultiplier(ctx sdk.Context, asse

// get underlying assets from all liquidity in a full range position
// note: this is not the same as the total liquidity in the pool, as this includes positions not in the full range
bondDenom, err := k.sk.BondDenom(ctx)
if err != nil {
return err
}
fullRangeLiquidity, err := k.clk.GetFullRangeLiquidityInPool(ctx, poolId)
if err != nil {
k.Logger(ctx).Error(err.Error())
Expand All @@ -195,6 +207,10 @@ func (k Keeper) updateConcentratedOsmoEquivalentMultiplier(ctx sdk.Context, asse
assets := sdk.NewCoins(asset0, asset1)

// get OSMO amount from underlying assets
bondDenom, err := k.sk.BondDenom(ctx)
if err != nil {
return err
}
osmoPoolAsset := assets.AmountOf(bondDenom)
if osmoPoolAsset.IsZero() {
// Pool has unexpectedly removed OSMO from its assets.
Expand Down
17 changes: 15 additions & 2 deletions x/superfluid/keeper/epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ func (s *KeeperTestSuite) TestUpdateOsmoEquivalentMultipliers() {
// Note: this does not error since CL errors are surrounded in `ApplyFuncIfNoError`
expectedZeroMultipler: true,
},
{
name: "update native token Osmo equivalent successfully",
asset: types.SuperfluidAsset{Denom: "foo", AssetType: types.SuperfluidAssetTypeNative, PricePoolId: 1},
expectedMultiplier: osmomath.MustNewDecFromStr("2.0"),
},
{
name: "update native token Osmo equivalent successfully - no pool",
asset: types.SuperfluidAsset{Denom: "foo", AssetType: types.SuperfluidAssetTypeNative},
expectedError: errors.New("failed to get twap price"),
},
}

for _, tc := range testCases {
Expand All @@ -78,15 +88,15 @@ func (s *KeeperTestSuite) TestUpdateOsmoEquivalentMultipliers() {
if tc.removeStakingAsset {
stakeDenom = "bar"
}
poolCoins := sdk.NewCoins(sdk.NewCoin(stakeDenom, osmomath.NewInt(1000000000000000000)), sdk.NewCoin("foo", osmomath.NewInt(1000000000000000000)))
poolCoins := sdk.NewCoins(sdk.NewCoin(stakeDenom, osmomath.NewInt(1000000000000000000)), sdk.NewCoin("foo", osmomath.NewInt(500000000000000000)))

// Ensure that the multiplier is zero before the test
multiplier := superfluidKeeper.GetOsmoEquivalentMultiplier(ctx, tc.asset.Denom)
s.Require().Equal(multiplier, osmomath.ZeroDec())

// Create the respective pool if the test case requires it
if !tc.poolDoesNotExist {
if tc.asset.AssetType == types.SuperfluidAssetTypeLPShare {
if tc.asset.AssetType == types.SuperfluidAssetTypeLPShare || tc.asset.AssetType == types.SuperfluidAssetTypeNative {
s.PrepareBalancerPoolWithCoins(poolCoins...)
} else if tc.asset.AssetType == types.SuperfluidAssetTypeConcentratedShare {
s.PrepareConcentratedPoolWithCoinsAndLockedFullRangePosition(stakeDenom, "foo")
Expand Down Expand Up @@ -115,6 +125,9 @@ func (s *KeeperTestSuite) TestUpdateOsmoEquivalentMultipliers() {

if !tc.expectedZeroMultipler {
s.Require().NotEqual(multiplier, osmomath.ZeroDec())
if !tc.expectedMultiplier.IsNil() {
s.Require().Equal(tc.expectedMultiplier, multiplier)
}
} else {
// Zero on success is expected on CL errors since those are surrounded with `ApplyFuncIfNoError`
s.Require().Equal(multiplier, osmomath.ZeroDec())
Expand Down
3 changes: 3 additions & 0 deletions x/superfluid/keeper/gov/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func HandleSetSuperfluidAssetsProposal(ctx sdk.Context, k keeper.Keeper, ek type
return fmt.Errorf("concentrated LP share denom (%s) must have asset type %s", asset.Denom, types.SuperfluidAssetTypeConcentratedShare)
}
}
if asset.AssetType == types.SuperfluidAssetTypeNative && asset.PricePoolId == 0 {
return fmt.Errorf("native asset (%s) must have a price pool id", asset.Denom)
}
if err := k.AddNewSuperfluidAsset(ctx, asset); err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions x/superfluid/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (q Querier) SuperfluidDelegationsByDelegator(goCtx context.Context, req *ty

// Find how many osmo tokens this delegation is worth at superfluids current risk adjustment
// and twap of the denom.
equivalentAmount, err := q.Keeper.GetSuperfluidOSMOTokens(ctx, baseDenom, lockedCoins.Amount)
equivalentAmount, err := q.Keeper.GetSuperfluidOSMOTokensExcludeNative(ctx, baseDenom, lockedCoins.Amount)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -430,7 +430,7 @@ func (q Querier) SuperfluidDelegationsByValidatorDenom(goCtx context.Context, re
lockedCoins := sdk.NewCoin(req.Denom, lock.GetCoins().AmountOf(req.Denom))
baseDenom := lock.Coins.GetDenomByIndex(0)

equivalentAmount, err := q.Keeper.GetSuperfluidOSMOTokens(ctx, baseDenom, lockedCoins.Amount)
equivalentAmount, err := q.Keeper.GetSuperfluidOSMOTokensExcludeNative(ctx, baseDenom, lockedCoins.Amount)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -525,7 +525,7 @@ func (q Querier) TotalDelegationByValidatorForDenom(goCtx context.Context, req *
amount = amount.Add(record.DelegationAmount.Amount)
}

equivalentAmountOSMO, err := q.Keeper.GetSuperfluidOSMOTokens(ctx, req.Denom, amount)
equivalentAmountOSMO, err := q.Keeper.GetSuperfluidOSMOTokensExcludeNative(ctx, req.Denom, amount)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -704,7 +704,7 @@ func (q Querier) filterConcentratedPositionLocks(ctx sdk.Context, positions []mo

baseDenom := lock.Coins.GetDenomByIndex(0)
lockedCoins := sdk.NewCoin(baseDenom, lock.GetCoins().AmountOf(baseDenom))
equivalentAmount, err := q.Keeper.GetSuperfluidOSMOTokens(ctx, baseDenom, lockedCoins.Amount)
equivalentAmount, err := q.Keeper.GetSuperfluidOSMOTokensExcludeNative(ctx, baseDenom, lockedCoins.Amount)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion x/superfluid/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *KeeperTestSuite) TestTotalDelegationByValidatorForAsset() {
for _, result := range res.Assets {
// check osmo equivalent is correct
actual_response_osmo := result.OsmoEquivalent
needed_response_osmo, err := s.App.SuperfluidKeeper.GetSuperfluidOSMOTokens(ctx, denom, osmomath.NewInt(delegation_amount))
needed_response_osmo, err := s.App.SuperfluidKeeper.GetSuperfluidOSMOTokensExcludeNative(ctx, denom, osmomath.NewInt(delegation_amount))
s.Require().NoError(err)

s.Require().Equal(actual_response_osmo, needed_response_osmo)
Expand Down
Loading

0 comments on commit 7c213f8

Please sign in to comment.