Skip to content

Commit

Permalink
matts comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stackman27 committed Nov 29, 2022
1 parent 530c917 commit d2da989
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 80 deletions.
42 changes: 4 additions & 38 deletions x/twap/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
}
Expand All @@ -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()}
Expand Down
40 changes: 0 additions & 40 deletions x/twap/strategy.go

This file was deleted.

4 changes: 2 additions & 2 deletions x/valset-pref/validator_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d2da989

Please sign in to comment.