Skip to content

Commit

Permalink
move fee check after we ensure there is someone to pay too (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups authored Jan 26, 2023
1 parent 08a5709 commit 1401967
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions x/feeshare/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (fsd FeeSharePayoutDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
// tested in ante_test.go
func FeePayLogic(fees sdk.Coins, govPercent sdk.Dec, numPairs int) sdk.Coins {
var splitFees sdk.Coins
for _, c := range fees {
for _, c := range fees.Sort() {
rewardAmount := govPercent.MulInt(c.Amount).QuoInt64(int64(numPairs)).RoundInt()
if !rewardAmount.IsZero() {
splitFees = splitFees.Add(sdk.NewCoin(c.Denom, rewardAmount))
Expand All @@ -60,22 +60,6 @@ func FeeSharePayout(ctx sdk.Context, bankKeeper BankKeeper, totalFees sdk.Coins,
return nil
}

// Get only allowed governance fees to be paid (helps for taxes)
// Juno v13 will have a globalFee for setting more allowed denoms later.
var fees sdk.Coins
if len(params.AllowedDenoms) == 0 {
// If empty, we allow all denoms to be used as payment
fees = totalFees
} else {
for _, fee := range totalFees {
for _, allowed := range params.AllowedDenoms {
if fee.Denom == allowed {
fees = fees.Add(fee)
}
}
}
}

// Get valid withdraw addresses from contracts
toPay := make([]sdk.AccAddress, 0)
for _, msg := range msgs {
Expand All @@ -94,6 +78,26 @@ func FeeSharePayout(ctx sdk.Context, bankKeeper BankKeeper, totalFees sdk.Coins,
}
}

// Do nothing if no one needs payment
if len(toPay) == 0 {
return nil
}

// Get only allowed governance fees to be paid (helps for taxes)
var fees sdk.Coins
if len(params.AllowedDenoms) == 0 {
// If empty, we allow all denoms to be used as payment
fees = totalFees
} else {
for _, fee := range totalFees.Sort() {
for _, allowed := range params.AllowedDenoms {
if fee.Denom == allowed {
fees = fees.Add(fee)
}
}
}
}

// FeeShare logic payouts for contracts
numPairs := len(toPay)
if numPairs > 0 {
Expand Down

0 comments on commit 1401967

Please sign in to comment.