diff --git a/go.mod b/go.mod index 6902ffe2bc6..6e53cb2244d 100644 --- a/go.mod +++ b/go.mod @@ -20,10 +20,17 @@ require ( github.com/mattn/go-sqlite3 v1.14.17 github.com/ory/dockertest/v3 v3.10.0 github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 +<<<<<<< HEAD github.com/osmosis-labs/osmosis/osmomath v0.0.5 github.com/osmosis-labs/osmosis/osmoutils v0.0.6-0.20230709040235-cbf530ed88cc github.com/osmosis-labs/osmosis/x/epochs v0.0.1 github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.7 +======= + github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230629191111-f375469de8b6 + github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230715164027-b45d8bd42434 + github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304 + github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230602130523-f9a94d8bbd10 +>>>>>>> 04596cab (Make accumulator objects more consistently pointers throughout (#5848)) github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.7 github.com/spf13/cast v1.5.1 diff --git a/go.sum b/go.sum index 0377ada74d5..36ebd2fa607 100644 --- a/go.sum +++ b/go.sum @@ -948,6 +948,7 @@ github.com/osmosis-labs/cosmos-sdk v0.45.0-rc1.0.20230703010110-ed4eb883f2a6 h1: github.com/osmosis-labs/cosmos-sdk v0.45.0-rc1.0.20230703010110-ed4eb883f2a6/go.mod h1:9KGhMg+7ZWgZ50Wa/x8w/jN19O0TSqYLlqUj+2wwxLU= github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:YlmchqTmlwdWSmrRmXKR+PcU96ntOd8u10vTaTZdcNY= github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI= +<<<<<<< HEAD github.com/osmosis-labs/osmosis/osmomath v0.0.5 h1:veOu4VvnqMbJyjx2MEEFW53I9h3m8Kd3WN4hVvUyeIU= github.com/osmosis-labs/osmosis/osmomath v0.0.5/go.mod h1:UlftwozB+QObT3o0YfkuuyL9fsVdgoWt0dm6J7MLYnU= github.com/osmosis-labs/osmosis/osmoutils v0.0.6-0.20230709040235-cbf530ed88cc h1:NhjYKK0ADJCq5nmDfLMGRIAq8/QIhrStlt78+5xOZP4= @@ -956,6 +957,18 @@ github.com/osmosis-labs/osmosis/x/epochs v0.0.1 h1:RCL3+W2s712dgtaKGgUHVt/6iJKfu github.com/osmosis-labs/osmosis/x/epochs v0.0.1/go.mod h1:8dvJFHTpu6SIxmOaSaEw0tHnQ/Z9blf5qsF/ZJnMVHo= github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.7 h1:rd5guXn/SF6i66PO5rlGaDK0AT81kCpiLixyQ5EJ6Yg= github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.7/go.mod h1:sR0lpev9mcm9/9RY50T1og3UC3WpZAsINh/OmgrmFlg= +======= +github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230629191111-f375469de8b6 h1:Kmkx5Rh72+LB8AL6dc6fZA+IVR0INu0YIiMF2ScDhaQ= +github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230629191111-f375469de8b6/go.mod h1:JTym95/bqrSnG5MPcXr1YDhv43JdCeo3p+iDbazoX68= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230709024311-81c831b050de h1:W2lMduMgpNA5zheEIIialw08n1pWJ44Y4t2F924tpDU= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230709024311-81c831b050de/go.mod h1:Pl8Nzx6O6ow/+aqfMoMSz4hX+zz6RrnDYsooptECGxM= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230715164027-b45d8bd42434 h1:MXPrA3sDtqOHYUa9zl4HMGMW+IJwGMqUf6+Hl9nhrCA= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230715164027-b45d8bd42434/go.mod h1:Pl8Nzx6O6ow/+aqfMoMSz4hX+zz6RrnDYsooptECGxM= +github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304 h1:RIrWLzIiZN5Xd2JOfSOtGZaf6V3qEQYg6EaDTAkMnCo= +github.com/osmosis-labs/osmosis/x/epochs v0.0.0-20230328024000-175ec88e4304/go.mod h1:yPWoJTj5RKrXKUChAicp+G/4Ni/uVEpp27mi/FF/L9c= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230602130523-f9a94d8bbd10 h1:XrES5AHZMZ/Y78boW35PTignkhN9h8VvJ1sP8EJDIu8= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230602130523-f9a94d8bbd10/go.mod h1:Ln6CKcXg/CJLSBE6Fd96/MIKPyA4iHuQTKSbl9q7vYo= +>>>>>>> 04596cab (Make accumulator objects more consistently pointers throughout (#5848)) github.com/osmosis-labs/wasmd v0.31.0-osmo-v16 h1:X747cZYdnqc/+RV48iPVeGprpVb/fUWSaKGsZUWrdbg= github.com/osmosis-labs/wasmd v0.31.0-osmo-v16/go.mod h1:Rf8zW/GgBQyFRRB4s62VQHWA6sTlMFSjoDQQpoq64iI= github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw= diff --git a/osmoutils/accum/accum.go b/osmoutils/accum/accum.go index c4fc46e2598..0b58daa6ba7 100644 --- a/osmoutils/accum/accum.go +++ b/osmoutils/accum/accum.go @@ -65,19 +65,19 @@ func MakeAccumulatorWithValueAndShare(accumStore store.KVStore, accumName string } // Gets the current value of the accumulator corresponding to accumName in accumStore -func GetAccumulator(accumStore store.KVStore, accumName string) (AccumulatorObject, error) { +func GetAccumulator(accumStore store.KVStore, accumName string) (*AccumulatorObject, error) { accumContent := AccumulatorContent{} found, err := osmoutils.Get(accumStore, formatAccumPrefixKey(accumName), &accumContent) if err != nil { - return AccumulatorObject{}, err + return &AccumulatorObject{}, err } if !found { - return AccumulatorObject{}, AccumDoesNotExistError{AccumName: accumName} + return &AccumulatorObject{}, AccumDoesNotExistError{AccumName: accumName} } accum := AccumulatorObject{accumStore, accumName, accumContent.AccumValue, accumContent.TotalShares} - return accum, nil + return &accum, nil } // MustGetPosition returns the position associated with the given address. No errors in position retrieval are allowed. @@ -146,7 +146,7 @@ func (accum *AccumulatorObject) NewPositionIntervalAccumulation(name string, num return err } - initOrUpdatePosition(*accum, intervalAccumulationPerShare, name, numShareUnits, sdk.NewDecCoins(), options) + initOrUpdatePosition(accum, intervalAccumulationPerShare, name, numShareUnits, sdk.NewDecCoins(), options) // Update total shares in accum (re-fetch accum from state to ensure it's up to date) updatedAccum, err := GetAccumulator(accum.store, accum.name) @@ -199,13 +199,13 @@ func (accum *AccumulatorObject) AddToPositionIntervalAccumulation(name string, n } // Get addr's current position - position, err := GetPosition(*accum, name) + position, err := GetPosition(accum, name) if err != nil { return err } // Save current number of shares and unclaimed rewards - unclaimedRewards := GetTotalRewards(*accum, position) + unclaimedRewards := GetTotalRewards(accum, position) oldNumShares, err := accum.GetPositionSize(name) if err != nil { return err @@ -213,7 +213,7 @@ func (accum *AccumulatorObject) AddToPositionIntervalAccumulation(name string, n // Update user's position with new number of shares while moving its unaccrued rewards // into UnclaimedRewards. Starting accumulator value is moved up to accum'scurrent value - initOrUpdatePosition(*accum, intervalAccumulationPerShare, name, oldNumShares.Add(newShares), unclaimedRewards, position.Options) + initOrUpdatePosition(accum, intervalAccumulationPerShare, name, oldNumShares.Add(newShares), unclaimedRewards, position.Options) // Update total shares in accum (re-fetch accum from state to ensure it's up to date) updatedAccum, err := GetAccumulator(accum.store, accum.name) @@ -247,7 +247,7 @@ func (accum *AccumulatorObject) RemoveFromPositionIntervalAccumulation(name stri } // Get addr's current position - position, err := GetPosition(*accum, name) + position, err := GetPosition(accum, name) if err != nil { return err } @@ -258,14 +258,14 @@ func (accum *AccumulatorObject) RemoveFromPositionIntervalAccumulation(name stri } // Save current number of shares and unclaimed rewards - unclaimedRewards := GetTotalRewards(*accum, position) + unclaimedRewards := GetTotalRewards(accum, position) oldNumShares, err := accum.GetPositionSize(name) if err != nil { return err } // Update user's position with new number of shares - initOrUpdatePosition(*accum, intervalAccumulationPerShare, name, oldNumShares.Sub(numSharesToRemove), unclaimedRewards, position.Options) + initOrUpdatePosition(accum, intervalAccumulationPerShare, name, oldNumShares.Sub(numSharesToRemove), unclaimedRewards, position.Options) updatedAccum, err := GetAccumulator(accum.store, accum.name) if err != nil { @@ -313,14 +313,14 @@ func (accum *AccumulatorObject) UpdatePositionIntervalAccumulation(name string, // Returns nil on success, error otherwise. func (accum *AccumulatorObject) SetPositionIntervalAccumulation(name string, intervalAccumulationPerShare sdk.DecCoins) error { // Get addr's current position - position, err := GetPosition(*accum, name) + position, err := GetPosition(accum, name) if err != nil { return err } // Update the user's position with the new accumulator value. The unclaimed rewards, options, and // the number of shares stays the same as in the original position. - initOrUpdatePosition(*accum, intervalAccumulationPerShare, name, position.NumShares, position.UnclaimedRewardsTotal, position.Options) + initOrUpdatePosition(accum, intervalAccumulationPerShare, name, position.NumShares, position.UnclaimedRewardsTotal, position.Options) return nil } @@ -366,7 +366,7 @@ func (accum AccumulatorObject) deletePosition(positionName string) { // GetPositionSize returns the number of shares the position with the given // name has in the accumulator. Returns error if position does not exist // or if fails to retrieve position from state. -func (accum AccumulatorObject) GetPositionSize(name string) (sdk.Dec, error) { +func (accum *AccumulatorObject) GetPositionSize(name string) (sdk.Dec, error) { position, err := GetPosition(accum, name) if err != nil { return sdk.Dec{}, err @@ -400,7 +400,7 @@ func (accum AccumulatorObject) GetValue() sdk.DecCoins { // Returns error if // - no position exists for the given address // - any database errors occur. -func (accum AccumulatorObject) ClaimRewards(positionName string) (sdk.Coins, sdk.DecCoins, error) { +func (accum *AccumulatorObject) ClaimRewards(positionName string) (sdk.Coins, sdk.DecCoins, error) { position, err := GetPosition(accum, positionName) if err != nil { return sdk.Coins{}, sdk.DecCoins{}, NoPositionError{positionName} @@ -426,14 +426,15 @@ func (accum AccumulatorObject) ClaimRewards(positionName string) (sdk.Coins, sdk // GetTotalShares returns the total number of shares in the accumulator func (accum AccumulatorObject) GetTotalShares() (sdk.Dec, error) { - accum, err := GetAccumulator(accum.store, accum.name) - return accum.totalShares, err + // TODO: Make this not do an extra get. + accumPtr, err := GetAccumulator(accum.store, accum.name) + return accumPtr.totalShares, err } // AddToUnclaimedRewards adds the given amount of rewards to the unclaimed rewards // for the given position. Returns error if no position exists for the given position name. // Returns error if any database errors occur or if neggative rewards are provided. -func (accum AccumulatorObject) AddToUnclaimedRewards(positionName string, rewardsToAddTotal sdk.DecCoins) error { +func (accum *AccumulatorObject) AddToUnclaimedRewards(positionName string, rewardsToAddTotal sdk.DecCoins) error { position, err := GetPosition(accum, positionName) if err != nil { return err diff --git a/osmoutils/accum/accum_helpers.go b/osmoutils/accum/accum_helpers.go index e7ec22b3eaa..f7d440696d1 100644 --- a/osmoutils/accum/accum_helpers.go +++ b/osmoutils/accum/accum_helpers.go @@ -8,7 +8,7 @@ import ( // initOrUpdatePosition creates a new position or override an existing position // at accumulator's current value with a specific number of shares and unclaimed rewards -func initOrUpdatePosition(accum AccumulatorObject, accumulatorValuePerShare sdk.DecCoins, index string, numShareUnits sdk.Dec, unclaimedRewardsTotal sdk.DecCoins, options *Options) { +func initOrUpdatePosition(accum *AccumulatorObject, accumulatorValuePerShare sdk.DecCoins, index string, numShareUnits sdk.Dec, unclaimedRewardsTotal sdk.DecCoins, options *Options) { position := Record{ NumShares: numShareUnits, AccumValuePerShare: accumulatorValuePerShare, @@ -19,7 +19,7 @@ func initOrUpdatePosition(accum AccumulatorObject, accumulatorValuePerShare sdk. } // Gets addr's current position from store -func GetPosition(accum AccumulatorObject, name string) (Record, error) { +func GetPosition(accum *AccumulatorObject, name string) (Record, error) { position := Record{} found, err := osmoutils.Get(accum.store, FormatPositionPrefixKey(accum.name, name), &position) if err != nil { @@ -33,7 +33,7 @@ func GetPosition(accum AccumulatorObject, name string) (Record, error) { } // Gets total unclaimed rewards, including existing and newly accrued unclaimed rewards -func GetTotalRewards(accum AccumulatorObject, position Record) sdk.DecCoins { +func GetTotalRewards(accum *AccumulatorObject, position Record) sdk.DecCoins { totalRewards := position.UnclaimedRewardsTotal // TODO: add a check that accum.value is greater than position.InitAccumValue diff --git a/osmoutils/accum/accum_test.go b/osmoutils/accum/accum_test.go index 21ff0b3a73b..ecee59f3815 100644 --- a/osmoutils/accum/accum_test.go +++ b/osmoutils/accum/accum_test.go @@ -23,13 +23,13 @@ type AccumTestSuite struct { store store.KVStore } -func (suite *AccumTestSuite) GetAccumulator(name string) accumPackage.AccumulatorObject { +func (suite *AccumTestSuite) GetAccumulator(name string) *accumPackage.AccumulatorObject { accum, err := accumPackage.GetAccumulator(suite.store, name) suite.Require().NoError(err) return accum } -func (suite *AccumTestSuite) MakeAndGetAccumulator(name string) accumPackage.AccumulatorObject { +func (suite *AccumTestSuite) MakeAndGetAccumulator(name string) *accumPackage.AccumulatorObject { err := accumPackage.MakeAccumulator(suite.store, name) suite.Require().NoError(err) accum, err := accumPackage.GetAccumulator(suite.store, name) @@ -37,7 +37,7 @@ func (suite *AccumTestSuite) MakeAndGetAccumulator(name string) accumPackage.Acc return accum } -func (suite *AccumTestSuite) TotalSharesCheck(accum accumPackage.AccumulatorObject, expected sdk.Dec) { +func (suite *AccumTestSuite) TotalSharesCheck(accum *accumPackage.AccumulatorObject, expected sdk.Dec) { shareCount, err := accum.GetTotalShares() suite.Require().NoError(err) suite.Require().Equal(expected.String(), shareCount.String()) @@ -245,32 +245,32 @@ func (suite *AccumTestSuite) TestNewPosition() { expectedPosition accumPackage.Record }{ "test address one - position created": { - accObject: &defaultAccObject, + accObject: defaultAccObject, name: testAddressOne, numShareUnits: positionOne.NumShares, expectedPosition: positionOne, }, "test address two (non-nil options) - position created": { - accObject: &defaultAccObject, + accObject: defaultAccObject, name: testAddressTwo, numShareUnits: positionTwo.NumShares, expectedPosition: positionTwo, options: &emptyPositionOptions, }, "test address one - position overwritten": { - accObject: &defaultAccObject, + accObject: defaultAccObject, name: testAddressOne, numShareUnits: positionOneV2.NumShares, expectedPosition: positionOneV2, }, "test address three - added": { - accObject: &defaultAccObject, + accObject: defaultAccObject, name: testAddressThree, numShareUnits: positionThree.NumShares, expectedPosition: positionThree, }, "test address one with non-empty accumulator - position created": { - accObject: &nonEmptyAccObject, + accObject: nonEmptyAccObject, name: testAddressOne, numShareUnits: positionOne.NumShares, expectedPosition: withInitialAccumValue(positionOne, initialCoinsDenomOne), @@ -297,7 +297,7 @@ func (suite *AccumTestSuite) TestNewPosition() { // ensure receiver was mutated suite.Require().Equal(expectedAccValue, tc.accObject.GetTotalShareField()) // ensure state was mutated - suite.TotalSharesCheck(*tc.accObject, expectedAccValue) + suite.TotalSharesCheck(tc.accObject, expectedAccValue) if tc.options == nil { suite.Require().Nil(position.Options) @@ -327,7 +327,7 @@ func (suite *AccumTestSuite) TestNewPositionIntervalAccumulation() { expectedError error }{ "interval acc value equals to acc": { - accObject: &defaultAccObject, + accObject: defaultAccObject, name: testAddressOne, numShareUnits: positionOne.NumShares, intervalAccumulationPerShare: defaultAccObject.GetValue(), @@ -338,7 +338,7 @@ func (suite *AccumTestSuite) TestNewPositionIntervalAccumulation() { }, }, "interval acc value does not equal to acc": { - accObject: &defaultAccObject, + accObject: defaultAccObject, name: testAddressTwo, numShareUnits: positionTwo.NumShares, intervalAccumulationPerShare: defaultAccObject.GetValue().MulDec(sdk.NewDec(2)), @@ -350,7 +350,7 @@ func (suite *AccumTestSuite) TestNewPositionIntervalAccumulation() { options: &emptyPositionOptions, }, "negative acc value - error": { - accObject: &defaultAccObject, + accObject: defaultAccObject, name: testAddressOne, numShareUnits: positionOne.NumShares, intervalAccumulationPerShare: defaultAccObject.GetValue().MulDec(sdk.NewDec(-1)), @@ -384,7 +384,7 @@ func (suite *AccumTestSuite) TestNewPositionIntervalAccumulation() { // ensure receiver was mutated suite.Require().Equal(expectedAccValue, tc.accObject.GetTotalShareField()) // ensure state was mutated - suite.TotalSharesCheck(*tc.accObject, expectedAccValue) + suite.TotalSharesCheck(tc.accObject, expectedAccValue) if tc.options == nil { suite.Require().Nil(position.Options) return @@ -447,7 +447,7 @@ func (suite *AccumTestSuite) TestClaimRewards() { tests := []struct { testName string - accObject accumPackage.AccumulatorObject + accObject *accumPackage.AccumulatorObject accName string expectedResult sdk.Coins updateNumSharesToZero bool @@ -760,7 +760,7 @@ func (suite *AccumTestSuite) TestAddToPositionIntervalAccumulation() { expectedError error }{ "interval acc value equals to acc": { - accObject: &accObject, + accObject: accObject, name: testAddressOne, numShareUnits: positionOne.NumShares, intervalAccumulationPerShare: accObject.GetValue(), @@ -771,7 +771,7 @@ func (suite *AccumTestSuite) TestAddToPositionIntervalAccumulation() { }, }, "interval acc value does not equal to acc": { - accObject: &accObject, + accObject: accObject, name: testAddressTwo, numShareUnits: positionTwo.NumShares, intervalAccumulationPerShare: accObject.GetValue().MulDec(sdk.NewDec(2)), @@ -814,7 +814,7 @@ func (suite *AccumTestSuite) TestAddToPositionIntervalAccumulation() { // ensure receiver was mutated suite.Require().Equal(expectedAccValue, tc.accObject.GetTotalShareField()) // ensure state was mutated - suite.TotalSharesCheck(*tc.accObject, expectedAccValue) + suite.TotalSharesCheck(tc.accObject, expectedAccValue) }) } } @@ -1030,7 +1030,7 @@ func (suite *AccumTestSuite) TestRemoveFromPositionIntervalAccumulation() { accObject := accumPackage.MakeTestAccumulator(suite.store, testNameOne, baseAccumValue, emptyDec) tests := map[string]struct { - accObject accumPackage.AccumulatorObject + accObject *accumPackage.AccumulatorObject name string numShareUnits sdk.Dec intervalAccumulationPerShare sdk.DecCoins @@ -1559,7 +1559,7 @@ func (suite *AccumTestSuite) TestGetTotalShares() { // Run a number of NewPosition, AddToPosition, and RemoveFromPosition operations on each accum testAddresses := []string{testAddressOne, testAddressTwo, testAddressThree} - accums := []accumPackage.AccumulatorObject{accumOne, accumTwo} + accums := []*accumPackage.AccumulatorObject{accumOne, accumTwo} expectedShares := []sdk.Dec{sdk.OneDec(), sdk.ZeroDec()} for i := 1; i <= 10; i++ { diff --git a/osmoutils/accum/export_test.go b/osmoutils/accum/export_test.go index b6637e02c6c..d477e68c5c3 100644 --- a/osmoutils/accum/export_test.go +++ b/osmoutils/accum/export_test.go @@ -21,7 +21,7 @@ func (accum AccumulatorObject) GetAllPositions() ([]Record, error) { } // Creates an accumulator object for testing purposes -func MakeTestAccumulator(store store.KVStore, name string, value sdk.DecCoins, totalShares sdk.Dec) AccumulatorObject { +func MakeTestAccumulator(store store.KVStore, name string, value sdk.DecCoins, totalShares sdk.Dec) *AccumulatorObject { // We store an accumulator object in state even if unused in tests // because position operations still require GetAccumulator to work _ = MakeAccumulator(store, name) @@ -32,7 +32,7 @@ func MakeTestAccumulator(store store.KVStore, name string, value sdk.DecCoins, t totalShares: totalShares, } setAccumulator(&acc, value, totalShares) - return acc + return &acc } // Gets store from accumulator for testing purposes @@ -55,7 +55,7 @@ func parseRecordFromBz(bz []byte) (record Record, err error) { } // WithPosition is a decorator test function to append a position with the given name to the given accumulator. -func WithPosition(accum AccumulatorObject, name string, position Record) AccumulatorObject { +func WithPosition(accum *AccumulatorObject, name string, position Record) *AccumulatorObject { osmoutils.MustSet(accum.store, FormatPositionPrefixKey(accum.name, name), &position) return accum } @@ -82,6 +82,6 @@ func (accum AccumulatorObject) GetValueField() sdk.DecCoins { return accum.valuePerShare } -func InitOrUpdatePosition(accum AccumulatorObject, accumulatorValue sdk.DecCoins, index string, numShareUnits sdk.Dec, unclaimedRewards sdk.DecCoins, options *Options) { +func InitOrUpdatePosition(accum *AccumulatorObject, accumulatorValue sdk.DecCoins, index string, numShareUnits sdk.Dec, unclaimedRewards sdk.DecCoins, options *Options) { initOrUpdatePosition(accum, accumulatorValue, index, numShareUnits, unclaimedRewards, options) } diff --git a/x/concentrated-liquidity/export_test.go b/x/concentrated-liquidity/export_test.go index 614b82d4cb7..079463cf5e9 100644 --- a/x/concentrated-liquidity/export_test.go +++ b/x/concentrated-liquidity/export_test.go @@ -40,11 +40,11 @@ func (k Keeper) GetPoolById(ctx sdk.Context, poolId uint64) (types.ConcentratedP return k.getPoolById(ctx, poolId) } -func (k Keeper) GetSwapAccumulators(ctx sdk.Context, poolId uint64) (accum.AccumulatorObject, []accum.AccumulatorObject, error) { +func (k Keeper) GetSwapAccumulators(ctx sdk.Context, poolId uint64) (*accum.AccumulatorObject, []*accum.AccumulatorObject, error) { return k.getSwapAccumulators(ctx, poolId) } -func (k Keeper) CrossTick(ctx sdk.Context, poolId uint64, tickIndex int64, nextTickInfo *model.TickInfo, swapStateSpreadRewardGrowth sdk.DecCoin, spreadRewardAccumValue sdk.DecCoins, uptimeAccums []accum.AccumulatorObject) (liquidityDelta sdk.Dec, err error) { +func (k Keeper) CrossTick(ctx sdk.Context, poolId uint64, tickIndex int64, nextTickInfo *model.TickInfo, swapStateSpreadRewardGrowth sdk.DecCoin, spreadRewardAccumValue sdk.DecCoins, uptimeAccums []*accum.AccumulatorObject) (liquidityDelta sdk.Dec, err error) { return k.crossTick(ctx, poolId, tickIndex, nextTickInfo, swapStateSpreadRewardGrowth, spreadRewardAccumValue, uptimeAccums) } @@ -199,11 +199,11 @@ func ValidateTickRangeIsValid(tickSpacing uint64, lowerTick int64, upperTick int return validateTickRangeIsValid(tickSpacing, lowerTick, upperTick) } -func UpdatePosValueToInitValuePlusGrowthOutside(spreadRewardAccumulator accum.AccumulatorObject, positionKey string, spreadRewardGrowthOutside sdk.DecCoins) error { +func UpdatePosValueToInitValuePlusGrowthOutside(spreadRewardAccumulator *accum.AccumulatorObject, positionKey string, spreadRewardGrowthOutside sdk.DecCoins) error { return updatePositionToInitValuePlusGrowthOutside(spreadRewardAccumulator, positionKey, spreadRewardGrowthOutside) } -func UpdatePositionToInitValuePlusGrowthOutside(accumulator accum.AccumulatorObject, positionKey string, growthOutside sdk.DecCoins) error { +func UpdatePositionToInitValuePlusGrowthOutside(accumulator *accum.AccumulatorObject, positionKey string, growthOutside sdk.DecCoins) error { return updatePositionToInitValuePlusGrowthOutside(accumulator, positionKey, growthOutside) } @@ -246,7 +246,7 @@ func CalcAccruedIncentivesForAccum(ctx sdk.Context, accumUptime time.Duration, q return calcAccruedIncentivesForAccum(ctx, accumUptime, qualifyingLiquidity, timeElapsed, poolIncentiveRecords) } -func (k Keeper) UpdateGivenPoolUptimeAccumulatorsToNow(ctx sdk.Context, pool types.ConcentratedPoolExtension, uptimeAccums []accum.AccumulatorObject) error { +func (k Keeper) UpdateGivenPoolUptimeAccumulatorsToNow(ctx sdk.Context, pool types.ConcentratedPoolExtension, uptimeAccums []*accum.AccumulatorObject) error { return k.updateGivenPoolUptimeAccumulatorsToNow(ctx, pool, uptimeAccums) } @@ -278,7 +278,7 @@ func GetUptimeTrackerValues(uptimeTrackers []model.UptimeTracker) []sdk.DecCoins return getUptimeTrackerValues(uptimeTrackers) } -func UpdateAccumAndClaimRewards(accum accum.AccumulatorObject, positionKey string, growthOutside sdk.DecCoins) (sdk.Coins, sdk.DecCoins, error) { +func UpdateAccumAndClaimRewards(accum *accum.AccumulatorObject, positionKey string, growthOutside sdk.DecCoins) (sdk.Coins, sdk.DecCoins, error) { return updateAccumAndClaimRewards(accum, positionKey, growthOutside) } @@ -298,11 +298,11 @@ func (k Keeper) UpdatePoolForSwap(ctx sdk.Context, pool types.ConcentratedPoolEx return k.updatePoolForSwap(ctx, pool, swapDetails, poolUpdates, totalSpreadRewards) } -func (k Keeper) PrepareBalancerPoolAsFullRange(ctx sdk.Context, clPoolId uint64, uptimeAccums []accum.AccumulatorObject) (uint64, sdk.Dec, error) { +func (k Keeper) PrepareBalancerPoolAsFullRange(ctx sdk.Context, clPoolId uint64, uptimeAccums []*accum.AccumulatorObject) (uint64, sdk.Dec, error) { return k.prepareBalancerPoolAsFullRange(ctx, clPoolId, uptimeAccums) } -func (k Keeper) ClaimAndResetFullRangeBalancerPool(ctx sdk.Context, clPoolId uint64, balPoolId uint64, uptimeAccums []accum.AccumulatorObject) (sdk.Coins, error) { +func (k Keeper) ClaimAndResetFullRangeBalancerPool(ctx sdk.Context, clPoolId uint64, balPoolId uint64, uptimeAccums []*accum.AccumulatorObject) (sdk.Coins, error) { return k.claimAndResetFullRangeBalancerPool(ctx, clPoolId, balPoolId, uptimeAccums) } @@ -344,6 +344,6 @@ func (k Keeper) SetupSwapStrategy(ctx sdk.Context, p types.ConcentratedPoolExten return k.setupSwapStrategy(p, spreadFactor, tokenInDenom, priceLimit) } -func MoveRewardsToNewPositionAndDeleteOldAcc(ctx sdk.Context, accum accum.AccumulatorObject, oldPositionName, newPositionName string, growthOutside sdk.DecCoins) error { +func MoveRewardsToNewPositionAndDeleteOldAcc(ctx sdk.Context, accum *accum.AccumulatorObject, oldPositionName, newPositionName string, growthOutside sdk.DecCoins) error { return moveRewardsToNewPositionAndDeleteOldAcc(accum, oldPositionName, newPositionName, growthOutside) } diff --git a/x/concentrated-liquidity/genesis.go b/x/concentrated-liquidity/genesis.go index a0fe65a049a..9ff73399197 100644 --- a/x/concentrated-liquidity/genesis.go +++ b/x/concentrated-liquidity/genesis.go @@ -245,7 +245,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *genesis.GenesisState { // initOrUpdateAccumPosition creates a new position or override an existing position // at accumulator's current value with a specific number of shares and unclaimed rewards -func (k Keeper) initOrUpdateAccumPosition(ctx sdk.Context, accumumulator accum.AccumulatorObject, accumulatorValuePerShare sdk.DecCoins, index string, numShareUnits sdk.Dec, unclaimedRewardsTotal sdk.DecCoins, options *accum.Options) { +func (k Keeper) initOrUpdateAccumPosition(ctx sdk.Context, accumumulator *accum.AccumulatorObject, accumulatorValuePerShare sdk.DecCoins, index string, numShareUnits sdk.Dec, unclaimedRewardsTotal sdk.DecCoins, options *accum.Options) { position := accum.Record{ NumShares: numShareUnits, AccumValuePerShare: accumulatorValuePerShare, diff --git a/x/concentrated-liquidity/genesis_test.go b/x/concentrated-liquidity/genesis_test.go index 4318b1a397a..7de709d2eb7 100644 --- a/x/concentrated-liquidity/genesis_test.go +++ b/x/concentrated-liquidity/genesis_test.go @@ -506,7 +506,7 @@ func (s *KeeperTestSuite) TestInitGenesis() { s.Require().NoError(err) // Check pools - spreadFactorAccums := []accum.AccumulatorObject{} + spreadFactorAccums := []*accum.AccumulatorObject{} incentiveRecords := []types.IncentiveRecord{} s.Require().Equal(len(clPoolsAfterInitialization), len(tc.genesis.PoolData)) for i, actualPoolI := range clPoolsAfterInitialization { diff --git a/x/concentrated-liquidity/incentives.go b/x/concentrated-liquidity/incentives.go index 0007e67df58..17903834f8a 100644 --- a/x/concentrated-liquidity/incentives.go +++ b/x/concentrated-liquidity/incentives.go @@ -44,12 +44,12 @@ func getUptimeTrackerValues(uptimeTrackers []model.UptimeTracker) []sdk.DecCoins // GetUptimeAccumulators gets the uptime accumulator objects for the given poolId // Returns error if accumulator for the given poolId does not exist. -func (k Keeper) GetUptimeAccumulators(ctx sdk.Context, poolId uint64) ([]accum.AccumulatorObject, error) { - accums := make([]accum.AccumulatorObject, len(types.SupportedUptimes)) +func (k Keeper) GetUptimeAccumulators(ctx sdk.Context, poolId uint64) ([]*accum.AccumulatorObject, error) { + accums := make([]*accum.AccumulatorObject, len(types.SupportedUptimes)) for uptimeIndex := range types.SupportedUptimes { acc, err := accum.GetAccumulator(ctx.KVStore(k.storeKey), types.KeyUptimeAccumulator(poolId, uint64(uptimeIndex))) if err != nil { - return []accum.AccumulatorObject{}, err + return []*accum.AccumulatorObject{}, err } accums[uptimeIndex] = acc @@ -123,7 +123,7 @@ func (k Keeper) getInitialUptimeGrowthOppositeDirectionOfLastTraversalForTick(ct // CONTRACT: the caller validates that the pool with the given id exists. // CONTRACT: caller is responsible for the uptimeAccums to be up-to-date. // CONTRACT: uptimeAccums are associated with the given pool id. -func (k Keeper) prepareBalancerPoolAsFullRange(ctx sdk.Context, clPoolId uint64, uptimeAccums []accum.AccumulatorObject) (uint64, sdk.Dec, error) { +func (k Keeper) prepareBalancerPoolAsFullRange(ctx sdk.Context, clPoolId uint64, uptimeAccums []*accum.AccumulatorObject) (uint64, sdk.Dec, error) { // Get CL pool from ID clPool, err := k.getPoolById(ctx, clPoolId) if err != nil { @@ -245,7 +245,7 @@ func (k Keeper) prepareBalancerPoolAsFullRange(ctx sdk.Context, clPoolId uint64, // CONTRACT: the caller validates that the pool with the given id exists. // CONTRACT: caller is responsible for the uptimeAccums to be up-to-date. // CONTRACT: uptimeAccums are associated with the given pool id. -func (k Keeper) claimAndResetFullRangeBalancerPool(ctx sdk.Context, clPoolId uint64, balPoolId uint64, uptimeAccums []accum.AccumulatorObject) (sdk.Coins, error) { +func (k Keeper) claimAndResetFullRangeBalancerPool(ctx sdk.Context, clPoolId uint64, balPoolId uint64, uptimeAccums []*accum.AccumulatorObject) (sdk.Coins, error) { // Get CL pool from ID. This also serves as an early pool existence check. clPool, err := k.getPoolById(ctx, clPoolId) if err != nil { @@ -364,7 +364,7 @@ var dec1e9 = sdk.NewDec(1e9) // * this function does not refetch the uptime accumulators from state. // * this function operates on the given pool directly, instead of fetching it from state. // This is to avoid unnecessary state reads during swaps for performance reasons. -func (k Keeper) updateGivenPoolUptimeAccumulatorsToNow(ctx sdk.Context, pool types.ConcentratedPoolExtension, uptimeAccums []accum.AccumulatorObject) error { +func (k Keeper) updateGivenPoolUptimeAccumulatorsToNow(ctx sdk.Context, pool types.ConcentratedPoolExtension, uptimeAccums []*accum.AccumulatorObject) error { if pool == nil { return types.ErrPoolNil } @@ -788,7 +788,7 @@ func (k Keeper) initOrUpdatePositionUptimeAccumulators(ctx sdk.Context, poolId u // - fails to claim rewards // - fails to check if position record exists // - fails to update position accumulator with the current growth inside the position -func updateAccumAndClaimRewards(accum accum.AccumulatorObject, positionKey string, growthOutside sdk.DecCoins) (sdk.Coins, sdk.DecCoins, error) { +func updateAccumAndClaimRewards(accum *accum.AccumulatorObject, positionKey string, growthOutside sdk.DecCoins) (sdk.Coins, sdk.DecCoins, error) { // Set the position's accumulator value to it's initial value at creation time plus the growth outside at this moment. err := updatePositionToInitValuePlusGrowthOutside(accum, positionKey, growthOutside) if err != nil { @@ -828,7 +828,7 @@ func updateAccumAndClaimRewards(accum accum.AccumulatorObject, positionKey strin // Returns nil on success. Error otherwise. // NOTE: It is only used by fungifyChargedPosition which we disabled for launch. // nolint: unused -func moveRewardsToNewPositionAndDeleteOldAcc(accum accum.AccumulatorObject, oldPositionName, newPositionName string, growthOutside sdk.DecCoins) error { +func moveRewardsToNewPositionAndDeleteOldAcc(accum *accum.AccumulatorObject, oldPositionName, newPositionName string, growthOutside sdk.DecCoins) error { if oldPositionName == newPositionName { return types.ModifySamePositionAccumulatorError{PositionAccName: oldPositionName} } diff --git a/x/concentrated-liquidity/incentives_test.go b/x/concentrated-liquidity/incentives_test.go index 9e21f7d2307..a59f0d55bfd 100644 --- a/x/concentrated-liquidity/incentives_test.go +++ b/x/concentrated-liquidity/incentives_test.go @@ -4075,7 +4075,7 @@ func (s *KeeperTestSuite) TestGetLargestAuthorizedAndSupportedUptimes() { // 2ETH var defaultGlobalRewardGrowth = sdk.NewDecCoins(oneEth.Add(oneEth)) -func (s *KeeperTestSuite) prepareSpreadRewardsAccumulator() accum.AccumulatorObject { +func (s *KeeperTestSuite) prepareSpreadRewardsAccumulator() *accum.AccumulatorObject { pool := s.PrepareConcentratedPool() testAccumulator, err := s.clk.GetSpreadRewardAccumulator(s.Ctx, pool.GetId()) s.Require().NoError(err) diff --git a/x/concentrated-liquidity/spread_rewards.go b/x/concentrated-liquidity/spread_rewards.go index 28a275661f2..448410b927c 100644 --- a/x/concentrated-liquidity/spread_rewards.go +++ b/x/concentrated-liquidity/spread_rewards.go @@ -23,7 +23,7 @@ func (k Keeper) createSpreadRewardAccumulator(ctx sdk.Context, poolId uint64) er // GetSpreadRewardAccumulator gets the spread reward accumulator object using the given poolOd // returns error if accumulator for the given poolId does not exist. -func (k Keeper) GetSpreadRewardAccumulator(ctx sdk.Context, poolId uint64) (accum.AccumulatorObject, error) { +func (k Keeper) GetSpreadRewardAccumulator(ctx sdk.Context, poolId uint64) (*accum.AccumulatorObject, error) { return accum.GetAccumulator(ctx.KVStore(k.storeKey), types.KeySpreadRewardPoolAccumulator(poolId)) } @@ -297,7 +297,7 @@ func calculateSpreadRewardGrowth(targetTick int64, ticksSpreadRewardGrowthOpposi // as we must set the position's accumulator value to the sum of // - the spread reward/uptime growth inside at position creation time (position.InitAccumValue) // - spread reward/uptime growth outside at the current block time (spreadRewardGrowthOutside/uptimeGrowthOutside) -func updatePositionToInitValuePlusGrowthOutside(accumulator accum.AccumulatorObject, positionKey string, growthOutside sdk.DecCoins) error { +func updatePositionToInitValuePlusGrowthOutside(accumulator *accum.AccumulatorObject, positionKey string, growthOutside sdk.DecCoins) error { position, err := accum.GetPosition(accumulator, positionKey) if err != nil { return err diff --git a/x/concentrated-liquidity/spread_rewards_test.go b/x/concentrated-liquidity/spread_rewards_test.go index 2c6552eaebe..14ee54614d9 100644 --- a/x/concentrated-liquidity/spread_rewards_test.go +++ b/x/concentrated-liquidity/spread_rewards_test.go @@ -77,7 +77,7 @@ func (s *KeeperTestSuite) TestCreateAndGetSpreadRewardAccumulator() { s.Require().NoError(err) } else { s.Require().Error(err) - s.Require().Equal(accum.AccumulatorObject{}, poolSpreadRewardAccumulator) + s.Require().Equal(&accum.AccumulatorObject{}, poolSpreadRewardAccumulator) } }) } diff --git a/x/concentrated-liquidity/swaps.go b/x/concentrated-liquidity/swaps.go index 7bdef709bc3..98785e59138 100644 --- a/x/concentrated-liquidity/swaps.go +++ b/x/concentrated-liquidity/swaps.go @@ -609,7 +609,7 @@ func (k Keeper) swapCrossTickLogic(ctx sdk.Context, swapState SwapState, strategy swapstrategy.SwapStrategy, nextInitializedTick int64, nextTickIter db.Iterator, p types.ConcentratedPoolExtension, - spreadRewardAccum accum.AccumulatorObject, uptimeAccums []accum.AccumulatorObject, + spreadRewardAccum *accum.AccumulatorObject, uptimeAccums []*accum.AccumulatorObject, tokenInDenom string) (SwapState, error) { nextInitializedTickInfo, err := ParseTickFromBz(nextTickIter.Value()) if err != nil { @@ -771,14 +771,14 @@ func (k Keeper) getPoolForSwap(ctx sdk.Context, poolId uint64) (types.Concentrat return p, nil } -func (k Keeper) getSwapAccumulators(ctx sdk.Context, poolId uint64) (accum.AccumulatorObject, []accum.AccumulatorObject, error) { +func (k Keeper) getSwapAccumulators(ctx sdk.Context, poolId uint64) (*accum.AccumulatorObject, []*accum.AccumulatorObject, error) { spreadAccum, err := k.GetSpreadRewardAccumulator(ctx, poolId) if err != nil { - return accum.AccumulatorObject{}, []accum.AccumulatorObject{}, err + return &accum.AccumulatorObject{}, []*accum.AccumulatorObject{}, err } uptimeAccums, err := k.GetUptimeAccumulators(ctx, poolId) if err != nil { - return accum.AccumulatorObject{}, []accum.AccumulatorObject{}, err + return &accum.AccumulatorObject{}, []*accum.AccumulatorObject{}, err } return spreadAccum, uptimeAccums, nil } diff --git a/x/concentrated-liquidity/tick.go b/x/concentrated-liquidity/tick.go index bfceb2ed568..18eccc4a0b3 100644 --- a/x/concentrated-liquidity/tick.go +++ b/x/concentrated-liquidity/tick.go @@ -79,7 +79,7 @@ func (k Keeper) initOrUpdateTick(ctx sdk.Context, poolId uint64, currentTick int // CONTRACT: the caller validates that the pool with the given id exists. // CONTRACT: caller is responsible for the uptimeAccums to be up-to-date. // CONTRACT: uptimeAccums are associated with the given pool id. -func (k Keeper) crossTick(ctx sdk.Context, poolId uint64, tickIndex int64, tickInfo *model.TickInfo, swapStateSpreadRewardGrowth sdk.DecCoin, spreadRewardAccumValue sdk.DecCoins, uptimeAccums []accum.AccumulatorObject) (liquidityDelta sdk.Dec, err error) { +func (k Keeper) crossTick(ctx sdk.Context, poolId uint64, tickIndex int64, tickInfo *model.TickInfo, swapStateSpreadRewardGrowth sdk.DecCoin, spreadRewardAccumValue sdk.DecCoins, uptimeAccums []*accum.AccumulatorObject) (liquidityDelta sdk.Dec, err error) { if tickInfo == nil { return sdk.Dec{}, types.ErrNextTickInfoNil } diff --git a/x/concentrated-liquidity/tick_test.go b/x/concentrated-liquidity/tick_test.go index 3e9ea26a1cf..01844057cbe 100644 --- a/x/concentrated-liquidity/tick_test.go +++ b/x/concentrated-liquidity/tick_test.go @@ -651,8 +651,8 @@ func (s *KeeperTestSuite) TestCrossTick() { nextTickInfo = &model.TickInfo{} } - var uptimeAccums []accum.AccumulatorObject - var spreadRewardAccum accum.AccumulatorObject + var uptimeAccums []*accum.AccumulatorObject + var spreadRewardAccum *accum.AccumulatorObject if test.poolToGet == validPoolId { uptimeAccums, err = s.App.ConcentratedLiquidityKeeper.GetUptimeAccumulators(s.Ctx, test.poolToGet) s.Require().NoError(err)