Skip to content

Commit

Permalink
flip spot price too
Browse files Browse the repository at this point in the history
  • Loading branch information
stackman27 committed Aug 1, 2023
1 parent 074d2e6 commit 23c923f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
8 changes: 4 additions & 4 deletions app/upgrades/v17/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ func FlipTwapSpotPriceRecords(ctx sdk.Context, poolIds []uint64, keepers *keeper
twapRecord.LastErrorTime = time.Time{}
oldAsset0Denom := twapRecord.Asset0Denom
oldAsset1Denom := twapRecord.Asset1Denom
// oldSpotPrice0 := twapRecord.P0LastSpotPrice
// oldSpotPrice1 := twapRecord.P1LastSpotPrice
oldSpotPrice0 := twapRecord.P0LastSpotPrice
oldSpotPrice1 := twapRecord.P1LastSpotPrice

twapRecord.Asset0Denom = oldAsset1Denom
twapRecord.Asset1Denom = oldAsset0Denom
// twapRecord.P0LastSpotPrice = oldSpotPrice1
// twapRecord.P1LastSpotPrice = oldSpotPrice0
twapRecord.P0LastSpotPrice = oldSpotPrice1
twapRecord.P1LastSpotPrice = oldSpotPrice0
keepers.TwapKeeper.StoreNewRecord(ctx, oldAsset0Denom, oldAsset1Denom, twapRecord)
}
}
Expand Down
32 changes: 22 additions & 10 deletions app/upgrades/v17/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ func dummyUpgrade(suite *UpgradeTestSuite) {
suite.Ctx = suite.Ctx.WithBlockHeight(dummyUpgradeHeight)
}

func dummyTwapRecord(poolId uint64, t time.Time, asset0 string, asset1 string) types.TwapRecord {
func dummyTwapRecord(poolId uint64, t time.Time, asset0 string, asset1 string, sp0, accum0, accum1, geomAccum sdk.Dec) types.TwapRecord {
return types.TwapRecord{
PoolId: poolId,
Time: t,
Asset0Denom: asset0,
Asset1Denom: asset1,

P0LastSpotPrice: sdk.ZeroDec(),
P1LastSpotPrice: sdk.ZeroDec(),
P0ArithmeticTwapAccumulator: sdk.ZeroDec(),
P1ArithmeticTwapAccumulator: sdk.ZeroDec(),
GeometricTwapAccumulator: sdk.ZeroDec(),
P0LastSpotPrice: sp0,
P1LastSpotPrice: sdk.OneDec().Quo(sp0),
P0ArithmeticTwapAccumulator: accum0,
P1ArithmeticTwapAccumulator: accum1,
GeometricTwapAccumulator: geomAccum,
}
}

Expand All @@ -79,8 +79,17 @@ func (suite *UpgradeTestSuite) TestUpgrade() {
pool2 := suite.PrepareConcentratedPoolWithCoins("uion", "uosmo")

// create few TWAP records for the pools
dummyTwapRecord(pool1.GetId(), time.Unix(1257894000, 0).UTC(), "eth", "usdc")
dummyTwapRecord(pool2.GetId(), time.Unix(1257894000, 0).UTC(), "uion", "uosmo")
t1 := dummyTwapRecord(pool1.GetId(), time.Unix(1257894000, 0).UTC(), "eth", "usdc", sdk.NewDec(2),
sdk.OneDec().MulInt64(10*10+5*10),
sdk.OneDec().MulInt64(3),
sdk.ZeroDec())
t2 := dummyTwapRecord(pool2.GetId(), time.Unix(1257894000, 0).UTC(), "uion", "uosmo", sdk.NewDec(10),
sdk.OneDec().MulInt64(10*10),
sdk.OneDec(),
sdk.ZeroDec())

suite.App.TwapKeeper.StoreNewRecord(suite.Ctx, "eth", "usdc", t1)
suite.App.TwapKeeper.StoreNewRecord(suite.Ctx, "uion", "uosmo", t2)
},
func() {
oldTwapRecordsPool1, err := suite.App.TwapKeeper.GetAllMostRecentRecordsForPool(suite.Ctx, 1)
Expand Down Expand Up @@ -108,11 +117,14 @@ func (suite *UpgradeTestSuite) TestUpgrade() {
for idx := range updatedTwapRecordsPool1 {
suite.Require().Equal(oldTwapRecordsPool1[idx].Asset0Denom, updatedTwapRecordsPool1[idx].Asset1Denom)
suite.Require().Equal(oldTwapRecordsPool1[idx].Asset1Denom, updatedTwapRecordsPool1[idx].Asset0Denom)

suite.Require().Equal(oldTwapRecordsPool1[idx].P0LastSpotPrice, updatedTwapRecordsPool1[idx].P1LastSpotPrice)
suite.Require().Equal(oldTwapRecordsPool1[idx].P1LastSpotPrice, updatedTwapRecordsPool1[idx].P0LastSpotPrice)
}

for idx := range updatedTwapRecordsPool2 {
suite.Require().Equal(oldTwapRecordsPool2[idx].Asset0Denom, updatedTwapRecordsPool2[idx].Asset1Denom)
suite.Require().Equal(oldTwapRecordsPool2[idx].Asset1Denom, updatedTwapRecordsPool2[idx].Asset0Denom)
suite.Require().Equal(oldTwapRecordsPool2[idx].P0LastSpotPrice, updatedTwapRecordsPool2[idx].P1LastSpotPrice)
suite.Require().Equal(oldTwapRecordsPool2[idx].P1LastSpotPrice, updatedTwapRecordsPool2[idx].P0LastSpotPrice)
}

},
Expand Down

0 comments on commit 23c923f

Please sign in to comment.