Skip to content

Commit

Permalink
prevent the swap fee going to network fee and move it to surplus
Browse files Browse the repository at this point in the history
  • Loading branch information
kiragpg committed Nov 10, 2023
1 parent c4d2476 commit 6b8a97e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 11 deletions.
6 changes: 1 addition & 5 deletions x/basket/keeper/mint_burn_swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/KiraCore/sekai/x/basket/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

func (k Keeper) MintBasketToken(ctx sdk.Context, msg *types.MsgBasketTokenMint) error {
Expand Down Expand Up @@ -228,10 +227,7 @@ func (k Keeper) BasketSwap(ctx sdk.Context, msg *types.MsgBasketTokenSwap) error
// pay network for fee
feeAmount := pair.InAmount.Amount.Sub(swapAmount)
if feeAmount.IsPositive() {
err := k.bk.SendCoinsFromModuleToModule(ctx, types.ModuleName, authtypes.FeeCollectorName, sdk.Coins{sdk.NewCoin(pair.InAmount.Denom, feeAmount)})
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
}
basket.Surplus = sdk.Coins(basket.Surplus).Add(sdk.NewCoin(pair.InAmount.Denom, feeAmount))
}

outAmount := sdk.NewDecFromInt(swapAmount).Mul(inRate).Quo(outRate).RoundInt()
Expand Down
6 changes: 0 additions & 6 deletions x/basket/keeper/mint_burn_swap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/KiraCore/sekai/x/basket/types"
"github.com/cometbft/cometbft/crypto/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
)

Expand Down Expand Up @@ -759,11 +758,6 @@ func (suite *KeeperTestSuite) TestBasketSwap() {
historicalAmount := suite.app.BasketKeeper.GetLimitsPeriodSwapAmount(suite.ctx, 1, tc.limitPeriod)
suite.Require().Equal(historicalAmount, tc.prevSwapAmount.Add(tc.swapBalance.Amount))

// check correct fee amount
feeCollector := suite.app.AccountKeeper.GetModuleAddress(authtypes.FeeCollectorName)
feeCollectorBalance := suite.app.BankKeeper.GetBalance(suite.ctx, feeCollector, "ukex")
suite.Require().Equal(feeCollectorBalance.Amount, sdk.NewDecFromInt(tc.swapBalance.Amount).Mul(basket.SwapFee).RoundInt())

// check correct slippage amount + surplus
suite.Require().True(sdk.Coins(savedBasket.Surplus).Sub(basket.Surplus...).IsAllPositive())
}
Expand Down

0 comments on commit 6b8a97e

Please sign in to comment.