Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ecosystem Incentive Tx memo handler #654

Merged
merged 13 commits into from
Aug 8, 2023
Merged
6 changes: 6 additions & 0 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (

builderante "github.com/skip-mev/pob/x/builder/ante"
builderkeeper "github.com/skip-mev/pob/x/builder/keeper"

ecosystemincentiveante "github.com/UnUniFi/chain/x/ecosystemincentive/ante"
ecosystemincentivekeeper "github.com/UnUniFi/chain/x/ecosystemincentive/keeper"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
Expand All @@ -28,6 +31,8 @@ type HandlerOptions struct {
BuilderKeeper builderkeeper.Keeper
TxEncoder sdk.TxEncoder
Mempool builderante.Mempool

EcosystemincentiveKeeper ecosystemincentivekeeper.Keeper
}

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
Expand Down Expand Up @@ -62,6 +67,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ecosystemincentiveante.NewFrontendIncentiveDecorator(options.EcosystemincentiveKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
builderante.NewBuilderDecorator(options.BuilderKeeper, options.TxEncoder, options.Mempool),
}
Expand Down
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ func (app *App) CreateAnteHandler(txConfig client.TxConfig, wasmConfig wasmtypes
TxEncoder: txConfig.TxEncoder(),
BuilderKeeper: app.AppKeepers.BuilderKeeper,
Mempool: mempool,

EcosystemincentiveKeeper: app.AppKeepers.EcosystemincentiveKeeper,
},
)
if err != nil {
Expand Down
30 changes: 1 addition & 29 deletions proto/ununifi/ecosystemincentive/ecosystemincentive.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,7 @@ import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/UnUniFi/chain/x/ecosystemincentive/types";

message RecipientContainer {
string id = 1 [
(gogoproto.moretags) = "yaml:\"id\""
];
repeated WeightedAddress weighted_addresses = 2 [
(gogoproto.moretags) = "yaml:\"weighted_addresses\"",
(gogoproto.nullable) = false
];
}

message WeightedAddress {
string address = 1 [
(gogoproto.moretags) = "yaml:\"address\""
];
string weight = 2 [
(gogoproto.moretags) = "yaml:\"weight\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message RewardStore {
message RewardRecord {
string address = 1 [
(gogoproto.moretags) = "yaml:\"address\""
];
Expand All @@ -37,10 +16,3 @@ message RewardStore {
(gogoproto.nullable) = false
];
}

message BelongingRecipientContainers {
string address = 1 [
(gogoproto.moretags) = "yaml:\"address\""
];
repeated string recipient_container_ids = 2 [ (gogoproto.moretags) = "yaml:\"recipient_container_ids\"" ];
}
40 changes: 11 additions & 29 deletions proto/ununifi/ecosystemincentive/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/UnUniFi/chain/x/ecosystemincentive/types";

message EventRegister {
string recipient_container_id = 1 [(gogoproto.moretags) = "yaml:\"recipient_container_id\""];
repeated WeightedAddress weighted_addresses = 2
[(gogoproto.moretags) = "yaml:\"weighted_addresses\"", (gogoproto.nullable) = false];
}

message EventWithdrawAllRewards {
string sender = 1 [(gogoproto.moretags) = "yaml:\"sender\""];
repeated cosmos.base.v1beta1.Coin all_withdrawn_rewards = 2 [
Expand All @@ -31,30 +25,18 @@ message EventWithdrawReward {
];
}

message EventFailedParsingTxMemoData {
string class_id = 1 [(gogoproto.moretags) = "yaml:\"class_id\""];
string nft_id = 2 [(gogoproto.moretags) = "yaml:\"nft_id\""];
string memo = 3 [(gogoproto.moretags) = "yaml:\"memo\""];
}

message EventRecordedRecipientContainerId {
string recipient_container_id = 1 [(gogoproto.moretags) = "yaml:\"recipient_container_id\""];
string class_id = 2 [(gogoproto.moretags) = "yaml:\"class_id\""];
string nft_id = 3 [(gogoproto.moretags) = "yaml:\"nft_id\""];
}
// message EventFailedParsingTxMemoData {
// string class_id = 1 [(gogoproto.moretags) = "yaml:\"class_id\""];
// string nft_id = 2 [(gogoproto.moretags) = "yaml:\"nft_id\""];
// string memo = 3 [(gogoproto.moretags) = "yaml:\"memo\""];
// }

message EventDeletedNftIdRecordedForFrontendReward {
string recipient_container_id = 1 [(gogoproto.moretags) = "yaml:\"recipient_container_id\""];
string class_id = 2 [(gogoproto.moretags) = "yaml:\"class_id\""];
string nft_id = 3 [(gogoproto.moretags) = "yaml:\"nft_id\""];
}

message EventNotRegisteredRecipientContainerId {
string recipient_container_id = 1 [(gogoproto.moretags) = "yaml:\"recipient_container_id\""];
string class_id = 2 [(gogoproto.moretags) = "yaml:\"class_id\""];
string nft_id = 3 [(gogoproto.moretags) = "yaml:\"nft_id\""];
}

message EventNotRecordedNftId {
string class_id = 1 [(gogoproto.moretags) = "yaml:\"class_id\""];
string nft_id = 2 [(gogoproto.moretags) = "yaml:\"nft_id\""];
Expand All @@ -69,12 +51,6 @@ message EventUpdatedReward {
];
}

message EventVersionUnmatched {
string unmatched_version = 1 [(gogoproto.moretags) = "yaml:\"unmatched_version\""];
string class_id = 2 [(gogoproto.moretags) = "yaml:\"class_id\""];
string nft_id = 3 [(gogoproto.moretags) = "yaml:\"nft_id\""];
}

message EventDistributionForStakers {
cosmos.base.v1beta1.Coin distributed_amount = 1 [
(gogoproto.moretags) = "yaml:\"distributed_amount\"",
Expand All @@ -83,3 +59,9 @@ message EventDistributionForStakers {
];
int64 block_height = 2 [(gogoproto.moretags) = "yaml:\"block_height\""];
}

message EventVersionUnmatched {
uint32 unmatched_version = 1 [(gogoproto.moretags) = "yaml:\"unmatched_version\""];
string class_id = 2 [(gogoproto.moretags) = "yaml:\"class_id\""];
string nft_id = 3 [(gogoproto.moretags) = "yaml:\"nft_id\""];
}
5 changes: 2 additions & 3 deletions proto/ununifi/ecosystemincentive/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ option go_package = "github.com/UnUniFi/chain/x/ecosystemincentive/types";

// GenesisState defines the ecosystemincentive module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated RecipientContainer recipient_containers = 2 [(gogoproto.nullable) = false];
repeated RewardStore reward_stores = 3 [(gogoproto.nullable) = false];
Params params = 1 [(gogoproto.nullable) = false];
repeated RewardRecord reward_records = 2 [(gogoproto.nullable) = false];
}
8 changes: 4 additions & 4 deletions proto/ununifi/ecosystemincentive/memo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import "gogoproto/gogo.proto";

option go_package = "github.com/UnUniFi/chain/x/ecosystemincentive/types";

message TxMemoData {
string version = 1 [
message FrontendMetadata {
uint32 version = 1 [
(gogoproto.moretags) = "yaml:\"version\""
];
string recipient_container_id = 2 [
(gogoproto.moretags) = "yaml:\"recipient_container_id\""
string recipient = 2 [
(gogoproto.moretags) = "yaml:\"recipient\""
];
}
41 changes: 1 addition & 40 deletions proto/ununifi/ecosystemincentive/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,13 @@ service Query {
option (google.api.http).get = "/ununifi/ecosystemincentive/params";
}

rpc RecipientContainer(QueryRecipientContainerRequest) returns (QueryRecipientContainerResponse) {
option (google.api.http).get = "/ununifi/ecosystemincentive/recipient-containers/{id}";
}

rpc AllRewards(QueryAllRewardsRequest) returns (QueryAllRewardsResponse) {
option (google.api.http).get = "/ununifi/ecosystemincentive/rewards/{address}";
}

rpc Reward(QueryRewardRequest) returns (QueryRewardResponse) {
option (google.api.http).get = "/ununifi/ecosystemincentive/rewards/{address}/{denom}";
}

rpc RecordedRecipientContainerId(QueryRecordedRecipientContainerIdRequest)
returns (QueryRecordedRecipientContainerIdResponse) {
option (google.api.http).get = "/ununifi/ecosystemincentive/recorded-recipient-containers/{class_id}/{nft_id}";
}

rpc BelongingRecipientContainerIdsByAddr(QueryBelongingRecipientContainerIdsByAddrRequest)
returns (QueryBelongingRecipientContainerIdsByAddrResponse) {
option (google.api.http).get = "/ununifi/ecosystemincentive/belonging-recipient-containers/{address}";
}
}

message QueryParamsRequest {}
Expand All @@ -47,20 +33,12 @@ message QueryParamsResponse {
Params params = 1 [(gogoproto.moretags) = "yaml:\"params\"", (gogoproto.nullable) = false];
}

message QueryRecipientContainerRequest {
string id = 1 [(gogoproto.moretags) = "yaml:\"id\""];
}

message QueryRecipientContainerResponse {
RecipientContainer recipient_container = 1 [(gogoproto.moretags) = "yaml:\"recipient_container\""];
}

message QueryAllRewardsRequest {
string address = 1 [(gogoproto.moretags) = "yaml:\"address\""];
}

message QueryAllRewardsResponse {
RewardStore rewards = 1 [(gogoproto.moretags) = "yaml:\"rewards\"", (gogoproto.nullable) = false];
RewardRecord reward_record = 1 [(gogoproto.moretags) = "yaml:\"reward_record\"", (gogoproto.nullable) = false];
}

message QueryRewardRequest {
Expand All @@ -75,20 +53,3 @@ message QueryRewardResponse {
(gogoproto.nullable) = false
];
}

message QueryRecordedRecipientContainerIdRequest {
string class_id = 1 [(gogoproto.moretags) = "yaml:\"class_id\""];
string nft_id = 2 [(gogoproto.moretags) = "yaml:\"nft_id\""];
}

message QueryRecordedRecipientContainerIdResponse {
string recipient_container_id = 1 [(gogoproto.moretags) = "yaml:\"recipient_container_id\""];
}

message QueryBelongingRecipientContainerIdsByAddrRequest {
string address = 1 [(gogoproto.moretags) = "yaml:\"address\""];
}

message QueryBelongingRecipientContainerIdsByAddrResponse {
repeated string recipient_container_ids = 2 [(gogoproto.moretags) = "yaml:\"recipient_container_ids\""];
}
17 changes: 0 additions & 17 deletions proto/ununifi/ecosystemincentive/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,10 @@ option go_package = "github.com/UnUniFi/chain/x/ecosystemincentive/types";

// Msg defines the Msg service.
service Msg {
rpc Register(MsgRegister) returns (MsgRegisterResponse);
rpc WithdrawAllRewards(MsgWithdrawAllRewards) returns (MsgWithdrawAllRewardsResponse);
rpc WithdrawReward(MsgWithdrawReward) returns (MsgWithdrawRewardResponse);
}

message MsgRegister {
string sender = 1 [
(gogoproto.moretags) = "yaml:\"sender\""
];
string recipient_container_id = 2 [ (gogoproto.moretags) = "yaml:\"recipient_container_id\"" ];
repeated string addresses = 3 [
(gogoproto.moretags) = "yaml:\"subject_addrs\""
];
repeated string weights = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"weights\"",
(gogoproto.nullable) = false
];
}
message MsgRegisterResponse {}

message MsgWithdrawAllRewards {
string sender = 1 [
(gogoproto.moretags) = "yaml:\"sender\""
Expand Down
31 changes: 31 additions & 0 deletions x/ecosystemincentive/ante/ante.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ante

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

ecosystemincentivekeeper "github.com/UnUniFi/chain/x/ecosystemincentive/keeper"
)

type FrontendIncentiveDecorator struct {
keeper ecosystemincentivekeeper.Keeper
}

func NewFrontendIncentiveDecorator(keeper ecosystemincentivekeeper.Keeper) FrontendIncentiveDecorator {
return FrontendIncentiveDecorator{
keeper: keeper,
}
}

func (decorator FrontendIncentiveDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
memoTx, ok := tx.(sdk.TxWithMemo)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type")
}
msgs := memoTx.GetMsgs()
memo := memoTx.GetMemo()

decorator.keeper.MemoTxHandler(ctx, msgs, memo)

return next(ctx, tx, simulate)
}
Loading
Loading