Skip to content

Commit

Permalink
Cover exact fee
Browse files Browse the repository at this point in the history
  • Loading branch information
joelsmith-2019 committed Sep 1, 2023
1 parent 4d558ea commit 282301f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
30 changes: 23 additions & 7 deletions x/feepay/ante/dedcuct_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,38 @@ func (dfd DeductFeeDecorator) handleZeroFees(ctx sdk.Context, deductFeesFromAcc
return sdkerrors.ErrInvalidRequest.Wrapf("contract %s is not registered for fee pay", cw.GetContract())
}

// TODO: instead of hardcoding payment, GetGas() * globalFeeParam.GetParams(ctx).MinimumGasPrices of ujuno or ujunox (app.GetDenom() func).
// feeTx := tx.(sdk.FeeTx)
// gas := feeTx.GetGas()
// Get the fee price in the chain denom
var feePrice sdk.DecCoin
for _, c := range dfd.globalfeeKeeper.GetParams(ctx).MinimumGasPrices {
if c.Denom == dfd.bondDenom {
feePrice = c
}
}

ctx.Logger().Error("HandleZeroFees", "FeePrice", feePrice)

// Get the tx gas
feeTx := tx.(sdk.FeeTx)
gas := sdkmath.LegacyNewDec(int64(feeTx.GetGas()))

ctx.Logger().Error("HandleZeroFees", "Gas", gas)

requiredFee := feePrice.Amount.Mul(gas).Ceil().RoundInt()

ctx.Logger().Error("HandleZeroFees", "RequiredFee", requiredFee)

payment := sdk.NewCoins(sdk.NewCoin("ujuno", sdk.NewDec(500_000).RoundInt()))
// Create an array of coins, storing the required fee
payment := sdk.NewCoins(sdk.NewCoin(feePrice.Denom, requiredFee))

ctx.Logger().Error("HandleZeroFees", "Payment", payment)

// keeper.SendCoinsFromModuleToAccount(ctx, "feeprepay", deductFeesFromAcc.GetAddress(), payment)
// Cover the fees of the transaction, send from FeePay Module to FeeCollector Module
err := dfd.bankKeeper.SendCoinsFromModuleToModule(ctx, feepaytypes.ModuleName, types.FeeCollectorName, payment)

// Handle error
// Throw transfer errors
if err != nil {
ctx.Logger().Error("HandleZeroFees", "Error transfering funds from module to module", err)
return sdkerrors.ErrInsufficientFunds.Wrapf("error transfering funds from module to module: %s", err)
// return nil
}

ctx.Logger().Error("HandleZeroFees", "Ending", true)
Expand Down
9 changes: 0 additions & 9 deletions x/feepay/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,3 @@ func (k Keeper) RegisterContract(ctx sdk.Context, fpc types.FeePayContract) bool
// Return true by default (for now)
return true
}

// FeeShare - how to do a map. store.Get()

// KV
// -> KVs `string -> []bytes`
// Store users interactions on a contract -> int
// "user-interaction" < key
// "userAddr-contractAddr" -> []byte(1)
// feeshare.go < how to do kvs

0 comments on commit 282301f

Please sign in to comment.