Skip to content

Commit

Permalink
fix: calc in/out route spot price (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmic-vagabond authored Jan 23, 2024
1 parent 42e7532 commit fe642cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions x/amm/keeper/calc_in_route_spot_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ func (k Keeper) CalcInRouteSpotPrice(ctx sdk.Context, tokenIn sdk.Coin, routes [
return sdk.ZeroDec(), sdk.Coin{}, sdk.ZeroDec(), sdk.ZeroDec(), sdk.Coin{}, sdk.ZeroDec(), types.ErrSpotPriceIsZero
}

// invert the spot price
spotPrice = sdk.OneDec().Quo(spotPrice)

// Calculate the token out amount
tokenOutAmt := sdk.NewDecFromInt(tokenIn.Amount).Mul(spotPrice)

// invert the spot price
spotPrice = sdk.OneDec().Quo(spotPrice)

// Construct the token out coin
tokenOut := sdk.NewCoin(tokenOutDenom, tokenOutAmt.TruncateInt())

Expand Down
3 changes: 3 additions & 0 deletions x/amm/keeper/calc_out_route_spot_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ func (k Keeper) CalcOutRouteSpotPrice(ctx sdk.Context, tokenOut sdk.Coin, routes
// Calculate the token in amount
tokenInAmt := sdk.NewDecFromInt(tokenOut.Amount).Mul(spotPrice)

// invert the spot price
spotPrice = sdk.OneDec().Quo(spotPrice)

// Construct the token out coin
tokenIn := sdk.NewCoin(tokenInDenom, tokenInAmt.TruncateInt())

Expand Down

0 comments on commit fe642cc

Please sign in to comment.