Skip to content

Commit

Permalink
Merge branch 'main' into mattverse/stake-multi0msg
Browse files Browse the repository at this point in the history
  • Loading branch information
mattverse committed Aug 11, 2023
2 parents 18f4bd7 + 396e722 commit eab4bfa
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/changelog-entry-reminder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v37.1.0
uses: tj-actions/changed-files@v37.6.0
with:
files_ignore: |
**/*.md
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/required_labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v37.1.0
uses: tj-actions/changed-files@v37.6.0
with:
files_ignore: |
**/*.md
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### API breaks

* [#6014](https://github.com/osmosis-labs/osmosis/pull/6014) refactor: reduce the number of returns in superfluid migration
* [#5983](https://github.com/osmosis-labs/osmosis/pull/5983) refactor(CL): 6 return values in CL CreatePosition with a struct
* [#6004](https://github.com/osmosis-labs/osmosis/pull/6004) reduce number of returns for creating full range position

Expand Down
8 changes: 2 additions & 6 deletions app/upgrades/v17/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,8 @@ func InitializeAssetPairsTestnet(ctx sdk.Context, keepers *keepers.AppKeepers) (

spreadFactor := cfmmPool.GetSpreadFactor(ctx)
err = validateSpotPriceFallsInBounds(ctx, cfmmPool, keepers, baseAsset, spreadFactor)
if errors.Is(err, gammtypes.ErrInvalidMathApprox) {
// Result is zero, which means 0.1 osmo was too much for the swap to handle.
// This is likely because the pool liquidity is too small, so since this just testnet, we skip it.
if err != nil {
continue
} else if err != nil {
return nil, err
}

// Set the spread factor to the same spread factor the GAMM pool was.
Expand Down Expand Up @@ -407,7 +403,7 @@ func validateSpotPriceFallsInBounds(ctx sdk.Context, cfmmPool gammtypes.CFMMPool
}
expectedSpotPriceFromSwap := sdk.NewDec(100000).Quo(respectiveBaseAsset.Amount.ToDec())
if expectedSpotPriceFromSwap.LT(cltypes.MinSpotPrice) || expectedSpotPriceFromSwap.GT(cltypes.MaxSpotPrice) {
return err
return fmt.Errorf("expected spot price from swap to be between %s and %s, got %s", cltypes.MinSpotPrice, cltypes.MaxSpotPrice, expectedSpotPriceFromSwap)
}
return nil
}
6 changes: 0 additions & 6 deletions app/upgrades/v17/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,9 @@ func flipTwapSpotPriceRecords(ctx sdk.Context, pools []poolmanagertypes.PoolI, k

for _, historicalTwapRecord := range twapRecordHistoricalPoolIndexed {
oldRecord := historicalTwapRecord
historicalTwapRecord.Asset0Denom, historicalTwapRecord.Asset1Denom = oldRecord.Asset1Denom, oldRecord.Asset0Denom
historicalTwapRecord.P0LastSpotPrice, historicalTwapRecord.P1LastSpotPrice = oldRecord.P1LastSpotPrice, oldRecord.P0LastSpotPrice

keepers.TwapKeeper.StoreHistoricalTWAP(ctx, historicalTwapRecord)
keepers.TwapKeeper.DeleteHistoricalRecord(ctx, oldRecord)
}

clPoolTwapRecords, err := keepers.TwapKeeper.GetAllMostRecentRecordsForPool(ctx, poolId)
Expand All @@ -248,14 +246,10 @@ func flipTwapSpotPriceRecords(ctx sdk.Context, pools []poolmanagertypes.PoolI, k
}

for _, twapRecord := range clPoolTwapRecords {
twapRecord.LastErrorTime = time.Time{}
oldRecord := twapRecord

twapRecord.Asset0Denom, twapRecord.Asset1Denom = oldRecord.Asset1Denom, oldRecord.Asset0Denom
twapRecord.P0LastSpotPrice, twapRecord.P1LastSpotPrice = oldRecord.P1LastSpotPrice, oldRecord.P0LastSpotPrice

keepers.TwapKeeper.StoreNewRecord(ctx, twapRecord)
keepers.TwapKeeper.DeleteMostRecentRecord(ctx, oldRecord)
}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions app/upgrades/v17/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func dummyTwapRecord(poolId uint64, t time.Time, asset0 string, asset1 string, s
}

func assertTwapFlipped(suite *UpgradeTestSuite, pre, post types.TwapRecord) {
suite.Require().Equal(pre.Asset0Denom, post.Asset1Denom)
suite.Require().Equal(pre.Asset1Denom, post.Asset0Denom)
suite.Require().Equal(pre.Asset0Denom, post.Asset0Denom)
suite.Require().Equal(pre.Asset1Denom, post.Asset1Denom)
suite.Require().Equal(pre.P0LastSpotPrice, post.P1LastSpotPrice)
suite.Require().Equal(pre.P1LastSpotPrice, post.P0LastSpotPrice)
}
Expand Down
26 changes: 15 additions & 11 deletions x/gamm/keeper/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/osmosis-labs/osmosis/v17/x/gamm/types"
gammmigration "github.com/osmosis-labs/osmosis/v17/x/gamm/types/migration"
poolmanagertypes "github.com/osmosis-labs/osmosis/v17/x/poolmanager/types"
superfluidtypes "github.com/osmosis-labs/osmosis/v17/x/superfluid/types"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -20,41 +21,44 @@ import (
func (k Keeper) MigrateUnlockedPositionFromBalancerToConcentrated(ctx sdk.Context,
sender sdk.AccAddress, sharesToMigrate sdk.Coin,
tokenOutMins sdk.Coins,
) (positionData cltypes.CreateFullRangePositionData, poolIdLeaving, poolIdEntering uint64, err error) {
) (cltypes.CreateFullRangePositionData, superfluidtypes.MigrationPoolIDs, error) {
// Get the balancer poolId by parsing the gamm share denom.
poolIdLeaving, err = types.GetPoolIdFromShareDenom(sharesToMigrate.Denom)
poolIdLeaving, err := types.GetPoolIdFromShareDenom(sharesToMigrate.Denom)
if err != nil {
return cltypes.CreateFullRangePositionData{}, 0, 0, err
return cltypes.CreateFullRangePositionData{}, superfluidtypes.MigrationPoolIDs{}, err
}

// Find the governance sanctioned link between the balancer pool and a concentrated pool.
poolIdEntering, err = k.GetLinkedConcentratedPoolID(ctx, poolIdLeaving)
poolIdEntering, err := k.GetLinkedConcentratedPoolID(ctx, poolIdLeaving)
if err != nil {
return cltypes.CreateFullRangePositionData{}, 0, 0, err
return cltypes.CreateFullRangePositionData{}, superfluidtypes.MigrationPoolIDs{}, err
}

// Get the concentrated pool from the message and type cast it to ConcentratedPoolExtension.
concentratedPool, err := k.concentratedLiquidityKeeper.GetConcentratedPoolById(ctx, poolIdEntering)
if err != nil {
return cltypes.CreateFullRangePositionData{}, 0, 0, err
return cltypes.CreateFullRangePositionData{}, superfluidtypes.MigrationPoolIDs{}, err
}

// Exit the balancer pool position.
exitCoins, err := k.ExitPool(ctx, sender, poolIdLeaving, sharesToMigrate.Amount, tokenOutMins)
if err != nil {
return cltypes.CreateFullRangePositionData{}, 0, 0, err
return cltypes.CreateFullRangePositionData{}, superfluidtypes.MigrationPoolIDs{}, err
}
// Defense in depth, ensuring we are returning exactly two coins.
if len(exitCoins) != 2 {
return cltypes.CreateFullRangePositionData{}, 0, 0, fmt.Errorf("Balancer pool must have exactly two tokens")
return cltypes.CreateFullRangePositionData{}, superfluidtypes.MigrationPoolIDs{}, fmt.Errorf("Balancer pool must have exactly two tokens")
}

// Create a full range (min to max tick) concentrated liquidity position.
positionData, err = k.concentratedLiquidityKeeper.CreateFullRangePosition(ctx, concentratedPool.GetId(), sender, exitCoins)
positionData, err := k.concentratedLiquidityKeeper.CreateFullRangePosition(ctx, concentratedPool.GetId(), sender, exitCoins)
if err != nil {
return cltypes.CreateFullRangePositionData{}, 0, 0, err
return cltypes.CreateFullRangePositionData{}, superfluidtypes.MigrationPoolIDs{}, err
}
return positionData, poolIdLeaving, poolIdEntering, nil
return positionData, superfluidtypes.MigrationPoolIDs{
LeavingID: poolIdLeaving,
EnteringID: poolIdEntering,
}, nil
}

// GetAllMigrationInfo gets all existing links between Balancer Pool and Concentrated Pool,
Expand Down
10 changes: 5 additions & 5 deletions x/gamm/keeper/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,15 @@ func (s *KeeperTestSuite) TestMigrate() {

// Migrate the user's gamm shares to a full range concentrated liquidity position
userBalancesBeforeMigration := s.App.BankKeeper.GetAllBalances(s.Ctx, test.param.sender)
positionData, poolIdLeaving, poolIdEntering, err := keeper.MigrateUnlockedPositionFromBalancerToConcentrated(s.Ctx, test.param.sender, sharesToMigrate, test.tokenOutMins)
positionData, migratedPools, err := keeper.MigrateUnlockedPositionFromBalancerToConcentrated(s.Ctx, test.param.sender, sharesToMigrate, test.tokenOutMins)
userBalancesAfterMigration := s.App.BankKeeper.GetAllBalances(s.Ctx, test.param.sender)
if test.expectedErr != nil {
s.Require().Error(err)
s.Require().ErrorContains(err, test.expectedErr.Error())

// Expect zero values for both pool ids
s.Require().Zero(poolIdLeaving)
s.Require().Zero(poolIdEntering)
s.Require().Zero(migratedPools.LeavingID)
s.Require().Zero(migratedPools.EnteringID)

// Assure the user's gamm shares still exist
userGammBalanceAfterFailedMigration := s.App.BankKeeper.GetBalance(s.Ctx, test.param.sender, "gamm/pool/1")
Expand All @@ -259,8 +259,8 @@ func (s *KeeperTestSuite) TestMigrate() {

// Expect the poolIdLeaving to be the balancer pool id
// Expect the poolIdEntering to be the concentrated liquidity pool id
s.Require().Equal(balancerPoolId, poolIdLeaving)
s.Require().Equal(clPool.GetId(), poolIdEntering)
s.Require().Equal(balancerPoolId, migratedPools.LeavingID)
s.Require().Equal(clPool.GetId(), migratedPools.EnteringID)

// Determine how much of the user's balance was not used in the migration
// This amount should be returned to the user.
Expand Down
9 changes: 5 additions & 4 deletions x/superfluid/keeper/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

cltypes "github.com/osmosis-labs/osmosis/v17/x/concentrated-liquidity/types"
lockuptypes "github.com/osmosis-labs/osmosis/v17/x/lockup/types"
types "github.com/osmosis-labs/osmosis/v17/x/superfluid/types"
)

var (
Expand All @@ -22,15 +23,15 @@ func (k Keeper) PrepareConcentratedLockForSlash(ctx sdk.Context, lock *lockuptyp
return k.prepareConcentratedLockForSlash(ctx, lock, slashAmt)
}

func (k Keeper) MigrateSuperfluidBondedBalancerToConcentrated(ctx sdk.Context, sender sdk.AccAddress, lockId uint64, sharesToMigrate sdk.Coin, synthDenomBeforeMigration string, tokenOutMins sdk.Coins) (positionData cltypes.CreateFullRangePositionData, concentratedLockId, poolIdLeaving, poolIdEntering uint64, err error) {
func (k Keeper) MigrateSuperfluidBondedBalancerToConcentrated(ctx sdk.Context, sender sdk.AccAddress, lockId uint64, sharesToMigrate sdk.Coin, synthDenomBeforeMigration string, tokenOutMins sdk.Coins) (cltypes.CreateFullRangePositionData, uint64, types.MigrationPoolIDs, error) {
return k.migrateSuperfluidBondedBalancerToConcentrated(ctx, sender, lockId, sharesToMigrate, synthDenomBeforeMigration, tokenOutMins)
}

func (k Keeper) MigrateSuperfluidUnbondingBalancerToConcentrated(ctx sdk.Context, sender sdk.AccAddress, lockId uint64, sharesToMigrate sdk.Coin, synthDenomBeforeMigration string, tokenOutMins sdk.Coins) (positionData cltypes.CreateFullRangePositionData, concentratedLockId, poolIdLeaving, poolIdEntering uint64, err error) {
func (k Keeper) MigrateSuperfluidUnbondingBalancerToConcentrated(ctx sdk.Context, sender sdk.AccAddress, lockId uint64, sharesToMigrate sdk.Coin, synthDenomBeforeMigration string, tokenOutMins sdk.Coins) (cltypes.CreateFullRangePositionData, uint64, types.MigrationPoolIDs, error) {
return k.migrateSuperfluidUnbondingBalancerToConcentrated(ctx, sender, lockId, sharesToMigrate, synthDenomBeforeMigration, tokenOutMins)
}

func (k Keeper) MigrateNonSuperfluidLockBalancerToConcentrated(ctx sdk.Context, sender sdk.AccAddress, lockId uint64, sharesToMigrate sdk.Coin, tokenOutMins sdk.Coins) (positionData cltypes.CreateFullRangePositionData, concentratedLockId, poolIdLeaving, poolIdEntering uint64, err error) {
func (k Keeper) MigrateNonSuperfluidLockBalancerToConcentrated(ctx sdk.Context, sender sdk.AccAddress, lockId uint64, sharesToMigrate sdk.Coin, tokenOutMins sdk.Coins) (cltypes.CreateFullRangePositionData, uint64, types.MigrationPoolIDs, error) {
return k.migrateNonSuperfluidLockBalancerToConcentrated(ctx, sender, lockId, sharesToMigrate, tokenOutMins)
}

Expand All @@ -42,7 +43,7 @@ func (k Keeper) GetMigrationType(ctx sdk.Context, sender sdk.AccAddress, lockId
return k.getMigrationType(ctx, sender, lockId)
}

func (k Keeper) ValidateMigration(ctx sdk.Context, sender sdk.AccAddress, lockId uint64, sharesToMigrate sdk.Coin) (poolIdLeaving, poolIdEntering uint64, preMigrationLock *lockuptypes.PeriodLock, remainingLockTime time.Duration, err error) {
func (k Keeper) ValidateMigration(ctx sdk.Context, sender sdk.AccAddress, lockId uint64, sharesToMigrate sdk.Coin) (types.MigrationPoolIDs, *lockuptypes.PeriodLock, time.Duration, error) {
return k.validateMigration(ctx, sender, lockId, sharesToMigrate)
}

Expand Down
Loading

0 comments on commit eab4bfa

Please sign in to comment.