Skip to content

Commit

Permalink
Fix MultiSend handling (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
StrathCole authored Jan 9, 2025
1 parent 56fd846 commit 43409f5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions x/tax/handlers/bank_msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *BankMsgServer) Send(ctx context.Context, msg *banktypes.MsgSend) (*bank
fromAddr := sdk.MustAccAddressFromBech32(msg.FromAddress)

if !s.treasuryKeeper.HasBurnTaxExemptionAddress(sdkCtx, msg.FromAddress, msg.ToAddress) {
netAmount, err := s.taxKeeper.DeductTax(sdkCtx, fromAddr, msg.Amount)
netAmount, err := s.taxKeeper.DeductTax(sdkCtx, fromAddr, msg.Amount, false)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -76,7 +76,7 @@ func (s *BankMsgServer) MultiSend(ctx context.Context, msg *banktypes.MsgMultiSe
if tainted {
for i, input := range msg.Inputs {
fromAddr := sdk.MustAccAddressFromBech32(input.Address)
netCoins, err := s.taxKeeper.DeductTax(sdkCtx, fromAddr, input.Coins)
netCoins, err := s.taxKeeper.DeductTax(sdkCtx, fromAddr, input.Coins, false)
if err != nil {
return nil, err
}
Expand All @@ -85,7 +85,7 @@ func (s *BankMsgServer) MultiSend(ctx context.Context, msg *banktypes.MsgMultiSe

for i, output := range msg.Outputs {
toAddr := sdk.MustAccAddressFromBech32(output.Address)
netCoins, err := s.taxKeeper.DeductTax(sdkCtx, toAddr, output.Coins)
netCoins, err := s.taxKeeper.DeductTax(sdkCtx, toAddr, output.Coins, true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion x/tax/handlers/market_msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *MarketMsgServer) SwapSend(ctx context.Context, msg *markettypes.MsgSwap

sender := sdk.MustAccAddressFromBech32(msg.FromAddress)

netOfferCoin, err := s.taxKeeper.DeductTax(sdkCtx, sender, sdk.NewCoins(msg.OfferCoin))
netOfferCoin, err := s.taxKeeper.DeductTax(sdkCtx, sender, sdk.NewCoins(msg.OfferCoin), false)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions x/tax/handlers/wasm_msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *WasmMsgServer) ExecuteContract(ctx context.Context, msg *wasmtypes.MsgE
sender := sdk.MustAccAddressFromBech32(msg.Sender)
if !s.treasuryKeeper.HasBurnTaxExemptionContract(sdkCtx, msg.Contract) {
netFunds, err := s.taxKeeper.DeductTax(sdkCtx, sender, msg.Funds)
netFunds, err := s.taxKeeper.DeductTax(sdkCtx, sender, msg.Funds, false)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func (s *WasmMsgServer) InstantiateContract(ctx context.Context, msg *wasmtypes.
sender := sdk.MustAccAddressFromBech32(msg.Sender)
netFunds, err := s.taxKeeper.DeductTax(sdkCtx, sender, msg.Funds)
netFunds, err := s.taxKeeper.DeductTax(sdkCtx, sender, msg.Funds, false)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func (s *WasmMsgServer) InstantiateContract2(ctx context.Context, msg *wasmtypes
sender := sdk.MustAccAddressFromBech32(msg.Sender)
netFunds, err := s.taxKeeper.DeductTax(sdkCtx, sender, msg.Funds)
netFunds, err := s.taxKeeper.DeductTax(sdkCtx, sender, msg.Funds, false)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion x/tax/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (k Keeper) DeductTax(
ctx sdk.Context,
sender sdk.AccAddress,
amount sdk.Coins,
skipDeduct bool,
) (sdk.Coins, error) {
ctx.Logger().Info("Deducting tax", "sender", sender, "amount", amount, ctx.Value(types.ContextKeyTaxReverseCharge))

Expand All @@ -107,7 +108,7 @@ func (k Keeper) DeductTax(
taxes := k.ComputeTax(ctx, amount)
netAmount := amount.Sub(taxes...)

if !taxes.IsZero() {
if !taxes.IsZero() && !skipDeduct {
// Deduct the total tax amount from the sender and send to FeeCollector
if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, authtypes.FeeCollectorName, taxes); err != nil {
return nil, err
Expand Down

0 comments on commit 43409f5

Please sign in to comment.