diff --git a/api/exocore/feedistribute/module/module.pulsar.go b/api/exocore/feedistribute/module/module.pulsar.go deleted file mode 100644 index b0b78bfd7..000000000 --- a/api/exocore/feedistribute/module/module.pulsar.go +++ /dev/null @@ -1 +0,0 @@ -package module diff --git a/go.mod b/go.mod index 13d729653..fe8bdcf35 100644 --- a/go.mod +++ b/go.mod @@ -47,7 +47,7 @@ require ( ) require ( - cosmossdk.io/api v0.3.1 + cosmossdk.io/api v0.7.0 github.com/btcsuite/btcd v0.23.3 // indirect github.com/btcsuite/btcd/btcutil v1.1.3 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect @@ -68,13 +68,15 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v1.1.5 // indirect cloud.google.com/go/storage v1.35.1 // indirect - cosmossdk.io/core v0.6.1 // indirect + cosmossdk.io/collections v0.4.0 // indirect + cosmossdk.io/core v0.10.0 // indirect cosmossdk.io/depinject v1.0.0-alpha.4 // indirect cosmossdk.io/log v1.3.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect + github.com/DataDog/zstd v1.5.5 // indirect github.com/VictoriaMetrics/fastcache v1.12.1 // indirect github.com/aws/aws-sdk-go v1.44.224 // indirect github.com/beorn7/perks v1.0.1 // indirect @@ -89,9 +91,12 @@ require ( 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/pebble v0.0.0-20230928194634-aa077af62593 // indirect github.com/cockroachdb/redact v1.1.5 // indirect + github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect github.com/confio/ics23/go v0.9.0 // indirect + github.com/cosmos/cosmos-db v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/iavl v0.20.1 // indirect github.com/cosmos/ics23/go v0.10.0 // indirect @@ -242,7 +247,7 @@ require ( gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/yaml.v3 v3.0.1 // indirect nhooyr.io/websocket v1.8.7 // indirect - pgregory.net/rapid v0.5.5 // indirect + pgregory.net/rapid v1.1.0 // indirect ) replace ( diff --git a/go.sum b/go.sum index 60d3413c1..07e367757 100644 --- a/go.sum +++ b/go.sum @@ -519,8 +519,14 @@ cloud.google.com/go/workflows v1.9.0/go.mod h1:ZGkj1aFIOd9c8Gerkjjq7OW7I5+l6cSvT cloud.google.com/go/workflows v1.10.0/go.mod h1:fZ8LmRmZQWacon9UCX1r/g/DfAXx5VcPALq2CxzdePw= cosmossdk.io/api v0.3.1 h1:NNiOclKRR0AOlO4KIqeaG6PS6kswOMhHD0ir0SscNXE= cosmossdk.io/api v0.3.1/go.mod h1:DfHfMkiNA2Uhy8fj0JJlOCYOBp4eWUUJ1te5zBGNyIw= +cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4= +cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M= +cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= +cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.6.1 h1:OBy7TI2W+/gyn2z40vVvruK3di+cAluinA6cybFbE7s= cosmossdk.io/core v0.6.1/go.mod h1:g3MMBCBXtxbDWBURDVnJE7XML4BG5qENhs0gzkcpuFA= +cosmossdk.io/core v0.10.0 h1:NP28Ol9YyRODmZLJg2ko/mUl40hMegeMzhJnG+XPkcY= +cosmossdk.io/core v0.10.0/go.mod h1:MygXNld9DvMgYY4yE76DM/mdZpgfeyRjy6FPjEEehlY= cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc= cosmossdk.io/depinject v1.0.0-alpha.4/go.mod h1:HeDk7IkR5ckZ3lMGs/o91AVUc7E596vMaOmslGFM3yU= cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= @@ -545,6 +551,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM= github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= +github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ= +github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/ExocoreNetwork/evmos/v14 v14.1.1-0.20240408040728-a6f685cfebb9 h1:/jL9TiINGniPOG2bRfLmyCFSwMy/vFZ1Ta0OoE+xJaE= github.com/ExocoreNetwork/evmos/v14 v14.1.1-0.20240408040728-a6f685cfebb9/go.mod h1:Hi3CAMxAE+H7Fs7sSHsHKb4DZIURk+trop+mMrjlZqw= github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk= @@ -697,8 +705,12 @@ github.com/cockroachdb/errors v1.10.0 h1:lfxS8zZz1+OjtV4MtNWgboi/W5tyLEB6VQZBXN+ github.com/cockroachdb/errors v1.10.0/go.mod h1:lknhIsEVQ9Ss/qKDBQS/UqFSvPQjOwNq2qyKAxtHRqE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= +github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 h1:aPEJyR4rPBvDmeyi+l/FS/VtA00IWvjeFvjen1m1l1A= +github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593/go.mod h1:6hk1eMY/u5t+Cf18q5lFMUA1Rc+Sm5I6Ra1QuPyxXCo= github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= +github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= +github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/coinbase/rosetta-sdk-go/types v1.0.0 h1:jpVIwLcPoOeCR6o1tU+Xv7r5bMONNbHU7MuEHboiFuA= github.com/coinbase/rosetta-sdk-go/types v1.0.0/go.mod h1:eq7W2TMRH22GTW0N0beDnN931DW0/WOI1R2sdHNHG4c= @@ -718,6 +730,8 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk= github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis= +github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0E= +github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U= github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o= github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= @@ -2405,6 +2419,7 @@ nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g= nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= pgregory.net/rapid v0.5.5 h1:jkgx1TjbQPD/feRoK+S/mXw9e1uj6WilpHrXJowi6oA= pgregory.net/rapid v0.5.5/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= +pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= diff --git a/proto/exocore/feedistribute/genesis.proto b/proto/exocore/feedistribute/genesis.proto index 5dd186988..6e24fa20d 100644 --- a/proto/exocore/feedistribute/genesis.proto +++ b/proto/exocore/feedistribute/genesis.proto @@ -14,9 +14,4 @@ message GenesisState { (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; - // period is the amount of past periods, based on the epochs per period param - uint64 period = 2; - // epoch_identifier for fee distribution - string epoch_identifier = 3; - } diff --git a/proto/exocore/feedistribute/params.proto b/proto/exocore/feedistribute/params.proto index b4dae5b1c..00d5dfe02 100644 --- a/proto/exocore/feedistribute/params.proto +++ b/proto/exocore/feedistribute/params.proto @@ -9,5 +9,8 @@ option go_package = "github.com/ExocoreNetwork/exocore/x/feedistribution/types"; // Params defines the parameters for the module. message Params { option (amino.name) = "exocore/x/feedistribution/Params"; - option (gogoproto.equal) = true; + // period is the amount of past periods, based on the epochs per period param + uint64 period = 1; + // epoch_identifier for fee distribution + string epoch_identifier = 2; } \ No newline at end of file diff --git a/x/exomint/types/query.pb.gw.go b/x/exomint/types/query.pb.gw.go index d8e094f7e..c9413d3e6 100644 --- a/x/exomint/types/query.pb.gw.go +++ b/x/exomint/types/query.pb.gw.go @@ -20,7 +20,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -31,7 +30,6 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage -var _ = metadata.Join func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryParamsRequest @@ -54,14 +52,12 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -69,7 +65,6 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) diff --git a/x/exomint/types/tx.pb.gw.go b/x/exomint/types/tx.pb.gw.go index 4d66aadbe..9a54ea79f 100644 --- a/x/exomint/types/tx.pb.gw.go +++ b/x/exomint/types/tx.pb.gw.go @@ -20,7 +20,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -31,7 +30,6 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage -var _ = metadata.Join var ( filter_Msg_UpdateParams_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} @@ -72,14 +70,12 @@ func local_request_Msg_UpdateParams_0(ctx context.Context, marshaler runtime.Mar // RegisterMsgHandlerServer registers the http handlers for service Msg to "mux". // UnaryRPC :call MsgServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterMsgHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterMsgHandlerFromEndpoint instead. func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server MsgServer) error { mux.Handle("POST", pattern_Msg_UpdateParams_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -87,7 +83,6 @@ func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server return } resp, md, err := local_request_Msg_UpdateParams_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) diff --git a/x/feedistribution/client/cli/query.go b/x/feedistribution/client/cli/query.go new file mode 100644 index 000000000..774dee486 --- /dev/null +++ b/x/feedistribution/client/cli/query.go @@ -0,0 +1,47 @@ +package cli + +import ( + "fmt" + "github.com/ExocoreNetwork/exocore/x/feedistribution/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(_ string) *cobra.Command { + // Group fee distirbution queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(QueryDistritbutionInfo()) + return cmd +} + +func QueryDistritbutionInfo() *cobra.Command { + cmd := &cobra.Command{ + Use: "DistributionInfo query", + Short: "DistributionInfo query", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + return cmd +} diff --git a/x/feedistribution/client/cli/tx.go b/x/feedistribution/client/cli/tx.go new file mode 100644 index 000000000..a1264ca17 --- /dev/null +++ b/x/feedistribution/client/cli/tx.go @@ -0,0 +1,20 @@ +package cli + +import ( + "fmt" + "github.com/ExocoreNetwork/exocore/x/feedistribution/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + return cmd +} diff --git a/x/feedistribution/keeper/allocation.go b/x/feedistribution/keeper/allocation.go new file mode 100644 index 000000000..baf7b5b71 --- /dev/null +++ b/x/feedistribution/keeper/allocation.go @@ -0,0 +1,101 @@ +package keeper + +import ( + "cosmossdk.io/collections" + "github.com/ExocoreNetwork/exocore/x/feedistribution/types" + operatortype "github.com/ExocoreNetwork/exocore/x/operator/types" + sdk "github.com/cosmos/cosmos-sdk/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" +) + +func (k Keeper) AllocateTokens(ctx sdk.Context, totalPreviousPower int64) error { + feeCollector := k.authKeeper.GetModuleAccount(ctx, k.feeCollectorName) + feesCollectedInt := k.bankKeeper.GetAllBalances(ctx, feeCollector.GetAddress()) + feesCollected := sdk.NewDecCoinsFromCoins(feesCollectedInt...) + // transfer collected fees to the distribution module account + if err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, k.feeCollectorName, types.ModuleName, feesCollectedInt); err != nil { + return err + } + feePool, err := k.FeePool.Get(ctx) + if err != nil { + return err + } + if totalPreviousPower == 0 { + if err := k.FeePool.Set(ctx, distrtypes.FeePool{CommunityPool: feePool.CommunityPool.Add(feesCollected...)}); err != nil { + return err + } + } + // calculate fraction allocated to validators + remaining := feesCollected + communityTax, err := k.GetCommunityTax(ctx) + if err != nil { + return err + } + + // allocate tokens proportionally to voting power of different validators + + +} + +// AllocateTokensToValidator allocate tokens to a particular validator, +// splitting according to commission. +func (k Keeper) AllocateTokensToValidator(ctx sdk.Context, val operatortype.OperatorInfo, tokens sdk.DecCoins) error { + // split tokens between validator and delegators according to commission + rate := val.GetCommission().Rate + commission := tokens.MulDec(rate) + shared := tokens.Sub(commission) + + valBz, err := k.StakingKeeper.GetExocoreValidator() vali ValidatorAddressCodec().StringToBytes(val.GetOperator()) + if err != nil { + return err + } + + // update current commission + if err = k.EventService.EventManager(ctx).EmitKV( + types.EventTypeCommission, + event.NewAttribute(sdk.AttributeKeyAmount, commission.String()), + event.NewAttribute(types.AttributeKeyValidator, val.GetOperator()), + ); err != nil { + return err + } + currentCommission, err := k.ValidatorsAccumulatedCommission.Get(ctx, valBz) + if err != nil && !errors.Is(err, collections.ErrNotFound) { + return err + } + + currentCommission.Commission = currentCommission.Commission.Add(commission...) + err = k.ValidatorsAccumulatedCommission.Set(ctx, valBz, currentCommission) + if err != nil { + return err + } + + // update current rewards + currentRewards, err := k.ValidatorCurrentRewards.Get(ctx, valBz) + // if the rewards do not exist it's fine, we will just add to zero. + if err != nil && !errors.Is(err, collections.ErrNotFound) { + return err + } + + currentRewards.Rewards = currentRewards.Rewards.Add(shared...) + err = k.ValidatorCurrentRewards.Set(ctx, valBz, currentRewards) + if err != nil { + return err + } + + // update outstanding rewards + if err = k.EventService.EventManager(ctx).EmitKV( + types.EventTypeRewards, + event.NewAttribute(sdk.AttributeKeyAmount, tokens.String()), + event.NewAttribute(types.AttributeKeyValidator, val.GetOperator()), + ); err != nil { + return err + } + + outstanding, err := k.ValidatorOutstandingRewards.Get(ctx, valBz) + if err != nil && !errors.Is(err, collections.ErrNotFound) { + return err + } + + outstanding.Rewards = outstanding.Rewards.Add(tokens...) + return k.ValidatorOutstandingRewards.Set(ctx, valBz, outstanding) +} diff --git a/x/feedistribution/keeper/genesis.go b/x/feedistribution/keeper/genesis.go new file mode 100644 index 000000000..f1073e49a --- /dev/null +++ b/x/feedistribution/keeper/genesis.go @@ -0,0 +1,26 @@ +package keeper + +import ( + "fmt" + "github.com/ExocoreNetwork/exocore/x/feedistribution/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// InitGenesis initializes the module's state from a provided genesis state. +func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { + k.SetParams(ctx, genState.Params) + epochID := genState.Params.EpochIdentifier + _, found := k.epochsKeeper.GetEpochInfo(ctx, epochID) + if !found { + // the panic is suitable here because it is being done at genesis, when the node + // is not running. it means that the genesis file is malformed. + panic(fmt.Sprintf("epoch info not found %s", epochID)) + } +} + +// ExportGenesis returns the module's exported genesis +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + genesis := types.DefaultGenesis() + genesis.Params = k.GetParams(ctx) + return genesis +} diff --git a/x/feedistribution/keeper/hooks.go b/x/feedistribution/keeper/hooks.go index 38a1dcaf9..3043e4e8d 100644 --- a/x/feedistribution/keeper/hooks.go +++ b/x/feedistribution/keeper/hooks.go @@ -12,7 +12,6 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumb if epochIdentifier != expEpochID { return } - // the minted coins already be generated by minting module and thus do the token allocation distribution here } diff --git a/x/feedistribution/keeper/keeper.go b/x/feedistribution/keeper/keeper.go index 5bb1a63bd..dc9b2e614 100644 --- a/x/feedistribution/keeper/keeper.go +++ b/x/feedistribution/keeper/keeper.go @@ -3,13 +3,15 @@ package keeper import ( "fmt" storetypes "github.com/cosmos/cosmos-sdk/store/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + collections "cosmossdk.io/collections" "cosmossdk.io/core/store" "cosmossdk.io/log" + stakingkeeper "github.com/ExocoreNetwork/exocore/x/dogfood/keeper" + "github.com/ExocoreNetwork/exocore/x/feedistribution/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/ExocoreNetwork/exocore/x/feedistribution/types" ) type ( @@ -21,9 +23,14 @@ type ( // the address capable of executing a MsgUpdateParams message. Typically, this // should be the x/gov module account. - authority string - - bankKeeper types.BankKeeper + authority string + authKeeper types.AccountKeeper + bankKeeper types.BankKeeper + epochsKeeper types.EpochsKeeper + feeCollectorName string + // FeePool stores decimal tokens that cannot be yet distributed. + FeePool collections.Item[distrtypes.FeePool] + StakingKeeper stakingkeeper.Keeper } ) diff --git a/x/feedistribution/keeper/params.go b/x/feedistribution/keeper/params.go index 4c911579a..b89c52f7d 100644 --- a/x/feedistribution/keeper/params.go +++ b/x/feedistribution/keeper/params.go @@ -1,33 +1,31 @@ package keeper import ( - "context" - - "github.com/cosmos/cosmos-sdk/runtime" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ExocoreNetwork/exocore/x/feedistribution/types" ) // GetParams get all parameters as types.Params -func (k Keeper) GetParams(ctx context.Context) (params types.Params) { - store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) - bz := store.Get(types.ParamsKey) - if bz == nil { - return params - } - +func (k Keeper) GetParams(ctx sdk.Context) types.Params { + store := ctx.KVStore(k.storeKey) + key := types.KeyPrefixParams + bz := store.Get(key) + var params types.Params k.cdc.MustUnmarshal(bz, ¶ms) return params } // SetParams set the params -func (k Keeper) SetParams(ctx context.Context, params types.Params) error { - store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) - bz, err := k.cdc.Marshal(¶ms) - if err != nil { - return err - } - store.Set(types.ParamsKey, bz) +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + store := ctx.KVStore(k.storeKey) + key := types.KeyPrefixParams + bz := k.cdc.MustMarshal(¶ms) + store.Set(key, bz) +} + +// GetCommunityTax returns the current distribution community tax. +func (k Keeper) GetCommunityTax(ctx sdk.Context) (math.LegacyDec, error) { - return nil } diff --git a/x/feedistribution/module/autocli.go b/x/feedistribution/module/autocli.go deleted file mode 100644 index 6a74f169e..000000000 --- a/x/feedistribution/module/autocli.go +++ /dev/null @@ -1,35 +0,0 @@ -package feedistribute - -import ( - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - - modulev1 "github.com/ExocoreNetwork/exocore/api/exocore/feedistribute" -) - -// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. -func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { - return &autocliv1.ModuleOptions{ - Query: &autocliv1.ServiceCommandDescriptor{ - Service: modulev1.Query_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Params", - Use: "params", - Short: "Shows the parameters of the module", - }, - // this line is used by ignite scaffolding # autocli/query - }, - }, - Tx: &autocliv1.ServiceCommandDescriptor{ - Service: modulev1.Msg_ServiceDesc.ServiceName, - EnhanceCustomCommand: true, // only required if you want to use the custom command - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "UpdateParams", - Skip: true, // skipped because authority gated - }, - // this line is used by ignite scaffolding # autocli/tx - }, - }, - } -} \ No newline at end of file diff --git a/x/feedistribution/module/module.go b/x/feedistribution/module/module.go index 7866106a3..5079c884a 100644 --- a/x/feedistribution/module/module.go +++ b/x/feedistribution/module/module.go @@ -1,49 +1,35 @@ -package feedistribution +package feedistribute import ( "context" "encoding/json" "fmt" - storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/ExocoreNetwork/exocore/x/feedistribution/client/cli" + "github.com/ExocoreNetwork/exocore/x/feedistribution/keeper" + "github.com/ExocoreNetwork/exocore/x/feedistribution/types" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + abci "github.com/cometbft/cometbft/abci/types" - "cosmossdk.io/core/appmodule" - "cosmossdk.io/core/store" - "cosmossdk.io/depinject" - "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - - // this line is used by starport scaffolding # 1 - - modulev1 "github.com/ExocoreNetwork/exocore/api/exocore/feedistribution/module" - "github.com/ExocoreNetwork/exocore/x/feedistribution/keeper" - "github.com/ExocoreNetwork/exocore/x/feedistribution/types" ) var ( - _ module.AppModuleBasic = (*AppModule)(nil) - _ module.AppModuleSimulation = (*AppModule)(nil) - _ module.HasGenesis = (*AppModule)(nil) - _ module.HasInvariants = (*AppModule)(nil) - _ module.HasConsensusVersion = (*AppModule)(nil) - - _ appmodule.AppModule = (*AppModule)(nil) - _ appmodule.HasBeginBlocker = (*AppModule)(nil) - _ appmodule.HasEndBlocker = (*AppModule)(nil) + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} ) // ---------------------------------------------------------------------------- // AppModuleBasic // ---------------------------------------------------------------------------- -// AppModuleBasic implements the AppModuleBasic interface that defines the -// independent methods a Cosmos SDK module needs to implement. +// AppModuleBasic implements the AppModuleBasic interface that defines the independent methods a +// Cosmos SDK module needs to implement. type AppModuleBasic struct { cdc codec.BinaryCodec } @@ -52,28 +38,36 @@ func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { return AppModuleBasic{cdc: cdc} } -// Name returns the name of the module as a string. +// Name returns the name of the module as a string func (AppModuleBasic) Name() string { return types.ModuleName } -// RegisterLegacyAminoCodec registers the amino codec for the module, which is used -// to marshal and unmarshal structs to/from []byte in order to persist them in the module's KVStore. -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} +// RegisterLegacyAminoCodec registers the amino codec for the module, which is used to marshal +// and unmarshal structs to/from []byte in order to persist them in the module's KVStore +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} -// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message. +// RegisterInterfaces registers a module's interface types and their concrete implementations as +// proto.Message func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { types.RegisterInterfaces(reg) } -// DefaultGenesis returns a default GenesisState for the module, marshalled to json.RawMessage. -// The default GenesisState need to be defined by the module developer and is primarily used for testing. +// DefaultGenesis returns a default GenesisState for the module, marshaled to json.RawMessage. +// The default GenesisState need to be defined by the module developer and is primarily used for +// testing func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { return cdc.MustMarshalJSON(types.DefaultGenesis()) } -// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form. -func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { +// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form +func (AppModuleBasic) ValidateGenesis( + cdc codec.JSONCodec, + _ client.TxEncodingConfig, + bz json.RawMessage, +) error { var genState types.GenesisState if err := cdc.UnmarshalJSON(bz, &genState); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) @@ -81,138 +75,96 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod return genState.Validate() } -// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. -func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module +func (AppModuleBasic) RegisterGRPCGatewayRoutes( + clientCtx client.Context, + mux *runtime.ServeMux, +) { + if err := types.RegisterQueryHandlerClient( + context.Background(), mux, types.NewQueryClient(clientCtx), + ); err != nil { + // this panic is safe to do because it means an error in setting up the module. panic(err) } } +// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are +// used by end-users to generate new transactions containing messages defined in the module +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the root query command for the module. The subcommands of this root +// command are used by end-users to generate new queries to the subset of the state defined by +// the module +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + // ---------------------------------------------------------------------------- // AppModule // ---------------------------------------------------------------------------- -// AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement +// AppModule implements the AppModule interface that defines the inter-dependent methods that +// modules need to implement type AppModule struct { AppModuleBasic - - keeper keeper.Keeper - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper + keeper keeper.Keeper } func NewAppModule( cdc codec.Codec, keeper keeper.Keeper, - accountKeeper types.AccountKeeper, - bankKeeper types.BankKeeper, ) AppModule { return AppModule{ AppModuleBasic: NewAppModuleBasic(cdc), keeper: keeper, - accountKeeper: accountKeeper, - bankKeeper: bankKeeper, } } -// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries +// RegisterServices registers a gRPC query service to respond to the module-specific gRPC +// queries func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) types.RegisterQueryServer(cfg.QueryServer(), am.keeper) } -// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) +// RegisterInvariants registers the invariants of the module. If an invariant deviates from its +// predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will +// be halted) func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} // InitGenesis performs the module's genesis initialization. It returns no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) { +func (am AppModule) InitGenesis( + ctx sdk.Context, + cdc codec.JSONCodec, + gs json.RawMessage, +) []abci.ValidatorUpdate { var genState types.GenesisState // Initialize global index to index in genesis state cdc.MustUnmarshalJSON(gs, &genState) - InitGenesis(ctx, am.keeper, genState) + am.keeper.InitGenesis(ctx, genState) + + return []abci.ValidatorUpdate{} } // ExportGenesis returns the module's exported genesis state as raw JSON bytes. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - genState := ExportGenesis(ctx, am.keeper) + genState := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(genState) } -// ConsensusVersion is a sequence number for state-breaking change of the module. -// It should be incremented on each consensus-breaking change introduced by the module. -// To avoid wrong/empty versions, the initial version should be set to 1. +// ConsensusVersion is a sequence number for state-breaking change of the module. It should be +// incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty +// versions, the initial version should be set to 1 func (AppModule) ConsensusVersion() uint64 { return 1 } -// BeginBlock contains the logic that is automatically triggered at the beginning of each block. -// The begin block implementation is optional. -func (am AppModule) BeginBlock(_ context.Context) error { - return nil +// BeginBlock contains the logic that is automatically triggered at the beginning of each block +func (am AppModule) BeginBlock(sdk.Context, abci.RequestBeginBlock) { } -// EndBlock contains the logic that is automatically triggered at the end of each block. -// The end block implementation is optional. -func (am AppModule) EndBlock(_ context.Context) error { - return nil -} - -// IsOnePerModuleType implements the depinject.OnePerModuleType interface. -func (am AppModule) IsOnePerModuleType() {} - -// IsAppModule implements the appmodule.AppModule interface. -func (am AppModule) IsAppModule() {} - -// ---------------------------------------------------------------------------- -// App Wiring Setup -// ---------------------------------------------------------------------------- - -func init() { - appmodule.Register( - &modulev1.Module{}, - appmodule.Provide(ProvideModule), - ) -} - -type ModuleInputs struct { - depinject.In - - StoreService store.KVStoreService - Cdc codec.Codec - Config *modulev1.Module - Logger log.Logger - - AccountKeeper types.AccountKeeper - storeKey storetypes.StoreKey - BankKeeper types.BankKeeper -} - -type ModuleOutputs struct { - depinject.Out - - FeedistributeKeeper keeper.Keeper - Module appmodule.AppModule -} - -func ProvideModule(in ModuleInputs) ModuleOutputs { - // default to governance authority if not provided - authority := authtypes.NewModuleAddress(govtypes.ModuleName) - if in.Config.Authority != "" { - authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) - } - k := keeper.NewKeeper( - in.Cdc, - in.StoreService, - in.Logger, - authority.String(), - in.storeKey, - in.BankKeeper, - ) - m := NewAppModule( - in.Cdc, - k, - in.AccountKeeper, - in.BankKeeper, - ) - - return ModuleOutputs{FeedistributeKeeper: k, Module: m} +// EndBlock contains the logic that is automatically triggered at the end of each block +func (am AppModule) EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} } diff --git a/x/feedistribution/module/simulation.go b/x/feedistribution/module/simulation.go deleted file mode 100644 index 5a06c09ab..000000000 --- a/x/feedistribution/module/simulation.go +++ /dev/null @@ -1,59 +0,0 @@ -package feedistribute - -import ( - "math/rand" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/simulation" - - "github.com/ExocoreNetwork/exocore/testutil/sample" - feedistributesimulation "github.com/ExocoreNetwork/exocore/x/feedistribution/simulation" - "github.com/ExocoreNetwork/exocore/x/feedistribution/types" -) - -// avoid unused import issue -var ( - _ = feedistributesimulation.FindAccount - _ = rand.Rand{} - _ = sample.AccAddress - _ = sdk.AccAddress{} - _ = simulation.MsgEntryKind -) - -const ( -// this line is used by starport scaffolding # simapp/module/const -) - -// GenerateGenesisState creates a randomized GenState of the module. -func (AppModule) GenerateGenesisState(simState *module.SimulationState) { - accs := make([]string, len(simState.Accounts)) - for i, acc := range simState.Accounts { - accs[i] = acc.Address.String() - } - feedistributeGenesis := types.GenesisState{ - Params: types.DefaultParams(), - // this line is used by starport scaffolding # simapp/module/genesisState - } - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&feedistributeGenesis) -} - -// RegisterStoreDecoder registers a decoder. -func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {} - -// WeightedOperations returns the all the gov module operations with their respective weights. -func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { - operations := make([]simtypes.WeightedOperation, 0) - - // this line is used by starport scaffolding # simapp/module/operation - - return operations -} - -// ProposalMsgs returns msgs used for governance proposals for simulations. -func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { - return []simtypes.WeightedProposalMsg{ - // this line is used by starport scaffolding # simapp/module/OpMsg - } -} diff --git a/x/feedistribution/simulation/helpers.go b/x/feedistribution/simulation/helpers.go deleted file mode 100644 index 92c437c0d..000000000 --- a/x/feedistribution/simulation/helpers.go +++ /dev/null @@ -1,15 +0,0 @@ -package simulation - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" -) - -// FindAccount find a specific address from an account list -func FindAccount(accs []simtypes.Account, address string) (simtypes.Account, bool) { - creator, err := sdk.AccAddressFromBech32(address) - if err != nil { - panic(err) - } - return simtypes.FindAccount(accs, creator) -} diff --git a/x/feedistribution/types/codec.go b/x/feedistribution/types/codec.go index 42406fd9c..d4a575f90 100644 --- a/x/feedistribution/types/codec.go +++ b/x/feedistribution/types/codec.go @@ -1,14 +1,16 @@ package types import ( - + "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" - // this line is used by starport scaffolding # 1 ) +func RegisterCodec(*codec.LegacyAmino) { +} + func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { // this line is used by starport scaffolding # 3 @@ -18,4 +20,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } - +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) +) diff --git a/x/feedistribution/types/expected_keepers.go b/x/feedistribution/types/expected_keepers.go index 2b0c0066d..b19197d9d 100644 --- a/x/feedistribution/types/expected_keepers.go +++ b/x/feedistribution/types/expected_keepers.go @@ -2,9 +2,9 @@ package types import ( "context" - epochsTypes "github.com/evmos/evmos/v14/x/epochs/types" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/types" + epochsTypes "github.com/evmos/evmos/v14/x/epochs/types" ) // EpochsKeeper represents the expected keeper interface for the epochs module. @@ -17,14 +17,27 @@ type FeeDistributionHooks interface { // AccountKeeper defines the expected interface for the Account module. type AccountKeeper interface { - GetAccount(context.Context, sdk.AccAddress) sdk.AccountI // only used for simulation + GetAccount(context.Context, sdk.AccAddress) types.AccountI // only used for simulation // Methods imported from account should be defined here + GetModuleAddress(name string) sdk.AccAddress + GetModuleAccount(ctx context.Context, name string) types.ModuleAccountI + // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862 + SetModuleAccount(context.Context, types.ModuleAccountI) } // BankKeeper defines the expected interface for the Bank module. type BankKeeper interface { - SpendableCoins(context.Context, sdk.AccAddress) sdk.Coins - // Methods imported from bank should be defined here + MintCoins(ctx context.Context, moduleName string, amt sdk.Coins) error + GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins + + SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins + + SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt sdk.Coins) error + SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error + + BlockedAddr(addr sdk.AccAddress) bool + IsSendEnabledDenom(ctx context.Context, denom string) bool } // ParamSubspace defines the expected Subspace interface for parameters. diff --git a/x/feedistribution/types/genesis.pb.go b/x/feedistribution/types/genesis.pb.go index f78120d33..62b455f25 100644 --- a/x/feedistribution/types/genesis.pb.go +++ b/x/feedistribution/types/genesis.pb.go @@ -28,10 +28,6 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type GenesisState struct { // params defines all the parameters of the module. Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - // period is the amount of past periods, based on the epochs per period param - Period uint64 `protobuf:"varint,2,opt,name=period,proto3" json:"period,omitempty"` - // epoch_identifier for fee distribution - EpochIdentifier string `protobuf:"bytes,3,opt,name=epoch_identifier,json=epochIdentifier,proto3" json:"epoch_identifier,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -74,20 +70,6 @@ func (m *GenesisState) GetParams() Params { return Params{} } -func (m *GenesisState) GetPeriod() uint64 { - if m != nil { - return m.Period - } - return 0 -} - -func (m *GenesisState) GetEpochIdentifier() string { - if m != nil { - return m.EpochIdentifier - } - return "" -} - func init() { proto.RegisterType((*GenesisState)(nil), "exocore.feedistribute.GenesisState") } @@ -97,25 +79,21 @@ func init() { } var fileDescriptor_aee557f1ee09d7b3 = []byte{ - // 275 bytes of a gzipped FileDescriptorProto + // 222 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4e, 0xad, 0xc8, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0x4b, 0x4d, 0x4d, 0xc9, 0x2c, 0x2e, 0x29, 0xca, 0x4c, 0x2a, 0x2d, 0x49, 0xd5, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x85, 0x2a, 0xd2, 0x43, 0x51, 0x24, 0x25, 0x98, 0x98, 0x9b, 0x99, 0x97, 0xaf, 0x0f, 0x26, 0x21, 0x2a, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x4c, 0x7d, 0x10, 0x0b, 0x2a, 0xaa, 0x84, - 0xdd, 0x92, 0x82, 0xc4, 0xa2, 0xc4, 0x5c, 0xa8, 0x1d, 0x4a, 0x93, 0x19, 0xb9, 0x78, 0xdc, 0x21, - 0xb6, 0x06, 0x97, 0x24, 0x96, 0xa4, 0x0a, 0x39, 0x70, 0xb1, 0x41, 0x14, 0x48, 0x30, 0x2a, 0x30, - 0x6a, 0x70, 0x1b, 0xc9, 0xea, 0x61, 0x75, 0x85, 0x5e, 0x00, 0x58, 0x91, 0x13, 0xe7, 0x89, 0x7b, - 0xf2, 0x0c, 0x2b, 0x9e, 0x6f, 0xd0, 0x62, 0x0c, 0x82, 0xea, 0x13, 0x12, 0xe3, 0x62, 0x2b, 0x48, - 0x2d, 0xca, 0xcc, 0x4f, 0x91, 0x60, 0x52, 0x60, 0xd4, 0x60, 0x09, 0x82, 0xf2, 0x84, 0x34, 0xb9, - 0x04, 0x52, 0x0b, 0xf2, 0x93, 0x33, 0xe2, 0x33, 0x53, 0x52, 0xf3, 0x4a, 0x32, 0xd3, 0x32, 0x53, - 0x8b, 0x24, 0x98, 0x15, 0x18, 0x35, 0x38, 0x83, 0xf8, 0xc1, 0xe2, 0x9e, 0x70, 0x61, 0xa7, 0xe0, - 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, - 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0xb2, 0x4c, 0xcf, 0x2c, 0xc9, 0x28, - 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x77, 0x85, 0x38, 0xcc, 0x2f, 0xb5, 0xa4, 0x3c, 0xbf, 0x28, - 0x5b, 0x1f, 0xe6, 0xdb, 0x0a, 0x14, 0xff, 0x66, 0xe6, 0xe7, 0xe9, 0x97, 0x54, 0x16, 0xa4, 0x16, - 0x27, 0xb1, 0x81, 0x7d, 0x6c, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x90, 0xeb, 0xe5, 0x88, 0x7c, - 0x01, 0x00, 0x00, + 0xdd, 0x92, 0x82, 0xc4, 0xa2, 0xc4, 0x5c, 0xa8, 0x1d, 0x4a, 0x01, 0x5c, 0x3c, 0xee, 0x10, 0x4b, + 0x83, 0x4b, 0x12, 0x4b, 0x52, 0x85, 0x1c, 0xb8, 0xd8, 0x20, 0xf2, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, + 0xdc, 0x46, 0xb2, 0x7a, 0x58, 0x1d, 0xa1, 0x17, 0x00, 0x56, 0xe4, 0xc4, 0x79, 0xe2, 0x9e, 0x3c, + 0xc3, 0x8a, 0xe7, 0x1b, 0xb4, 0x18, 0x83, 0xa0, 0xfa, 0x9c, 0x82, 0x4f, 0x3c, 0x92, 0x63, 0xbc, + 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, + 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x32, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, + 0x57, 0xdf, 0x15, 0x62, 0xaa, 0x5f, 0x6a, 0x49, 0x79, 0x7e, 0x51, 0xb6, 0x3e, 0xcc, 0xa5, 0x15, + 0x28, 0x6e, 0xcd, 0xcc, 0xcf, 0xd3, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0xbb, 0xd6, + 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xe0, 0xf1, 0xcb, 0xd5, 0x38, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -138,18 +116,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.EpochIdentifier) > 0 { - i -= len(m.EpochIdentifier) - copy(dAtA[i:], m.EpochIdentifier) - i = encodeVarintGenesis(dAtA, i, uint64(len(m.EpochIdentifier))) - i-- - dAtA[i] = 0x1a - } - if m.Period != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.Period)) - i-- - dAtA[i] = 0x10 - } { size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -182,13 +148,6 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) - if m.Period != 0 { - n += 1 + sovGenesis(uint64(m.Period)) - } - l = len(m.EpochIdentifier) - if l > 0 { - n += 1 + l + sovGenesis(uint64(l)) - } return n } @@ -260,57 +219,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Period", wireType) - } - m.Period = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Period |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EpochIdentifier", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.EpochIdentifier = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/feedistribution/types/keys.go b/x/feedistribution/types/keys.go index 6093e405e..e5b1009b6 100644 --- a/x/feedistribution/types/keys.go +++ b/x/feedistribution/types/keys.go @@ -1,5 +1,10 @@ package types +import ( + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/ethereum/go-ethereum/common" +) + const ( // ModuleName defines the module name ModuleName = "feedistribution" @@ -7,20 +12,31 @@ const ( // StoreKey defines the primary module store key StoreKey = ModuleName + // RouterKey is the message route for distribution + RouterKey = ModuleName + // MemStoreKey defines the in-memory store key MemStoreKey = "mem_feedistribute" ) +// ModuleAddress is the native module address for EVM +var ModuleAddress common.Address + +func init() { + ModuleAddress = common.BytesToAddress(authtypes.NewModuleAddress(ModuleName).Bytes()) +} + const ( // EpochIdentifier defines the epoch identifier for fee distribution module - EpochIdentifierKey = "epoch_identifier_feedistribute" + prefixParams = iota + 1 + prefixEpochIdentifier ) var ( - ParamsKey = []byte("p_feedistribute") - KeyPrefixEpochIdentifier = []byte(EpochIdentifierKey) + KeyPrefixParams = KeyPrefix(prefixParams) + KeyPrefixEpochIdentifier = KeyPrefix(prefixEpochIdentifier) ) -func KeyPrefix(p string) []byte { +func KeyPrefix(p uint64) []byte { return []byte(p) } diff --git a/x/feedistribution/types/params.pb.go b/x/feedistribution/types/params.pb.go index a03412a86..63521f6bb 100644 --- a/x/feedistribution/types/params.pb.go +++ b/x/feedistribution/types/params.pb.go @@ -26,6 +26,10 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the module. type Params struct { + // period is the amount of past periods, based on the epochs per period param + Period uint64 `protobuf:"varint,1,opt,name=period,proto3" json:"period,omitempty"` + // epoch_identifier for fee distribution + EpochIdentifier string `protobuf:"bytes,2,opt,name=epoch_identifier,json=epochIdentifier,proto3" json:"epoch_identifier,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -61,6 +65,20 @@ func (m *Params) XXX_DiscardUnknown() { var xxx_messageInfo_Params proto.InternalMessageInfo +func (m *Params) GetPeriod() uint64 { + if m != nil { + return m.Period + } + return 0 +} + +func (m *Params) GetEpochIdentifier() string { + if m != nil { + return m.EpochIdentifier + } + return "" +} + func init() { proto.RegisterType((*Params)(nil), "exocore.feedistribute.Params") } @@ -70,42 +88,24 @@ func init() { } var fileDescriptor_2ff10781d3e27dd7 = []byte{ - // 185 bytes of a gzipped FileDescriptorProto + // 233 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4a, 0xad, 0xc8, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0x4b, 0x4d, 0x4d, 0xc9, 0x2c, 0x2e, 0x29, 0xca, 0x4c, 0x2a, 0x2d, 0x49, 0xd5, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x85, 0xaa, 0xd1, 0x43, 0x51, 0x23, 0x25, 0x98, 0x98, 0x9b, 0x99, 0x97, 0xaf, 0x0f, 0x26, 0x21, - 0x2a, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x4c, 0x7d, 0x10, 0x0b, 0x22, 0xaa, 0x64, 0xcc, - 0xc5, 0x16, 0x00, 0x36, 0xcf, 0x4a, 0xf3, 0xc5, 0x02, 0x79, 0xc6, 0xae, 0xe7, 0x1b, 0xb4, 0x14, - 0x60, 0xd6, 0x56, 0xa0, 0x58, 0x9c, 0x99, 0x9f, 0xa7, 0x0f, 0x51, 0xea, 0x14, 0x7c, 0xe2, 0x91, - 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, - 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x96, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, - 0xc9, 0xf9, 0xb9, 0xfa, 0xae, 0x10, 0x63, 0xfc, 0x52, 0x4b, 0xca, 0xf3, 0x8b, 0xb2, 0xf5, 0x71, - 0x9b, 0x5a, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0x76, 0x90, 0x31, 0x20, 0x00, 0x00, 0xff, - 0xff, 0xf9, 0xf5, 0x23, 0xb0, 0xf6, 0x00, 0x00, 0x00, + 0x2a, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x4c, 0x7d, 0x10, 0x0b, 0x22, 0xaa, 0x54, 0xc4, + 0xc5, 0x16, 0x00, 0x36, 0x4f, 0x48, 0x8c, 0x8b, 0xad, 0x20, 0xb5, 0x28, 0x33, 0x3f, 0x45, 0x82, + 0x51, 0x81, 0x51, 0x83, 0x25, 0x08, 0xca, 0x13, 0xd2, 0xe4, 0x12, 0x48, 0x2d, 0xc8, 0x4f, 0xce, + 0x88, 0xcf, 0x4c, 0x49, 0xcd, 0x2b, 0xc9, 0x4c, 0xcb, 0x4c, 0x2d, 0x92, 0x60, 0x52, 0x60, 0xd4, + 0xe0, 0x0c, 0xe2, 0x07, 0x8b, 0x7b, 0xc2, 0x85, 0xad, 0x54, 0xbb, 0x9e, 0x6f, 0xd0, 0x52, 0x80, + 0xb9, 0xba, 0x02, 0xc5, 0xdd, 0x99, 0xf9, 0x79, 0xfa, 0x10, 0x9b, 0x9c, 0x82, 0x4f, 0x3c, 0x92, + 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, + 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x32, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, + 0x39, 0x3f, 0x57, 0xdf, 0x15, 0x62, 0x8c, 0x5f, 0x6a, 0x49, 0x79, 0x7e, 0x51, 0xb6, 0x3e, 0x6e, + 0x53, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0xfe, 0x31, 0x06, 0x04, 0x00, 0x00, 0xff, + 0xff, 0xb7, 0x32, 0x5c, 0xe0, 0x35, 0x01, 0x00, 0x00, } -func (this *Params) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*Params) - if !ok { - that2, ok := that.(Params) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - return true -} func (m *Params) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -126,6 +126,18 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.EpochIdentifier) > 0 { + i -= len(m.EpochIdentifier) + copy(dAtA[i:], m.EpochIdentifier) + i = encodeVarintParams(dAtA, i, uint64(len(m.EpochIdentifier))) + i-- + dAtA[i] = 0x12 + } + if m.Period != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.Period)) + i-- + dAtA[i] = 0x8 + } return len(dAtA) - i, nil } @@ -146,6 +158,13 @@ func (m *Params) Size() (n int) { } var l int _ = l + if m.Period != 0 { + n += 1 + sovParams(uint64(m.Period)) + } + l = len(m.EpochIdentifier) + if l > 0 { + n += 1 + l + sovParams(uint64(l)) + } return n } @@ -184,6 +203,57 @@ func (m *Params) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Period", wireType) + } + m.Period = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Period |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochIdentifier", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EpochIdentifier = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:])