Skip to content

Commit

Permalink
swap fixes (#881)
Browse files Browse the repository at this point in the history
* adding swap fixes

* undoing tvl fixes

* fixing unit test cases, and close position swap type

* fixing test cases
  • Loading branch information
avkr003 authored Oct 26, 2024
1 parent 951ed74 commit c4d2695
Show file tree
Hide file tree
Showing 61 changed files with 212 additions and 224 deletions.
1 change: 1 addition & 0 deletions x/amm/client/cli/query_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func networkWithPoolObjects(t *testing.T, n int) (*network.Network, []types.Pool
pool := types.Pool{
PoolId: uint64(i),
TotalWeight: sdk.NewInt(100),
Address: types.NewPoolAddress(uint64(i)).String(),
PoolParams: types.PoolParams{
SwapFee: sdk.ZeroDec(),
ExitFee: sdk.ZeroDec(),
Expand Down
6 changes: 4 additions & 2 deletions x/amm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ func TestGenesis(t *testing.T) {

PoolList: []types.Pool{
{
PoolId: 0,
PoolId: 0,
Address: types.NewPoolAddress(0).String(),
},
{
PoolId: 1,
PoolId: 1,
Address: types.NewPoolAddress(1).String(),
},
},
DenomLiquidityList: []types.DenomLiquidity{
Expand Down
8 changes: 4 additions & 4 deletions x/amm/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ func (suite *KeeperTestSuite) TestExecuteSwapRequests() {
suite.SetupTest()

// bootstrap accounts
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := types.NewPoolAddress(uint64(1))
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr2 := types.NewPoolAddress(uint64(2))
treasuryAddr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolCoins := sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}
pool2Coins := sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin("uusdt", 1000000)}
Expand Down Expand Up @@ -245,7 +245,7 @@ func (suite *KeeperTestSuite) TestExecuteSwapRequests() {

pool := types.Pool{
PoolId: 1,
Address: poolAddr.String(),
Address: types.NewPoolAddress(uint64(1)).String(),
RebalanceTreasury: treasuryAddr.String(),
PoolParams: types.PoolParams{
SwapFee: sdk.ZeroDec(),
Expand All @@ -266,7 +266,7 @@ func (suite *KeeperTestSuite) TestExecuteSwapRequests() {
}
pool2 := types.Pool{
PoolId: 2,
Address: poolAddr2.String(),
Address: types.NewPoolAddress(uint64(2)).String(),
RebalanceTreasury: treasuryAddr2.String(),
PoolParams: types.PoolParams{
SwapFee: sdk.ZeroDec(),
Expand Down
5 changes: 2 additions & 3 deletions x/amm/keeper/calc_in_route_spot_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func (suite *KeeperTestSuite) TestCalcInRouteSpotPrice() {
// bootstrap accounts
sender := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
pool2Addr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
treasury2Addr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())

Expand All @@ -42,7 +41,7 @@ func (suite *KeeperTestSuite) TestCalcInRouteSpotPrice() {
}
pool := types.Pool{
PoolId: 1,
Address: poolAddr.String(),
Address: types.NewPoolAddress(uint64(1)).String(),
RebalanceTreasury: treasuryAddr.String(),
PoolParams: types.PoolParams{
UseOracle: false,
Expand All @@ -69,7 +68,7 @@ func (suite *KeeperTestSuite) TestCalcInRouteSpotPrice() {
}
pool2 := types.Pool{
PoolId: 2,
Address: pool2Addr.String(),
Address: types.NewPoolAddress(uint64(2)).String(),
RebalanceTreasury: treasury2Addr.String(),
PoolParams: types.PoolParams{
SwapFee: sdk.ZeroDec(),
Expand Down
5 changes: 2 additions & 3 deletions x/amm/keeper/calc_out_route_spot_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func (suite *KeeperTestSuite) TestCalcOutRouteSpotPrice() {
// bootstrap accounts
sender := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
pool2Addr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
treasury2Addr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())

Expand All @@ -42,7 +41,7 @@ func (suite *KeeperTestSuite) TestCalcOutRouteSpotPrice() {
}
pool := types.Pool{
PoolId: 1,
Address: poolAddr.String(),
Address: types.NewPoolAddress(uint64(1)).String(),
RebalanceTreasury: treasuryAddr.String(),
PoolParams: types.PoolParams{
UseOracle: false,
Expand All @@ -69,7 +68,7 @@ func (suite *KeeperTestSuite) TestCalcOutRouteSpotPrice() {
}
pool2 := types.Pool{
PoolId: 2,
Address: pool2Addr.String(),
Address: types.NewPoolAddress(uint64(2)).String(),
RebalanceTreasury: treasury2Addr.String(),
PoolParams: types.PoolParams{
SwapFee: sdk.ZeroDec(),
Expand Down
5 changes: 2 additions & 3 deletions x/amm/keeper/calc_swap_estimation_by_denom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func (suite *KeeperTestSuite) TestCalcSwapEstimationByDenom() {
// bootstrap accounts
sender := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
pool2Addr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
treasury2Addr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())

Expand All @@ -42,7 +41,7 @@ func (suite *KeeperTestSuite) TestCalcSwapEstimationByDenom() {
}
pool := types.Pool{
PoolId: 1,
Address: poolAddr.String(),
Address: types.NewPoolAddress(uint64(1)).String(),
RebalanceTreasury: treasuryAddr.String(),
PoolParams: types.PoolParams{
UseOracle: false,
Expand All @@ -69,7 +68,7 @@ func (suite *KeeperTestSuite) TestCalcSwapEstimationByDenom() {
}
pool2 := types.Pool{
PoolId: 2,
Address: pool2Addr.String(),
Address: types.NewPoolAddress(uint64(2)).String(),
RebalanceTreasury: treasury2Addr.String(),
PoolParams: types.PoolParams{
SwapFee: sdk.ZeroDec(),
Expand Down
4 changes: 2 additions & 2 deletions x/amm/keeper/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (suite *KeeperTestSuite) TestOnCollectFee() {
suite.SetupTest()

// bootstrap accounts
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := types.NewPoolAddress(uint64(1))
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
revenueAddr := types.NewPoolRevenueAddress(1)

Expand Down Expand Up @@ -155,7 +155,7 @@ func (suite *KeeperTestSuite) TestSwapFeesToRevenueToken() {
suite.SetupTest()

// bootstrap accounts
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := types.NewPoolAddress(uint64(1))
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
revenueAddr := types.NewPoolRevenueAddress(1)

Expand Down
4 changes: 0 additions & 4 deletions x/amm/keeper/keeper_create_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ func (k Keeper) CreatePool(ctx sdk.Context, msg *types.MsgCreatePool) (uint64, e
return 0, err
}

if err := pool.Validate(poolId); err != nil {
return 0, err
}

address, err := sdk.AccAddressFromBech32(pool.GetAddress())
if err != nil {
return 0, fmt.Errorf("invalid pool address %s", pool.GetAddress())
Expand Down
2 changes: 1 addition & 1 deletion x/amm/keeper/keeper_swap_exact_amount_in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (suite *KeeperTestSuite) TestSwapExactAmountIn() {
// bootstrap accounts
sender := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
recipient := sender
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := types.NewPoolAddress(uint64(1))
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
if tc.useNewRecipient {
recipient = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
Expand Down
2 changes: 1 addition & 1 deletion x/amm/keeper/keeper_swap_exact_amount_out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (suite *KeeperTestSuite) TestSwapExactAmountOut() {
// bootstrap accounts
sender := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
recipient := sender
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := types.NewPoolAddress(uint64(1))
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
if tc.useNewRecipient {
recipient = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
Expand Down
9 changes: 6 additions & 3 deletions x/amm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func SetupMockPools(k *keeper.Keeper, ctx sdk.Context) {
// Create and set mock pools
pools := []types.Pool{
{
PoolId: 1,
PoolId: 1,
Address: types.NewPoolAddress(uint64(1)).String(),
PoolAssets: []types.PoolAsset{
{Token: sdk.NewCoin("denom1", sdk.NewInt(1000)), Weight: sdk.OneInt()},
{Token: sdk.NewCoin("denom2", sdk.NewInt(1000)), Weight: sdk.OneInt()},
Expand All @@ -96,7 +97,8 @@ func SetupMockPools(k *keeper.Keeper, ctx sdk.Context) {
TotalShares: sdk.NewCoin(types.GetPoolShareDenom(1), types.OneShare),
},
{
PoolId: 2,
PoolId: 2,
Address: types.NewPoolAddress(uint64(2)).String(),
PoolAssets: []types.PoolAsset{
{Token: sdk.NewCoin("uusdc", sdk.NewInt(1000)), Weight: sdk.OneInt()},
{Token: sdk.NewCoin("denom1", sdk.NewInt(1000)), Weight: sdk.OneInt()},
Expand All @@ -108,7 +110,8 @@ func SetupMockPools(k *keeper.Keeper, ctx sdk.Context) {
TotalShares: sdk.NewCoin(types.GetPoolShareDenom(2), types.OneShare),
},
{
PoolId: 3,
PoolId: 3,
Address: types.NewPoolAddress(uint64(3)).String(),
PoolAssets: []types.PoolAsset{
{Token: sdk.NewCoin("uusdc", sdk.NewInt(1000)), Weight: sdk.OneInt()},
{Token: sdk.NewCoin("denom3", sdk.NewInt(1000)), Weight: sdk.OneInt()},
Expand Down
2 changes: 1 addition & 1 deletion x/amm/keeper/msg_server_join_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (suite *KeeperTestSuite) TestMsgServerJoinPool() {

// bootstrap accounts
sender := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := types.NewPoolAddress(uint64(1))
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())

// bootstrap balances
Expand Down
4 changes: 2 additions & 2 deletions x/amm/keeper/msg_server_swap_by_denom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func (suite *KeeperTestSuite) TestMsgServerSwapByDenom() {

// bootstrap accounts
sender := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := types.NewPoolAddress(uint64(1))
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr2 := types.NewPoolAddress(uint64(2))
treasuryAddr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolCoins := sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}
pool2Coins := sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin("uusdt", 1000000)}
Expand Down
6 changes: 3 additions & 3 deletions x/amm/keeper/msg_server_swap_exact_amount_in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ func (suite *KeeperTestSuite) TestMsgServerSwapExactAmountIn() {

// bootstrap accounts
sender := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := types.NewPoolAddress(uint64(1))
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr2 := types.NewPoolAddress(uint64(2))
treasuryAddr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolCoins := sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}
pool2Coins := sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin("uusdt", 1000000)}
Expand Down Expand Up @@ -223,7 +223,7 @@ func (suite *KeeperTestSuite) TestMsgServerSlippageDifferenceWhenSplit() {

// bootstrap accounts
sender := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := types.NewPoolAddress(uint64(1))
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolCoins := sdk.Coins{sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000), sdk.NewInt64Coin("uusdt", 1000000)}

Expand Down
4 changes: 2 additions & 2 deletions x/amm/keeper/msg_server_swap_exact_amount_out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ func (suite *KeeperTestSuite) TestMsgServerSwapExactAmountOut() {

// bootstrap accounts
sender := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := types.NewPoolAddress(uint64(1))
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr2 := types.NewPoolAddress(uint64(2))
treasuryAddr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolCoins := sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}
pool2Coins := sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin("uusdt", 1000000)}
Expand Down
4 changes: 4 additions & 0 deletions x/amm/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (

// SetPool set a specific pool in the store from its index
func (k Keeper) SetPool(ctx sdk.Context, pool types.Pool) {
err := pool.Validate()
if err != nil {
panic(err)
}
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.PoolKeyPrefix))
b := k.cdc.MustMarshal(&pool)
store.Set(types.PoolKey(pool.PoolId), b)
Expand Down
1 change: 1 addition & 0 deletions x/amm/keeper/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func createNPool(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Pool {
items := make([]types.Pool, n)
for i := range items {
items[i].PoolId = uint64(i)
items[i].Address = types.NewPoolAddress(uint64(i)).String()
items[i].TotalWeight = sdk.NewInt(100)
items[i].TotalShares = sdk.NewCoin(types.GetPoolShareDenom(uint64(i)), types.OneShare)
items[i].PoolParams = types.PoolParams{
Expand Down
2 changes: 1 addition & 1 deletion x/amm/keeper/route_exact_amount_in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (suite *KeeperTestSuite) TestRouteExactAmountIn() {

// bootstrap accounts
sender := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := types.NewPoolAddress(uint64(1))
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())

// bootstrap balances
Expand Down
2 changes: 1 addition & 1 deletion x/amm/keeper/route_exact_amount_out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (suite *KeeperTestSuite) TestRouteExactAmountOut() {

// bootstrap accounts
sender := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := types.NewPoolAddress(uint64(1))
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())

// bootstrap balances
Expand Down
4 changes: 2 additions & 2 deletions x/amm/keeper/update_pool_for_swap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (suite *KeeperTestSuite) TestUpdatePoolForSwap() {

// bootstrap accounts
sender := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr := types.NewPoolAddress(uint64(1))
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())

// bootstrap balances
Expand All @@ -146,7 +146,7 @@ func (suite *KeeperTestSuite) TestUpdatePoolForSwap() {
}
pool := types.Pool{
PoolId: 1,
Address: poolAddr.String(),
Address: types.NewPoolAddress(1).String(),
RebalanceTreasury: treasuryAddr.String(),
PoolParams: types.PoolParams{
SwapFee: sdk.ZeroDec(),
Expand Down
8 changes: 4 additions & 4 deletions x/amm/migrations/v5_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
)

func (m Migrator) V5Migration(ctx sdk.Context) error {
m.keeper.SetParams(ctx, types.Params{
PoolCreationFee: math.NewInt(10_000_000),
SlippageTrackDuration: 86400*7,
m.keeper.SetParams(ctx, types.Params{
PoolCreationFee: math.NewInt(10_000_000),
SlippageTrackDuration: 86400 * 7,
EnableBaseCurrencyPairedPoolOnly: false,
})

pools := m.keeper.GetAllLegacyPool(ctx)
for _, pool := range pools {
newPool := types.Pool{
Expand Down
12 changes: 6 additions & 6 deletions x/amm/types/calc_exit_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func CalcExitPool(
poolLiquidity := pool.GetTotalPoolLiquidity()

if pool.PoolParams.UseOracle && tokenOutDenom != "" {
initialWeightDistance := pool.WeightDistanceFromTarget(ctx, oracleKeeper, pool.PoolAssets)
initialWeightDistance := pool.WeightDistanceFromTarget(ctx, oracleKeeper, accountedPoolKeeper, pool.PoolAssets)
tokenPrice := oracleKeeper.GetAssetPriceFromDenom(ctx, tokenOutDenom)
exitValueWithoutSlippage, err := CalcExitValueWithoutSlippage(ctx, oracleKeeper, accountedPoolKeeper, pool, exitingShares, tokenOutDenom)
if err != nil {
Expand All @@ -117,9 +117,9 @@ func CalcExitPool(

oracleOutAmount := exitValueWithoutSlippage.Quo(tokenPrice)

newAssetPools, err := pool.NewPoolAssetsAfterSwap(
newAssetPools, err := pool.NewPoolAssetsAfterSwap(ctx,
sdk.Coins{},
sdk.Coins{sdk.NewCoin(tokenOutDenom, oracleOutAmount.RoundInt())},
sdk.Coins{sdk.NewCoin(tokenOutDenom, oracleOutAmount.RoundInt())}, accountedPoolKeeper,
)
if err != nil {
return sdk.Coins{}, math.LegacyZeroDec(), err
Expand All @@ -130,15 +130,15 @@ func CalcExitPool(
}
}

weightDistance := pool.WeightDistanceFromTarget(ctx, oracleKeeper, newAssetPools)
weightDistance := pool.WeightDistanceFromTarget(ctx, oracleKeeper, accountedPoolKeeper, newAssetPools)
distanceDiff := weightDistance.Sub(initialWeightDistance)

// target weight
targetWeightOut := NormalizedWeight(ctx, pool.PoolAssets, tokenOutDenom)
targetWeightOut := GetDenomNormalizedWeight(pool.PoolAssets, tokenOutDenom)
targetWeightIn := sdk.OneDec().Sub(targetWeightOut)

// weight breaking fee as in Plasma pool
weightOut := OracleAssetWeight(ctx, oracleKeeper, newAssetPools, tokenOutDenom)
weightOut := GetDenomOracleAssetWeight(ctx, pool.PoolId, oracleKeeper, accountedPoolKeeper, newAssetPools, tokenOutDenom)
weightIn := sdk.OneDec().Sub(weightOut)
weightBreakingFee := GetWeightBreakingFee(weightIn, weightOut, targetWeightIn, targetWeightOut, pool.PoolParams, distanceDiff)

Expand Down
2 changes: 1 addition & 1 deletion x/amm/types/calc_in_amt_given_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (p Pool) CalcInAmtGivenOut(
if err != nil {
return sdk.Coin{}, sdk.ZeroDec(), err
}
oracleWeights, err := OraclePoolNormalizedWeights(ctx, oracle, []PoolAsset{poolAssetIn, poolAssetOut})
oracleWeights, err := GetOraclePoolNormalizedWeights(ctx, p.PoolId, oracle, accountedPool, []PoolAsset{poolAssetIn, poolAssetOut})
if err != nil {
return sdk.Coin{}, sdk.ZeroDec(), err
}
Expand Down
2 changes: 1 addition & 1 deletion x/amm/types/calc_out_amt_given_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (p Pool) CalcOutAmtGivenIn(
if err != nil {
return sdk.Coin{}, sdk.ZeroDec(), err
}
oracleWeights, err := OraclePoolNormalizedWeights(ctx, oracle, []PoolAsset{poolAssetIn, poolAssetOut})
oracleWeights, err := GetOraclePoolNormalizedWeights(ctx, p.PoolId, oracle, accountedPool, []PoolAsset{poolAssetIn, poolAssetOut})
if err != nil {
return sdk.Coin{}, sdk.ZeroDec(), err
}
Expand Down
Loading

0 comments on commit c4d2695

Please sign in to comment.