diff --git a/x/twap/api.go b/x/twap/api.go index bb4b5b71dd9..49fe42ddcea 100644 --- a/x/twap/api.go +++ b/x/twap/api.go @@ -51,47 +51,12 @@ func (k Keeper) GetArithmeticTwap( quoteAssetDenom string, startTime time.Time, endTime time.Time, -) (sdk.Dec, error) { - arithmeticStrategy := &arithmetic{k} - return k.getTwap(ctx, poolId, baseAssetDenom, quoteAssetDenom, startTime, endTime, arithmeticStrategy) -} - -// GetArithmeticTwapToNow returns GetArithmeticTwap on the input, with endTime being fixed to ctx.BlockTime() -// This function does not mutate records. -func (k Keeper) GetArithmeticTwapToNow( - ctx sdk.Context, - poolId uint64, - baseAssetDenom string, - quoteAssetDenom string, - startTime time.Time, -) (sdk.Dec, error) { - arithmeticStrategy := &arithmetic{k} - return k.getTwapToNow(ctx, poolId, baseAssetDenom, quoteAssetDenom, startTime, arithmeticStrategy) -} - -// GetBeginBlockAccumulatorRecord returns a TwapRecord struct corresponding to the state of pool `poolId` -// as of the beginning of the block this is called on. -// This uses the state of the beginning of the block, as if there were swaps since the block has started, -// these swaps have had no time to be arbitraged back. -// This accumulator can be stored, to compute wider ranged twaps. -func (k Keeper) GetBeginBlockAccumulatorRecord(ctx sdk.Context, poolId uint64, asset0Denom string, asset1Denom string) (types.TwapRecord, error) { - return k.getMostRecentRecord(ctx, poolId, asset0Denom, asset1Denom) -} - -func (k Keeper) getTwap( - ctx sdk.Context, - poolId uint64, - baseAssetDenom string, - quoteAssetDenom string, - startTime time.Time, - endTime time.Time, - strategy twapStrategy, ) (sdk.Dec, error) { if startTime.After(endTime) { return sdk.Dec{}, types.StartTimeAfterEndTimeError{StartTime: startTime, EndTime: endTime} } if endTime.Equal(ctx.BlockTime()) { - return k.getTwapToNow(ctx, poolId, baseAssetDenom, quoteAssetDenom, startTime, strategy) + return k.GetArithmeticTwapToNow(ctx, poolId, baseAssetDenom, quoteAssetDenom, startTime) } else if endTime.After(ctx.BlockTime()) { return sdk.Dec{}, types.EndTimeInFutureError{EndTime: endTime, BlockTime: ctx.BlockTime()} } @@ -106,13 +71,14 @@ func (k Keeper) getTwap( return computeTwap(startRecord, endRecord, quoteAssetDenom, arithmeticTwapType) } -func (k Keeper) getTwapToNow( +// GetArithmeticTwapToNow returns GetArithmeticTwap on the input, with endTime being fixed to ctx.BlockTime() +// This function does not mutate records. +func (k Keeper) GetArithmeticTwapToNow( ctx sdk.Context, poolId uint64, baseAssetDenom string, quoteAssetDenom string, startTime time.Time, - strategy twapStrategy, ) (sdk.Dec, error) { if startTime.After(ctx.BlockTime()) { return sdk.Dec{}, types.StartTimeAfterEndTimeError{StartTime: startTime, EndTime: ctx.BlockTime()} diff --git a/x/twap/strategy.go b/x/twap/strategy.go deleted file mode 100644 index 49fa7ebc1c8..00000000000 --- a/x/twap/strategy.go +++ /dev/null @@ -1,40 +0,0 @@ -package twap - -import ( - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/osmosis-labs/osmosis/v13/x/twap/types" -) - -type twapStrategy interface { - getTwapToNow( - ctx sdk.Context, - poolId uint64, - baseAssetDenom string, - quoteAssetDenom string, - startTime time.Time) (sdk.Dec, error) - computeTwap(startRecord types.TwapRecord, endRecord types.TwapRecord, quoteAsset string) (sdk.Dec, error) -} - -type arithmetic struct { - keeper Keeper -} - -var _ twapStrategy = &arithmetic{} - -func (s *arithmetic) getTwapToNow( - ctx sdk.Context, - poolId uint64, - baseAssetDenom string, - quoteAssetDenom string, - startTime time.Time, -) (sdk.Dec, error) { - // decide whether we want to use arithmetic or geometric twap - return s.keeper.GetArithmeticTwapToNow(ctx, poolId, baseAssetDenom, quoteAssetDenom, startTime) -} - -func (s *arithmetic) computeTwap(startRecord types.TwapRecord, endRecord types.TwapRecord, quoteAsset string) (sdk.Dec, error) { - // decide whether we want to use arithmetic or geometric twap - return computeArithmeticTwap(startRecord, endRecord, quoteAsset) -} diff --git a/x/valset-pref/validator_set.go b/x/valset-pref/validator_set.go index 75348a4f260..4c1362bdb2d 100644 --- a/x/valset-pref/validator_set.go +++ b/x/valset-pref/validator_set.go @@ -54,7 +54,7 @@ func (k Keeper) DelegateToValidatorSet(ctx sdk.Context, delegatorAddr string, co // tokenAmt takes the amount to delegate, calculated by {val_distribution_weight * tokenAmt} tokenAmt := val.Weight.Mul(coin.Amount.ToDec()).TruncateInt() - // TODO: What happens here if validator is jailed, tombstoned, or unbonding + // TODO: What happens here if validator unbonding // Delegate the unbonded tokens _, err = k.stakingKeeper.Delegate(ctx, delegator, tokenAmt, stakingtypes.Unbonded, validator, true) if err != nil { @@ -90,7 +90,7 @@ func (k Keeper) UndelegateFromValidatorSet(ctx sdk.Context, delegatorAddr string } if !totalAmountFromWeights.Equal(tokenAmt) { - return fmt.Errorf("The undelegate total donot add up with the amount calculated from weights expected %s got %s", tokenAmt, totalAmountFromWeights) + return fmt.Errorf("The undelegate total do not add up with the amount calculated from weights expected %s got %s", tokenAmt, totalAmountFromWeights) } for _, val := range existingSet.Preferences {