Skip to content

Commit

Permalink
apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown unknown committed Sep 15, 2023
1 parent 08d524a commit 73fe1ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 5 additions & 1 deletion x/perp/v2/keeper/clearing_house.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,11 @@ func (k Keeper) afterPositionUpdate(
}

// update user volume
k.IncreaseTraderVolume(ctx, traderAddr, positionResp.ExchangedNotionalValue.Abs().TruncateInt())
dnrEpoch, err := k.DnREpoch.Get(ctx)
if err != nil {
return err
}
k.IncreaseTraderVolume(ctx, dnrEpoch, traderAddr, positionResp.ExchangedNotionalValue.Abs().TruncateInt())

transferredFee, err := k.transferFee(ctx, market.Pair, traderAddr, positionResp.ExchangedNotionalValue,
market.ExchangeFeeRatio, market.EcosystemFundFeeRatio,
Expand Down
7 changes: 1 addition & 6 deletions x/perp/v2/keeper/dnr.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ func (i intValueEncoder) Name() string {
}

// IncreaseTraderVolume adds the volume to the user's volume for the current epoch.
func (k Keeper) IncreaseTraderVolume(ctx sdk.Context, user sdk.AccAddress, volume math.Int) {
currentEpoch, err := k.DnREpoch.Get(ctx)
// the DnREpoch must always exist. Otherwise, the chain was not initted properly.
if err != nil {
panic(err)
}
func (k Keeper) IncreaseTraderVolume(ctx sdk.Context, currentEpoch uint64, user sdk.AccAddress, volume math.Int) {
currentVolume := k.TraderVolumes.GetOr(ctx, collections.Join(user, currentEpoch), math.ZeroInt())
newVolume := currentVolume.Add(volume)
k.TraderVolumes.Insert(ctx, collections.Join(user, currentEpoch), newVolume)
Expand Down

0 comments on commit 73fe1ab

Please sign in to comment.