Skip to content

Commit

Permalink
[v18] x/FeePay Module (#808)
Browse files Browse the repository at this point in the history
* comments

* decorator

* Base POC setup

* Create FeePrepay Module,
Override SDK Deduct Fee Decorator,
Plan to move logic

* Send funds to user on zero fee tx

* Transfer funds between modules (incomplete)

* Handle Transfer Errors

* Move ante to x/feepay

* Add FeePay keeper

* Add example contract and script for fee pay

* fix errors

* Hook Keeper Into Ante,
Start Work on Proto (copy from FeeShare)

* Register FeePay Module,
Add Tx for Registering Contract,
Update Ante to Handle FeePay Contracts,
Etc.

* Add BondDenom to ante

* Cover exact fee

* Start fund contract tx

* Add bond denom from main

* Update Fund CLI

* Fund Contract via User Wallet

* Fix contract funding,
Add contract querying

* Implement Contract Query Pagination

* Code cleanup,
Register fee pay errors

* Implement wallet limits,
Update ante to deduct contract balance

* Query if wallet is eligible,
Add admin checks on contract registration

* Improve ante error messages

* Add Tx for Unregistering Contract (WIP)

* Fix refund account address

* Add Tx Msg Validation

* Add bech32 validation to queries

* Update wallet limit bounds

* Refactor queries, txs, & keeper

* Add Tx for Updating Wallet Limit

* Add Params & Genesis Integration

* Prevent FeePay Tx in Ante when Disabled

* add base test

Co-authored-by: Joel Smith <[email protected]>

* Add Tests for Msg Server

* Add Query Tests

* Cleanup Query Response Validation

* Add Genesis Tests

* Add genesis state validation

* Add Contract Registration Helper

* update ictest to latest v7 + PR 810 backport

* add feepay test base

* fix: nil deduct fee if GlobalFee does not contain

* feepay e2e test

* test: globalfee e2e

* feepay v18 namespace

* minor cleanup

* add feepay to v18 upgrade handler

* default disable feepay for all e2e

* only feepayTx check if isEnabled

* fix drip test:: don't be overly assertive

* upgrade test: standalone old version genesis cfg

* go mod tidy

* fix ibc_test int64 -> math.Int cmp

* Adds back POB test (v0.2.1)

* Integrate GlobalFee with FeePay (wip)

* Fix missing zero fee check

* pfm fix test

* lintor

* Refactor Fee Pay Tx Validation

* tidy lint

* Add query err checks

* Use sdk errors

* Force new contract balance of 0

* Removed unused file

* Remove fee pay testing script

* Update query endpoints

* Remove incorrect comment

* Require balance in register contract helper method

* Update proto

* Delete chain state export file

* Removed unused parameter

* Remove contract balance check for eligiblity

* lintor

* Update Msg Server Endpoints

* ictest v7 latest

* remove pob test for now (works, just out of date)

* adds back feepay e2e

---------

Co-authored-by: Joel Smith <[email protected]>
  • Loading branch information
Reecepbcups and joelsmith-2019 authored Oct 24, 2023
1 parent 9d283e6 commit 7c67450
Show file tree
Hide file tree
Showing 62 changed files with 10,420 additions and 236 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/interchaintest-E2E.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ jobs:
- "ictest-tokenfactory"
- "ictest-feeshare"
- "ictest-pfm"
- "ictest-globalfee"
- "ictest-upgrade"
- "ictest-ibc"
- "ictest-unity-deploy"
- "ictest-unity-gov"
- "ictest-pob"
- "ictest-drip"
- "ictest-feepay"
- "ictest-burn"
- "ictest-cwhooks"
- "ictest-clock"
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ ictest-feeshare: rm-testcache
ictest-pfm: rm-testcache
cd interchaintest && go test -race -v -run TestPacketForwardMiddlewareRouter .

ictest-globalfee: rm-testcache
cd interchaintest && go test -race -v -run TestJunoGlobalFee .

# Executes a basic chain upgrade test via interchaintest
ictest-upgrade: rm-testcache
cd interchaintest && go test -race -v -run TestBasicJunoUpgrade .
Expand All @@ -163,6 +166,9 @@ ictest-pob: rm-testcache
ictest-drip: rm-testcache
cd interchaintest && go test -race -v -run TestJunoDrip .

ictest-feepay: rm-testcache
cd interchaintest && go test -race -v -run TestJunoFeePay .

ictest-burn: rm-testcache
cd interchaintest && go test -race -v -run TestJunoBurnModule .

Expand Down
15 changes: 11 additions & 4 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"

decorators "github.com/CosmosContracts/juno/v18/app/decorators"
feepayante "github.com/CosmosContracts/juno/v18/x/feepay/ante"
feepaykeeper "github.com/CosmosContracts/juno/v18/x/feepay/keeper"
feeshareante "github.com/CosmosContracts/juno/v18/x/feeshare/ante"
feesharekeeper "github.com/CosmosContracts/juno/v18/x/feeshare/keeper"
globalfeeante "github.com/CosmosContracts/juno/v18/x/globalfee/ante"
Expand All @@ -36,8 +39,9 @@ type HandlerOptions struct {

GovKeeper govkeeper.Keeper
IBCKeeper *ibckeeper.Keeper
FeePayKeeper feepaykeeper.Keeper
FeeShareKeeper feesharekeeper.Keeper
BankKeeperFork feeshareante.BankKeeper
BankKeeper bankkeeper.Keeper
TxCounterStoreKey storetypes.StoreKey
WasmConfig wasmtypes.WasmConfig
Cdc codec.BinaryCodec
Expand All @@ -50,6 +54,8 @@ type HandlerOptions struct {
BuilderKeeper builderkeeper.Keeper
TxEncoder sdk.TxEncoder
Mempool builderante.Mempool

BondDenom string
}

// NewAnteHandler returns an AnteHandler that checks and increments sequence
Expand All @@ -74,6 +80,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
}

anteDecorators := []sdk.AnteDecorator{
// GLobalFee query params for minimum fee
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit),
wasmkeeper.NewCountTXDecorator(options.TxCounterStoreKey),
Expand All @@ -83,9 +90,9 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
globalfeeante.NewFeeDecorator(options.BypassMinFeeMsgTypes, options.GlobalFeeKeeper, options.StakingKeeper, maxBypassMinFeeMsgGasUsage),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
feeshareante.NewFeeSharePayoutDecorator(options.BankKeeperFork, options.FeeShareKeeper),
globalfeeante.NewFeeDecorator(options.BypassMinFeeMsgTypes, options.GlobalFeeKeeper, options.StakingKeeper, options.FeePayKeeper, maxBypassMinFeeMsgGasUsage),
feepayante.NewDeductFeeDecorator(options.FeePayKeeper, options.GlobalFeeKeeper, options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.BondDenom),
feeshareante.NewFeeSharePayoutDecorator(options.BankKeeper, options.FeeShareKeeper),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
Expand Down
5 changes: 4 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ func New(
keepers.GetMaccPerms(),
appOpts,
wasmOpts,
app.GetChainBondDenom(),
)
app.keys = app.AppKeepers.GetKVStoreKey()

Expand Down Expand Up @@ -344,8 +345,9 @@ func New(

GovKeeper: app.AppKeepers.GovKeeper,
IBCKeeper: app.AppKeepers.IBCKeeper,
FeePayKeeper: app.AppKeepers.FeePayKeeper,
FeeShareKeeper: app.AppKeepers.FeeShareKeeper,
BankKeeperFork: app.AppKeepers.BankKeeper, // since we need extra methods
BankKeeper: app.AppKeepers.BankKeeper,
TxCounterStoreKey: app.AppKeepers.GetKey(wasmtypes.StoreKey),
WasmConfig: wasmConfig,
Cdc: appCodec,
Expand All @@ -357,6 +359,7 @@ func New(
TxEncoder: app.txConfig.TxEncoder(),
BuilderKeeper: app.AppKeepers.BuildKeeper,
Mempool: mempool,
BondDenom: app.GetChainBondDenom(),
},
)
if err != nil {
Expand Down
23 changes: 17 additions & 6 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ import (
cwhookstypes "github.com/CosmosContracts/juno/v18/x/cw-hooks/types"
dripkeeper "github.com/CosmosContracts/juno/v18/x/drip/keeper"
driptypes "github.com/CosmosContracts/juno/v18/x/drip/types"
feepaykeeper "github.com/CosmosContracts/juno/v18/x/feepay/keeper"
feepaytypes "github.com/CosmosContracts/juno/v18/x/feepay/types"
feesharekeeper "github.com/CosmosContracts/juno/v18/x/feeshare/keeper"
feesharetypes "github.com/CosmosContracts/juno/v18/x/feeshare/types"
"github.com/CosmosContracts/juno/v18/x/globalfee"
Expand Down Expand Up @@ -128,6 +130,7 @@ var maccPerms = map[string][]string{
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
globalfee.ModuleName: nil,
buildertypes.ModuleName: nil,
feepaytypes.ModuleName: nil,
junoburn.ModuleName: {authtypes.Burner},
}

Expand Down Expand Up @@ -160,6 +163,7 @@ type AppKeepers struct {
AuthzKeeper authzkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
NFTKeeper nftkeeper.Keeper
FeePayKeeper feepaykeeper.Keeper
FeeShareKeeper feesharekeeper.Keeper
GlobalFeeKeeper globalfeekeeper.Keeper
ContractKeeper wasmtypes.ContractOpsKeeper
Expand Down Expand Up @@ -197,6 +201,7 @@ func NewAppKeepers(
maccPerms map[string][]string,
appOpts servertypes.AppOptions,
wasmOpts []wasmkeeper.Option,
bondDenom string,
) AppKeepers {
appKeepers := AppKeepers{}

Expand Down Expand Up @@ -542,6 +547,16 @@ func NewAppKeepers(
wasmOpts...,
)

appKeepers.FeePayKeeper = feepaykeeper.NewKeeper(
appKeepers.keys[feepaytypes.StoreKey],
appCodec,
&appKeepers.BankKeeper,
appKeepers.WasmKeeper,
appKeepers.AccountKeeper,
bondDenom,
govModAddress,
)

// set the contract keeper for the Ics20WasmHooks
appKeepers.ContractKeeper = wasmkeeper.NewDefaultPermissionKeeper(&appKeepers.WasmKeeper)
appKeepers.Ics20WasmHooks.ContractKeeper = &appKeepers.WasmKeeper
Expand Down Expand Up @@ -725,16 +740,12 @@ func BlockedAddresses() map[string]bool {

// allow the following addresses to receive funds
delete(modAccAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String())
delete(modAccAddrs, authtypes.NewModuleAddress(feepaytypes.ModuleName).String())

return modAccAddrs
}

// GetMaccPerms returns a copy of the module account permissions
func GetMaccPerms() map[string][]string {
dupMaccPerms := make(map[string][]string)
for k, v := range maccPerms {
dupMaccPerms[k] = v
}

return dupMaccPerms
return maccPerms
}
2 changes: 2 additions & 0 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
clocktypes "github.com/CosmosContracts/juno/v18/x/clock/types"
cwhookstypes "github.com/CosmosContracts/juno/v18/x/cw-hooks/types"
driptypes "github.com/CosmosContracts/juno/v18/x/drip/types"
feepaytypes "github.com/CosmosContracts/juno/v18/x/feepay/types"
feesharetypes "github.com/CosmosContracts/juno/v18/x/feeshare/types"
globalfeetypes "github.com/CosmosContracts/juno/v18/x/globalfee/types"
minttypes "github.com/CosmosContracts/juno/v18/x/mint/types"
Expand All @@ -55,6 +56,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
packetforwardtypes.StoreKey,
ibchookstypes.StoreKey,
tokenfactorytypes.StoreKey,
feepaytypes.StoreKey,
feesharetypes.StoreKey,
globalfeetypes.StoreKey,
buildertypes.StoreKey,
Expand Down
8 changes: 8 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ import (
cwhooks "github.com/CosmosContracts/juno/v18/x/cw-hooks"
"github.com/CosmosContracts/juno/v18/x/drip"
driptypes "github.com/CosmosContracts/juno/v18/x/drip/types"
feepay "github.com/CosmosContracts/juno/v18/x/feepay"
feepaytypes "github.com/CosmosContracts/juno/v18/x/feepay/types"
feeshare "github.com/CosmosContracts/juno/v18/x/feeshare"
feesharetypes "github.com/CosmosContracts/juno/v18/x/feeshare/types"
"github.com/CosmosContracts/juno/v18/x/globalfee"
Expand Down Expand Up @@ -107,6 +109,7 @@ var ModuleBasics = module.NewBasicManager(
feegrantmodule.AppModuleBasic{},
tokenfactory.AppModuleBasic{},
drip.AppModuleBasic{},
feepay.AppModuleBasic{},
feeshare.AppModuleBasic{},
globalfee.AppModuleBasic{},
ibc_hooks.AppModuleBasic{},
Expand Down Expand Up @@ -152,6 +155,7 @@ func appModules(
ibcfee.NewAppModule(app.AppKeepers.IBCFeeKeeper),
tokenfactory.NewAppModule(app.AppKeepers.TokenFactoryKeeper, app.AppKeepers.AccountKeeper, app.AppKeepers.BankKeeper, app.GetSubspace(tokenfactorytypes.ModuleName)),
globalfee.NewAppModule(appCodec, app.AppKeepers.GlobalFeeKeeper, bondDenom),
feepay.NewAppModule(app.AppKeepers.FeePayKeeper, app.AppKeepers.AccountKeeper),
feeshare.NewAppModule(app.AppKeepers.FeeShareKeeper, app.AppKeepers.AccountKeeper, app.GetSubspace(feesharetypes.ModuleName)),
wasm.NewAppModule(appCodec, &app.AppKeepers.WasmKeeper, app.AppKeepers.StakingKeeper, app.AppKeepers.AccountKeeper, app.AppKeepers.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
ica.NewAppModule(&app.AppKeepers.ICAControllerKeeper, &app.AppKeepers.ICAHostKeeper),
Expand Down Expand Up @@ -194,6 +198,7 @@ func simulationModules(
wasm.NewAppModule(appCodec, &app.AppKeepers.WasmKeeper, app.AppKeepers.StakingKeeper, app.AppKeepers.AccountKeeper, app.AppKeepers.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
ibc.NewAppModule(app.AppKeepers.IBCKeeper),
transfer.NewAppModule(app.AppKeepers.TransferKeeper),
feepay.NewAppModule(app.AppKeepers.FeePayKeeper, app.AppKeepers.AccountKeeper),
feeshare.NewAppModule(app.AppKeepers.FeeShareKeeper, app.AppKeepers.AccountKeeper, app.GetSubspace(feesharetypes.ModuleName)),
ibcfee.NewAppModule(app.AppKeepers.IBCFeeKeeper),
}
Expand Down Expand Up @@ -231,6 +236,7 @@ func orderBeginBlockers() []string {
icqtypes.ModuleName,
tokenfactorytypes.ModuleName,
driptypes.ModuleName,
feepaytypes.ModuleName,
feesharetypes.ModuleName,
globalfee.ModuleName,
wasmtypes.ModuleName,
Expand Down Expand Up @@ -270,6 +276,7 @@ func orderEndBlockers() []string {
icqtypes.ModuleName,
tokenfactorytypes.ModuleName,
driptypes.ModuleName,
feepaytypes.ModuleName,
feesharetypes.ModuleName,
globalfee.ModuleName,
wasmtypes.ModuleName,
Expand Down Expand Up @@ -309,6 +316,7 @@ func orderInitBlockers() []string {
icqtypes.ModuleName,
tokenfactorytypes.ModuleName,
driptypes.ModuleName,
feepaytypes.ModuleName,
feesharetypes.ModuleName,
globalfee.ModuleName,
wasmtypes.ModuleName,
Expand Down
2 changes: 2 additions & 0 deletions app/upgrades/v18/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/CosmosContracts/juno/v18/app/upgrades"
cwhooks "github.com/CosmosContracts/juno/v18/x/cw-hooks"
feepaytypes "github.com/CosmosContracts/juno/v18/x/feepay/types"
)

// UpgradeName defines the on-chain upgrade name for the upgrade.
Expand All @@ -16,6 +17,7 @@ var Upgrade = upgrades.Upgrade{
StoreUpgrades: store.StoreUpgrades{
Added: []string{
cwhooks.ModuleName,
feepaytypes.ModuleName,
},
},
}
8 changes: 8 additions & 0 deletions app/upgrades/v18/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/CosmosContracts/juno/v18/app/keepers"
"github.com/CosmosContracts/juno/v18/app/upgrades"
cwhookstypes "github.com/CosmosContracts/juno/v18/x/cw-hooks/types"
feepaytypes "github.com/CosmosContracts/juno/v18/x/feepay/types"
)

func CreateV18UpgradeHandler(
Expand Down Expand Up @@ -37,6 +38,13 @@ func CreateV18UpgradeHandler(
return nil, err
}

// x/feepay
if err := k.FeePayKeeper.SetParams(ctx, feepaytypes.Params{
EnableFeepay: true,
}); err != nil {
return nil, err
}

return versionMap, err
}
}
27 changes: 12 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ require (
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/cockroachdb/errors v1.10.0 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/getsentry/sentry-go v0.23.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
)

require (
cloud.google.com/go v0.110.4 // indirect
cloud.google.com/go/compute v1.21.0 // indirect
Expand All @@ -68,6 +58,9 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
github.com/cockroachdb/errors v1.10.0 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
Expand All @@ -91,6 +84,7 @@ require (
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/getsentry/sentry-go v0.23.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
Expand Down Expand Up @@ -131,6 +125,8 @@ require (
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.16.3 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.7.16 // indirect
Expand All @@ -155,6 +151,7 @@ require (
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rakyll/statik v0.1.7 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/rs/zerolog v1.30.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
Expand All @@ -170,14 +167,14 @@ require (
github.com/zondax/ledger-go v0.14.1 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.126.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
Loading

0 comments on commit 7c67450

Please sign in to comment.