Skip to content

Commit

Permalink
revert statistics.go
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Jan 9, 2024
1 parent 46bd310 commit c3f306d
Showing 1 changed file with 33 additions and 24 deletions.
57 changes: 33 additions & 24 deletions x/protorev/keeper/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,6 @@ func (k Keeper) IncrementNumberOfTrades(ctx sdk.Context) error {
return nil
}

// GetAllProfits returns all of the profits made by the ProtoRev module.
func (k Keeper) GetAllProfits(ctx sdk.Context) []sdk.Coin {
profits := make([]sdk.Coin, 0)

store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.KeyPrefixProfitByDenom)

defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
bz := iterator.Value()
profit := sdk.Coin{}
if err := profit.Unmarshal(bz); err == nil {
profits = append(profits, profit)
}
}

return profits
}

// GetProfitsByDenom returns the profits made by the ProtoRev module for the given denom.
// If the denom is not found, a zero coin is returned.
// GetProfitsByDenom returns the profits made by the ProtoRev module for the given denom
func (k Keeper) GetProfitsByDenom(ctx sdk.Context, denom string) (sdk.Coin, error) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixProfitByDenom)
Expand All @@ -88,9 +67,23 @@ func (k Keeper) GetProfitsByDenom(ctx sdk.Context, denom string) (sdk.Coin, erro
return profits, nil
}

// UpdateProfitsByDenom updates the profits made by the ProtoRev module for the given denom
func (k Keeper) UpdateProfitsByDenom(ctx sdk.Context, denom string, tradeProfit osmomath.Int) error {
return osmoutils.IncreaseCoinByDenomFromPrefix(ctx, k.storeKey, types.KeyPrefixProfitByDenom, denom, tradeProfit)
// GetAllProfits returns all of the profits made by the ProtoRev module.
func (k Keeper) GetAllProfits(ctx sdk.Context) []sdk.Coin {
profits := make([]sdk.Coin, 0)

store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.KeyPrefixProfitByDenom)

defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
bz := iterator.Value()
profit := sdk.Coin{}
if err := profit.Unmarshal(bz); err == nil {
profits = append(profits, profit)
}
}

return profits
}

func (k Keeper) SetCyclicArbProfitTrackerValue(ctx sdk.Context, cyclicArbProfits sdk.Coins) {
Expand Down Expand Up @@ -133,6 +126,22 @@ func (k Keeper) SetCyclicArbProfitTrackerStartHeight(ctx sdk.Context, startHeigh
osmoutils.MustSet(ctx.KVStore(k.storeKey), types.KeyCyclicArbTrackerStartHeight, &gogotypes.Int64Value{Value: startHeight})
}

// UpdateProfitsByDenom updates the profits made by the ProtoRev module for the given denom
func (k Keeper) UpdateProfitsByDenom(ctx sdk.Context, denom string, tradeProfit osmomath.Int) error {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixProfitByDenom)
key := types.GetKeyPrefixProfitByDenom(denom)

profits, _ := k.GetProfitsByDenom(ctx, denom)
profits.Amount = profits.Amount.Add(tradeProfit)
bz, err := profits.Marshal()
if err != nil {
return err
}

store.Set(key, bz)
return nil
}

// GetAllRoutes returns all of the routes that the ProtoRev module has traded on
func (k Keeper) GetAllRoutes(ctx sdk.Context) ([][]uint64, error) {
routes := make([][]uint64, 0)
Expand Down

0 comments on commit c3f306d

Please sign in to comment.