Skip to content

Commit

Permalink
refactor(deps): switch to cosmossdk.io/math from fork math
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Aug 30, 2023
1 parent c55f2f9 commit 40a7f6f
Show file tree
Hide file tree
Showing 400 changed files with 8,821 additions and 8,638 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ Fixes mainnet bugs w/ incorrect accumulation sumtrees, and CL handling for a bal

### API breaks

* [#6238](https://github.com/osmosis-labs/osmosis/pull/6238) switch osmomath to sdkmath types and rename BigDec constructors to contain "Big" in the name.
* Note: with the update, the Dec and Int do not get initialized to zero values
by default in proto marhaling/unmarshaling. Instead, they get set to nil values.
* maxDecBitLen has changed by one bit so overflow panic can be triggerred sooner.
* [#6071](https://github.com/osmosis-labs/osmosis/pull/6071) reduce number of returns for UpdatePosition and TicksToSqrtPrice functions
* [#5906](https://github.com/osmosis-labs/osmosis/pull/5906) Add `AccountLockedCoins` query in lockup module to stargate whitelist.
* [#6053](https://github.com/osmosis-labs/osmosis/pull/6053) monotonic sqrt with 36 decimals
Expand All @@ -93,7 +97,7 @@ Fixes mainnet bugs w/ incorrect accumulation sumtrees, and CL handling for a bal
* [#5983](https://github.com/osmosis-labs/osmosis/pull/5983) refactor(CL): 6 return values in CL CreatePosition with a struct
* [#6004](https://github.com/osmosis-labs/osmosis/pull/6004) reduce number of returns for creating full range position
* [#6018](https://github.com/osmosis-labs/osmosis/pull/6018) golangci: add unused parameters linter
* [#6033](https://github.com/osmosis-labs/osmosis/pull/6033) change tick API from sdk.Dec to osmomath.BigDec
* [#6033](https://github.com/osmosis-labs/osmosis/pull/6033) change tick API from osmomath.Dec to osmomath.BigDec

### Features

Expand Down
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ func TestGetPoolAssetsByDenom(t *testing.T) {
poolAssets: []balancer.PoolAsset {
{
Token: sdk.NewInt64Coin("uosmo", 1e12),
Weight: sdk.NewInt(100),
Weight: osmomath.NewInt(100),
},
},
expectedPoolAssetsByDenom: map[string]balancer.PoolAsset {
"uosmo": {
Token: sdk.NewInt64Coin("uosmo", 1e12),
Weight: sdk.NewInt(100),
Weight: osmomath.NewInt(100),
},
},
},
Expand All @@ -234,10 +234,10 @@ func TestGetPoolAssetsByDenom(t *testing.T) {
poolAssets: []balancer.PoolAsset {
{
Token: sdk.NewInt64Coin("uosmo", 1e12),
Weight: sdk.NewInt(100),
Weight: osmomath.NewInt(100),
}, {
Token: sdk.NewInt64Coin("uosmo", 123),
Weight: sdk.NewInt(400),
Weight: osmomath.NewInt(400),
},
},
err: fmt.Errorf(balancer.ErrMsgFormatRepeatingPoolAssetsNotAllowed, "uosmo"),
Expand Down Expand Up @@ -495,7 +495,7 @@ Additionally, this affects `LastResultsHash` because it contains a `Data` field
Version A
```go
func (sk Keeper) validateAmount(ctx context.Context, amount sdk.Int) error {
func (sk Keeper) validateAmount(ctx context.Context, amount osmomath.Int) error {
if amount.IsNegative() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "amount must be positive or zero")
}
Expand All @@ -506,7 +506,7 @@ func (sk Keeper) validateAmount(ctx context.Context, amount sdk.Int) error {
Version B
```go
func (sk Keeper) validateAmount(ctx context.Context, amount sdk.Int) error {
func (sk Keeper) validateAmount(ctx context.Context, amount osmomath.Int) error {
if amount.IsNegative() || amount.IsZero() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "amount must be positive")
}
Expand Down
25 changes: 13 additions & 12 deletions app/apptesting/concentrated_liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/osmosis/osmomath"
clmodel "github.com/osmosis-labs/osmosis/v19/x/concentrated-liquidity/model"
"github.com/osmosis-labs/osmosis/v19/x/concentrated-liquidity/types"
poolmanagertypes "github.com/osmosis-labs/osmosis/v19/x/poolmanager/types"
Expand All @@ -19,24 +20,24 @@ var (
DefaultTickSpacing = uint64(100)
DefaultLowerTick = int64(30545000)
DefaultUpperTick = int64(31500000)
DefaultCoinAmount = sdk.NewInt(1000000000000000000)
DefaultCoinAmount = osmomath.NewInt(1000000000000000000)
)

// PrepareConcentratedPool sets up an eth usdc concentrated liquidity pool with a tick spacing of 100,
// no liquidity and zero spread factor.
func (s *KeeperTestHelper) PrepareConcentratedPool() types.ConcentratedPoolExtension {
return s.PrepareCustomConcentratedPool(s.TestAccs[0], ETH, USDC, DefaultTickSpacing, sdk.ZeroDec())
return s.PrepareCustomConcentratedPool(s.TestAccs[0], ETH, USDC, DefaultTickSpacing, osmomath.ZeroDec())
}

// PrepareConcentratedPoolWithCoins sets up a concentrated liquidity pool with custom denoms.
func (s *KeeperTestHelper) PrepareConcentratedPoolWithCoins(denom1, denom2 string) types.ConcentratedPoolExtension {
return s.PrepareCustomConcentratedPool(s.TestAccs[0], denom1, denom2, DefaultTickSpacing, sdk.ZeroDec())
return s.PrepareCustomConcentratedPool(s.TestAccs[0], denom1, denom2, DefaultTickSpacing, osmomath.ZeroDec())
}

// PrepareConcentratedPoolWithCoinsAndFullRangePosition sets up a concentrated liquidity pool with custom denoms.
// It also creates a full range position.
func (s *KeeperTestHelper) PrepareConcentratedPoolWithCoinsAndFullRangePosition(denom1, denom2 string) types.ConcentratedPoolExtension {
clPool := s.PrepareCustomConcentratedPool(s.TestAccs[0], denom1, denom2, DefaultTickSpacing, sdk.ZeroDec())
clPool := s.PrepareCustomConcentratedPool(s.TestAccs[0], denom1, denom2, DefaultTickSpacing, osmomath.ZeroDec())
fundCoins := sdk.NewCoins(sdk.NewCoin(denom1, DefaultCoinAmount), sdk.NewCoin(denom2, DefaultCoinAmount))
s.FundAcc(s.TestAccs[0], fundCoins)
s.CreateFullRangePosition(clPool, fundCoins)
Expand All @@ -45,14 +46,14 @@ func (s *KeeperTestHelper) PrepareConcentratedPoolWithCoinsAndFullRangePosition(

// createConcentratedPoolsFromCoinsWithSpreadFactor creates CL pools from given sets of coins and respective swap fees.
// Where element 1 of the input corresponds to the first pool created, element 2 to the second pool created etc.
func (s *KeeperTestHelper) CreateConcentratedPoolsAndFullRangePositionWithSpreadFactor(poolDenoms [][]string, spreadFactor []sdk.Dec) {
func (s *KeeperTestHelper) CreateConcentratedPoolsAndFullRangePositionWithSpreadFactor(poolDenoms [][]string, spreadFactor []osmomath.Dec) {
for i, curPoolDenoms := range poolDenoms {
s.Require().Equal(2, len(curPoolDenoms))
var curSpreadFactor sdk.Dec
var curSpreadFactor osmomath.Dec
if len(spreadFactor) > i {
curSpreadFactor = spreadFactor[i]
} else {
curSpreadFactor = sdk.ZeroDec()
curSpreadFactor = osmomath.ZeroDec()
}

clPool := s.PrepareCustomConcentratedPool(s.TestAccs[0], curPoolDenoms[0], curPoolDenoms[1], DefaultTickSpacing, curSpreadFactor)
Expand All @@ -65,13 +66,13 @@ func (s *KeeperTestHelper) CreateConcentratedPoolsAndFullRangePositionWithSpread
// createConcentratedPoolsFromCoins creates CL pools from given sets of coins (with zero swap fees).
// Where element 1 of the input corresponds to the first pool created, element 2 to the second pool created etc.
func (s *KeeperTestHelper) CreateConcentratedPoolsAndFullRangePosition(poolDenoms [][]string) {
s.CreateConcentratedPoolsAndFullRangePositionWithSpreadFactor(poolDenoms, []sdk.Dec{sdk.ZeroDec()})
s.CreateConcentratedPoolsAndFullRangePositionWithSpreadFactor(poolDenoms, []osmomath.Dec{osmomath.ZeroDec()})
}

// PrepareConcentratedPoolWithCoinsAndLockedFullRangePosition sets up a concentrated liquidity pool with custom denoms.
// It also creates a full range position and locks it for 14 days.
func (s *KeeperTestHelper) PrepareConcentratedPoolWithCoinsAndLockedFullRangePosition(denom1, denom2 string) (types.ConcentratedPoolExtension, uint64, uint64) {
clPool := s.PrepareCustomConcentratedPool(s.TestAccs[0], denom1, denom2, DefaultTickSpacing, sdk.ZeroDec())
clPool := s.PrepareCustomConcentratedPool(s.TestAccs[0], denom1, denom2, DefaultTickSpacing, osmomath.ZeroDec())
fundCoins := sdk.NewCoins(sdk.NewCoin(denom1, DefaultCoinAmount), sdk.NewCoin(denom2, DefaultCoinAmount))
s.FundAcc(s.TestAccs[0], fundCoins)
positionData, concentratedLockId, err := s.App.ConcentratedLiquidityKeeper.CreateFullRangePositionLocked(s.Ctx, clPool.GetId(), s.TestAccs[0], fundCoins, time.Hour*24*14)
Expand All @@ -82,7 +83,7 @@ func (s *KeeperTestHelper) PrepareConcentratedPoolWithCoinsAndLockedFullRangePos
}

// PrepareCustomConcentratedPool sets up a concentrated liquidity pool with the custom parameters.
func (s *KeeperTestHelper) PrepareCustomConcentratedPool(owner sdk.AccAddress, denom0, denom1 string, tickSpacing uint64, spreadFactor sdk.Dec) types.ConcentratedPoolExtension {
func (s *KeeperTestHelper) PrepareCustomConcentratedPool(owner sdk.AccAddress, denom0, denom1 string, tickSpacing uint64, spreadFactor osmomath.Dec) types.ConcentratedPoolExtension {
// Mint some assets to the account.
s.FundAcc(s.TestAccs[0], DefaultAcctFunds)

Expand Down Expand Up @@ -113,15 +114,15 @@ func (s *KeeperTestHelper) PrepareMultipleConcentratedPools(poolsToCreate uint16
}

// CreateFullRangePosition creates a full range position and returns position id and the liquidity created.
func (s *KeeperTestHelper) CreateFullRangePosition(pool types.ConcentratedPoolExtension, coins sdk.Coins) (uint64, sdk.Dec) {
func (s *KeeperTestHelper) CreateFullRangePosition(pool types.ConcentratedPoolExtension, coins sdk.Coins) (uint64, osmomath.Dec) {
s.FundAcc(s.TestAccs[0], coins)
positionData, err := s.App.ConcentratedLiquidityKeeper.CreateFullRangePosition(s.Ctx, pool.GetId(), s.TestAccs[0], coins)
s.Require().NoError(err)
return positionData.ID, positionData.Liquidity
}

// WithdrawFullRangePosition withdraws given liquidity from a position specified by id.
func (s *KeeperTestHelper) WithdrawFullRangePosition(pool types.ConcentratedPoolExtension, positionId uint64, liquidityToRemove sdk.Dec) {
func (s *KeeperTestHelper) WithdrawFullRangePosition(pool types.ConcentratedPoolExtension, positionId uint64, liquidityToRemove osmomath.Dec) {
clMsgServer := cl.NewMsgServerImpl(s.App.ConcentratedLiquidityKeeper)

_, err := clMsgServer.WithdrawPosition(sdk.WrapSDKContext(s.Ctx), &types.MsgWithdrawPosition{
Expand Down
78 changes: 39 additions & 39 deletions app/apptesting/gamm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,41 @@ const (
)

var DefaultAcctFunds sdk.Coins = sdk.NewCoins(
sdk.NewCoin(UOSMO, sdk.NewInt(10000000000)),
sdk.NewCoin(FOO, sdk.NewInt(10000000000)),
sdk.NewCoin(BAR, sdk.NewInt(10000000000)),
sdk.NewCoin(BAZ, sdk.NewInt(10000000000)),
sdk.NewCoin(UOSMO, osmomath.NewInt(10000000000)),
sdk.NewCoin(FOO, osmomath.NewInt(10000000000)),
sdk.NewCoin(BAR, osmomath.NewInt(10000000000)),
sdk.NewCoin(BAZ, osmomath.NewInt(10000000000)),
)

var DefaultPoolAssets = []balancer.PoolAsset{
{
Weight: sdk.NewInt(100),
Token: sdk.NewCoin(FOO, sdk.NewInt(5000000)),
Weight: osmomath.NewInt(100),
Token: sdk.NewCoin(FOO, osmomath.NewInt(5000000)),
},
{
Weight: sdk.NewInt(200),
Token: sdk.NewCoin(BAR, sdk.NewInt(5000000)),
Weight: osmomath.NewInt(200),
Token: sdk.NewCoin(BAR, osmomath.NewInt(5000000)),
},
{
Weight: sdk.NewInt(300),
Token: sdk.NewCoin(BAZ, sdk.NewInt(5000000)),
Weight: osmomath.NewInt(300),
Token: sdk.NewCoin(BAZ, osmomath.NewInt(5000000)),
},
{
Weight: sdk.NewInt(400),
Token: sdk.NewCoin(UOSMO, sdk.NewInt(5000000)),
Weight: osmomath.NewInt(400),
Token: sdk.NewCoin(UOSMO, osmomath.NewInt(5000000)),
},
}

var DefaultStableswapLiquidity = sdk.NewCoins(
sdk.NewCoin(FOO, sdk.NewInt(10000000)),
sdk.NewCoin(BAR, sdk.NewInt(10000000)),
sdk.NewCoin(BAZ, sdk.NewInt(10000000)),
sdk.NewCoin(FOO, osmomath.NewInt(10000000)),
sdk.NewCoin(BAR, osmomath.NewInt(10000000)),
sdk.NewCoin(BAZ, osmomath.NewInt(10000000)),
)

var ImbalancedStableswapLiquidity = sdk.NewCoins(
sdk.NewCoin(FOO, sdk.NewInt(10_000_000_000)),
sdk.NewCoin(BAR, sdk.NewInt(20_000_000_000)),
sdk.NewCoin(BAZ, sdk.NewInt(30_000_000_000)),
sdk.NewCoin(FOO, osmomath.NewInt(10_000_000_000)),
sdk.NewCoin(BAR, osmomath.NewInt(20_000_000_000)),
sdk.NewCoin(BAZ, osmomath.NewInt(30_000_000_000)),
)

// PrepareBalancerPoolWithCoins returns a balancer pool
Expand All @@ -74,21 +74,21 @@ func (s *KeeperTestHelper) PrepareBalancerPoolWithCoinsAndWeights(coins sdk.Coin
var poolAssets []balancer.PoolAsset
for i, coin := range coins {
poolAsset := balancer.PoolAsset{
Weight: sdk.NewInt(weights[i]),
Weight: osmomath.NewInt(weights[i]),
Token: coin,
}
poolAssets = append(poolAssets, poolAsset)
}

return s.PrepareCustomBalancerPool(poolAssets, balancer.PoolParams{
SwapFee: sdk.ZeroDec(),
ExitFee: sdk.ZeroDec(),
SwapFee: osmomath.ZeroDec(),
ExitFee: osmomath.ZeroDec(),
})
}

var zeroDec = sdk.ZeroDec()
var zeroDec = osmomath.ZeroDec()
var oneThirdSpotPriceUnits = sdk.NewDec(1).Quo(sdk.NewDec(3)).
MulIntMut(gammtypes.SpotPriceSigFigs).RoundInt().ToDec().QuoInt(gammtypes.SpotPriceSigFigs)
MulIntMut(gammtypes.SpotPriceSigFigs).RoundInt().ToLegacyDec().QuoInt(gammtypes.SpotPriceSigFigs)

// PrepareBalancerPool returns a Balancer pool's pool-ID with pool params set in PrepareBalancerPoolWithPoolParams.
func (s *KeeperTestHelper) PrepareBalancerPool() uint64 {
Expand All @@ -102,7 +102,7 @@ func (s *KeeperTestHelper) PrepareBalancerPool() uint64 {
s.Equal(sdk.NewDec(2), spotPrice)
spotPrice, err = s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, BAR, BAZ)
s.NoError(err)
s.Equal(sdk.NewDecWithPrec(15, 1), spotPrice)
s.Equal(osmomath.NewDecWithPrec(15, 1), spotPrice)
spotPrice, err = s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, BAZ, FOO)
s.NoError(err)
s.Equal(oneThirdSpotPriceUnits, spotPrice)
Expand Down Expand Up @@ -161,7 +161,7 @@ func (s *KeeperTestHelper) PrepareBalancerPoolWithPoolParams(poolParams balancer
// PrepareCustomBalancerPool sets up a Balancer pool with an array of assets and given parameters
func (s *KeeperTestHelper) PrepareCustomBalancerPool(assets []balancer.PoolAsset, params balancer.PoolParams) uint64 {
// Add coins for pool creation fee + coins needed to mint balances
fundCoins := sdk.NewCoins(sdk.NewCoin(UOSMO, sdk.NewInt(10000000000)))
fundCoins := sdk.NewCoins(sdk.NewCoin(UOSMO, osmomath.NewInt(10000000000)))
for _, a := range assets {
fundCoins = fundCoins.Add(a.Token)
}
Expand All @@ -179,7 +179,7 @@ func (s *KeeperTestHelper) PrepareCustomBalancerPoolFromCoins(coins sdk.Coins, p
var poolAssets []balancer.PoolAsset
for _, coin := range coins {
poolAsset := balancer.PoolAsset{
Weight: sdk.NewInt(1),
Weight: osmomath.NewInt(1),
Token: coin,
}
poolAssets = append(poolAssets, poolAsset)
Expand All @@ -189,7 +189,7 @@ func (s *KeeperTestHelper) PrepareCustomBalancerPoolFromCoins(coins sdk.Coins, p
}

// Modify spotprice of a pool to target spotprice
func (s *KeeperTestHelper) ModifySpotPrice(poolID uint64, targetSpotPrice sdk.Dec, baseDenom string) {
func (s *KeeperTestHelper) ModifySpotPrice(poolID uint64, targetSpotPrice osmomath.Dec, baseDenom string) {
var quoteDenom string
int64Max := int64(^uint64(0) >> 1)

Expand All @@ -206,28 +206,28 @@ func (s *KeeperTestHelper) ModifySpotPrice(poolID uint64, targetSpotPrice sdk.De

amountTrade := s.CalcAmoutOfTokenToGetTargetPrice(s.Ctx, pool, targetSpotPrice, baseDenom, quoteDenom)
if amountTrade.IsPositive() {
swapIn := sdk.NewCoins(sdk.NewCoin(quoteDenom, sdk.NewInt(amountTrade.RoundInt64())))
swapIn := sdk.NewCoins(sdk.NewCoin(quoteDenom, osmomath.NewInt(amountTrade.RoundInt64())))
s.FundAcc(s.TestAccs[0], swapIn)
msg := gammtypes.MsgSwapExactAmountIn{
Sender: s.TestAccs[0].String(),
Routes: []poolmanagertypes.SwapAmountInRoute{{PoolId: poolID, TokenOutDenom: baseDenom}},
TokenIn: swapIn[0],
TokenOutMinAmount: sdk.ZeroInt(),
TokenOutMinAmount: osmomath.ZeroInt(),
}

gammMsgServer := gammkeeper.NewMsgServerImpl(s.App.GAMMKeeper)
_, err = gammMsgServer.SwapExactAmountIn(sdk.WrapSDKContext(s.Ctx), &msg)
s.Require().NoError(err)
} else {
swapOut := sdk.NewCoins(sdk.NewCoin(quoteDenom, sdk.NewInt(amountTrade.RoundInt64()).Abs()))
swapOut := sdk.NewCoins(sdk.NewCoin(quoteDenom, osmomath.NewInt(amountTrade.RoundInt64()).Abs()))
spreadFactor := pool.GetSpreadFactor(s.Ctx)
tokenIn, err := pool.CalcInAmtGivenOut(s.Ctx, swapOut, baseDenom, spreadFactor)
s.Require().NoError(err)
s.FundAcc(s.TestAccs[0], sdk.NewCoins(tokenIn))
msg := gammtypes.MsgSwapExactAmountOut{
Sender: s.TestAccs[0].String(),
Routes: []poolmanagertypes.SwapAmountOutRoute{{PoolId: poolID, TokenInDenom: baseDenom}},
TokenInMaxAmount: sdk.NewInt(int64Max),
TokenInMaxAmount: osmomath.NewInt(int64Max),
TokenOut: swapOut[0],
}

Expand All @@ -238,7 +238,7 @@ func (s *KeeperTestHelper) ModifySpotPrice(poolID uint64, targetSpotPrice sdk.De
}

func (s *KeeperTestHelper) RunBasicExit(poolId uint64) {
shareInAmount := sdk.NewInt(100)
shareInAmount := osmomath.NewInt(100)
tokenOutMins := sdk.NewCoins()

msg := gammtypes.MsgExitPool{
Expand All @@ -260,7 +260,7 @@ func (s *KeeperTestHelper) RunBasicJoin(poolId uint64) {

tokenIn := sdk.NewCoins()
for _, denom := range denoms {
tokenIn = tokenIn.Add(sdk.NewCoin(denom, sdk.NewInt(10000000)))
tokenIn = tokenIn.Add(sdk.NewCoin(denom, osmomath.NewInt(10000000)))
}

s.FundAcc(s.TestAccs[0], sdk.NewCoins(tokenIn...))
Expand All @@ -269,7 +269,7 @@ func (s *KeeperTestHelper) RunBasicJoin(poolId uint64) {
msg := gammtypes.MsgJoinPool{
Sender: s.TestAccs[0].String(),
PoolId: poolId,
ShareOutAmount: totalPoolShare.Quo(sdk.NewInt(100000)),
ShareOutAmount: totalPoolShare.Quo(osmomath.NewInt(100000)),
TokenInMaxs: tokenIn,
}

Expand All @@ -278,15 +278,15 @@ func (s *KeeperTestHelper) RunBasicJoin(poolId uint64) {
s.Require().NoError(err)
}

func (s *KeeperTestHelper) CalcAmoutOfTokenToGetTargetPrice(ctx sdk.Context, pool gammtypes.CFMMPoolI, targetSpotPrice sdk.Dec, baseDenom, quoteDenom string) (amountTrade sdk.Dec) {
func (s *KeeperTestHelper) CalcAmoutOfTokenToGetTargetPrice(ctx sdk.Context, pool gammtypes.CFMMPoolI, targetSpotPrice osmomath.Dec, baseDenom, quoteDenom string) (amountTrade osmomath.Dec) {
blPool, ok := pool.(*balancer.Pool)
s.Require().True(ok)
quoteAsset, _ := blPool.GetPoolAsset(quoteDenom)
baseAsset, err := blPool.GetPoolAsset(baseDenom)
s.Require().NoError(err)

s.Require().NotEqual(baseAsset.Weight, sdk.ZeroInt())
s.Require().NotEqual(quoteAsset.Weight, sdk.ZeroInt())
s.Require().NotEqual(baseAsset.Weight, osmomath.ZeroInt())
s.Require().NotEqual(quoteAsset.Weight, osmomath.ZeroInt())

spotPriceNow, err := blPool.SpotPrice(ctx, baseDenom, quoteDenom)
s.Require().NoError(err)
Expand All @@ -295,9 +295,9 @@ func (s *KeeperTestHelper) CalcAmoutOfTokenToGetTargetPrice(ctx sdk.Context, poo
// AmoutQuoteTokenNeedToTrade = AmoutQuoTokenNow * ((targetSpotPrice/spotPriceNow)^((weight_base/(weight_base + weight_quote))) -1 )

ratioPrice := targetSpotPrice.Quo(spotPriceNow)
ratioWeight := (baseAsset.Weight.ToDec()).Quo(baseAsset.Weight.ToDec().Add(quoteAsset.Weight.ToDec()))
ratioWeight := (baseAsset.Weight.ToLegacyDec()).Quo(baseAsset.Weight.ToLegacyDec().Add(quoteAsset.Weight.ToLegacyDec()))

amountTrade = quoteAsset.Token.Amount.ToDec().Mul(osmomath.Pow(ratioPrice, ratioWeight).Sub(sdk.OneDec()))
amountTrade = quoteAsset.Token.Amount.ToLegacyDec().Mul(osmomath.Pow(ratioPrice, ratioWeight).Sub(osmomath.OneDec()))

return amountTrade
}
Loading

0 comments on commit 40a7f6f

Please sign in to comment.