Skip to content

Commit

Permalink
fix: amm price calc (#355)
Browse files Browse the repository at this point in the history
* fix: amm price calc

* test: fix tests
  • Loading branch information
cosmic-vagabond authored Feb 1, 2024
1 parent a47971d commit 9b83a21
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion x/amm/client/cli/tx_join_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func CmdJoinPool() *cobra.Command {
Use: "join-pool [pool-id] [max-amounts-in] [share-amount-out]",
Short: "join a new pool and provide the liquidity to it",
Example: `elysd tx amm join-pool 0 2000uatom,2000uusdc 200000000000000000 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000`,
Args: cobra.ExactArgs(4),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
poolId, err := cast.ToUint64E(args[0])
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions x/amm/keeper/calc_in_route_spot_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ func (k Keeper) CalcInRouteSpotPrice(ctx sdk.Context, tokenIn sdk.Coin, routes [
// 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
6 changes: 3 additions & 3 deletions x/perpetual/keeper/query_open_estimation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ func TestOpenEstimation_Long5XAtom100Usdc(t *testing.T) {
PositionSize: sdk.NewCoin(ptypes.ATOM, sdk.NewInt(497017398)),
SwapFee: sdk.MustNewDecFromStr("0.001000000000000000"),
Discount: sdk.MustNewDecFromStr("0.000000000000000000"),
OpenPrice: sdk.MustNewDecFromStr("1.006001001196340415"),
OpenPrice: sdk.MustNewDecFromStr("0.994034796000000000"),
TakeProfitPrice: sdk.MustNewDecFromStr("2.000000000000000000"),
LiquidationPrice: sdk.MustNewDecFromStr("0.806001001196340415"),
EstimatedPnl: sdk.NewInt(496999499),
LiquidationPrice: sdk.MustNewDecFromStr("0.794034796000000000"),
EstimatedPnl: sdk.NewInt(502982602),
AvailableLiquidity: sdk.NewCoin(ptypes.ATOM, sdk.NewInt(100000000000)),
WeightBalanceRatio: sdk.MustNewDecFromStr("0.000000000000000000"),
BorrowInterestRate: sdk.MustNewDecFromStr("0.000000000000000000"),
Expand Down

0 comments on commit 9b83a21

Please sign in to comment.