Skip to content

Commit

Permalink
feat(group): add group module (#1329)
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 authored Oct 21, 2024
1 parent 43d8aca commit 0382bbc
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 138 deletions.
17 changes: 17 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
grouptypes "github.com/cosmos/cosmos-sdk/x/group"
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params"
Expand Down Expand Up @@ -147,6 +149,7 @@ type AppKeepers struct {
StreamerKeeper streamermodulekeeper.Keeper
EIBCKeeper eibckeeper.Keeper
LightClientKeeper lightclientmodulekeeper.Keeper
GroupKeeper groupkeeper.Keeper

DelayedAckKeeper delayedackkeeper.Keeper
DenomMetadataKeeper *denommetadatamodulekeeper.Keeper
Expand Down Expand Up @@ -376,6 +379,19 @@ func (a *AppKeepers) InitKeepers(
a.RollappKeeper,
)

groupConfig := grouptypes.Config{
MaxExecutionPeriod: 0,
MaxMetadataLen: 0,
}

a.GroupKeeper = groupkeeper.NewKeeper(
a.keys[grouptypes.StoreKey],
appCodec,
bApp.MsgServiceRouter(),
a.AccountKeeper,
groupConfig,
)

a.RollappKeeper.SetSequencerKeeper(a.SequencerKeeper)
a.RollappKeeper.SetCanonicalClientKeeper(a.LightClientKeeper)

Expand Down Expand Up @@ -648,6 +664,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(delayedacktypes.ModuleName)
paramsKeeper.Subspace(eibcmoduletypes.ModuleName)
paramsKeeper.Subspace(dymnstypes.ModuleName)
paramsKeeper.Subspace(grouptypes.ModuleName)

// ethermint subspaces
paramsKeeper.Subspace(evmtypes.ModuleName)
Expand Down
5 changes: 4 additions & 1 deletion app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
grouptypes "github.com/cosmos/cosmos-sdk/x/group"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand All @@ -21,14 +22,15 @@ import (
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
irotypes "github.com/dymensionxyz/dymension/v3/x/iro/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
epochstypes "github.com/osmosis-labs/osmosis/v15/x/epochs/types"
gammtypes "github.com/osmosis-labs/osmosis/v15/x/gamm/types"
poolmanagertypes "github.com/osmosis-labs/osmosis/v15/x/poolmanager/types"
txfeestypes "github.com/osmosis-labs/osmosis/v15/x/txfees/types"

irotypes "github.com/dymensionxyz/dymension/v3/x/iro/types"

dymnstypes "github.com/dymensionxyz/dymension/v3/x/dymns/types"

delayedacktypes "github.com/dymensionxyz/dymension/v3/x/delayedack/types"
Expand Down Expand Up @@ -135,4 +137,5 @@ var KVStoreKeys = sdk.NewKVStoreKeys(
incentivestypes.StoreKey,
txfeestypes.StoreKey,
lightcliendmoduletypes.StoreKey,
grouptypes.StoreKey,
)
8 changes: 8 additions & 0 deletions app/keepers/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/gov/client"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
grouptypes "github.com/cosmos/cosmos-sdk/x/group"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
"github.com/cosmos/cosmos-sdk/x/mint"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params"
Expand Down Expand Up @@ -156,6 +158,7 @@ var ModuleBasics = module.NewBasicManager(
eibc.AppModuleBasic{},
dymnsmodule.AppModuleBasic{},
lightclientmodule.AppModuleBasic{},
groupmodule.AppModuleBasic{},

// Ethermint modules
evm.AppModuleBasic{},
Expand Down Expand Up @@ -210,6 +213,7 @@ func (a *AppKeepers) SetupModules(
eibcmodule.NewAppModule(appCodec, a.EIBCKeeper, a.AccountKeeper, a.BankKeeper),
dymnsmodule.NewAppModule(appCodec, a.DymNSKeeper),
lightclientmodule.NewAppModule(appCodec, a.LightClientKeeper),
groupmodule.NewAppModule(appCodec, a.GroupKeeper, a.AccountKeeper, a.BankKeeper, encodingConfig.InterfaceRegistry),

// Ethermint app modules
evm.NewAppModule(a.EvmKeeper, a.AccountKeeper, a.BankKeeper, a.GetSubspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable())),
Expand Down Expand Up @@ -254,6 +258,7 @@ var maccPerms = map[string][]string{
streamermoduletypes.ModuleName: nil,
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account.
evmtypes.ModuleVirtualFrontierContractDeployerName: nil, // used for deploying virtual frontier bank contract.
grouptypes.ModuleName: nil,
gammtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
lockuptypes.ModuleName: {authtypes.Minter, authtypes.Burner},
incentivestypes.ModuleName: {authtypes.Minter, authtypes.Burner},
Expand Down Expand Up @@ -301,6 +306,7 @@ var BeginBlockers = []string{
consensusparamtypes.ModuleName,
irotypes.ModuleName,
lightclientmoduletypes.ModuleName,
grouptypes.ModuleName,
}

var EndBlockers = []string{
Expand Down Expand Up @@ -342,6 +348,7 @@ var EndBlockers = []string{
irotypes.ModuleName,
lightclientmoduletypes.ModuleName,
crisistypes.ModuleName,
grouptypes.ModuleName,
}

var InitGenesis = []string{
Expand Down Expand Up @@ -383,4 +390,5 @@ var InitGenesis = []string{
irotypes.ModuleName,
lightclientmoduletypes.ModuleName,
crisistypes.ModuleName,
grouptypes.ModuleName,
}
12 changes: 5 additions & 7 deletions proto/dymensionxyz/dymension/eibc/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,22 @@ message MsgFulfillOrderAuthorized {
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
// operator_address is the bech32-encoded address of the account which is authorized to fulfill the demand order.
string operator_address = 4;
// lp_address is the bech32-encoded address of the account which the authorization was granted from.
// This account will receive the price amount at the finalization phase.
string lp_address = 5;
string lp_address = 4;
// operator_fee_address is an optional bech32-encoded address of an account that would collect the operator_fee_part
// if it's empty, the operator_fee_part will go to the operator_address
string operator_fee_address = 6;
string operator_fee_address = 5;
// expected_fee is the nominal fee set in the order.
string expected_fee = 7;
string expected_fee = 6;
// operator_fee_share is the share of the fee earnings that goes to the operator
// it will be deduced from the fee of the demand order and paid out immediately
cosmos.base.v1beta1.DecProto operator_fee_share = 8 [
cosmos.base.v1beta1.DecProto operator_fee_share = 7 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecProto"
];
// settlement_validated signals if the block behind the demand order needs to be "settlement validated" or not
bool settlement_validated = 9;
bool settlement_validated = 8;
}

message MsgFulfillOrderAuthorizedResponse {}
Expand Down
10 changes: 7 additions & 3 deletions x/eibc/client/cli/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
FlagDenoms = "denoms"
FlagMinLPFeePercentage = "min-lp-fee-percentage"
FlagMaxPrice = "max-price"
FlagOperatorFeePart = "operator-fee-part"
FlagOperatorFeeShare = "operator-fee-share"
FlagSettlementValidated = "settlement-validated"
)

Expand Down Expand Up @@ -80,7 +80,7 @@ Examples:
return fmt.Errorf("failed to parse max price: %w", err)
}

fulfillerFeePartStr, err := cmd.Flags().GetString(FlagOperatorFeePart)
fulfillerFeePartStr, err := cmd.Flags().GetString(FlagOperatorFeeShare)
if err != nil {
return fmt.Errorf("failed to get fulfiller fee part: %w", err)
}
Expand All @@ -107,6 +107,10 @@ Examples:
if err != nil {
return fmt.Errorf("failed to parse spend limit: %w", err)
}
spendLimit, err := sdk.ParseCoinsNormalized(limit)
if err != nil {
return fmt.Errorf("failed to parse spend limit: %w", err)
}

if !spendLimit.IsAllPositive() {
return fmt.Errorf("spend-limit should be greater than zero")
Expand Down Expand Up @@ -144,7 +148,7 @@ Examples:
cmd.Flags().Bool(FlagSettlementValidated, false, "Settlement validated flag")
cmd.Flags().String(FlagMinLPFeePercentage, "", "Minimum fee")
cmd.Flags().String(FlagMaxPrice, "", "Maximum price")
cmd.Flags().String(FlagOperatorFeePart, "", "Fulfiller fee part")
cmd.Flags().String(FlagOperatorFeeShare, "", "Fulfiller fee part")
cmd.Flags().Int64(FlagExpiration, 0, "Expire time as Unix timestamp. Set zero (0) for no expiry. Default is 0.")
return cmd
}
Expand Down
24 changes: 8 additions & 16 deletions x/eibc/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func NewFulfillOrderTxCmd() *cobra.Command {
}

const (
FlagOperatorAddress = "operator-address"
FlagOperatorFeeAddress = "operator-fee-address"
FlagRollappId = "rollapp-id"
FlagPrice = "price"
Expand Down Expand Up @@ -95,14 +94,9 @@ func NewFulfillOrderAuthorizedTxCmd() *cobra.Command {
return fmt.Errorf("rollapp ID is required")
}

fulfillerAddress, err := cmd.Flags().GetString(FlagOperatorAddress)
operatorFeeAddress, err := cmd.Flags().GetString(FlagOperatorFeeAddress)
if err != nil {
return fmt.Errorf("fulfiller address is required")
}

operatorAddress, err := cmd.Flags().GetString(FlagOperatorFeeAddress)
if err != nil {
return fmt.Errorf("operator address is required")
return fmt.Errorf("operator fee address is required")
}

priceStr, err := cmd.Flags().GetString(FlagPrice)
Expand All @@ -115,15 +109,15 @@ func NewFulfillOrderAuthorizedTxCmd() *cobra.Command {
return fmt.Errorf("invalid price: %w", err)
}

fulfillerFeePartStr, err := cmd.Flags().GetString(FlagOperatorFeePart)
oepratorFeeShareStr, err := cmd.Flags().GetString(FlagOperatorFeeShare)
if err != nil {
return fmt.Errorf("fulfiller fee part is required")
}
fulfillerFeePartDec, err := sdk.NewDecFromStr(fulfillerFeePartStr)
operatorFeeShareDec, err := sdk.NewDecFromStr(oepratorFeeShareStr)
if err != nil {
return fmt.Errorf("invalid fulfiller fee part: %w", err)
}
fulfillerFeePart := sdk.DecProto{Dec: fulfillerFeePartDec}
operatorFeeShare := sdk.DecProto{Dec: operatorFeeShareDec}

settlementValidated, err := cmd.Flags().GetBool(FlagSettlementValidated)
if err != nil {
Expand All @@ -134,11 +128,10 @@ func NewFulfillOrderAuthorizedTxCmd() *cobra.Command {
orderId,
rollappId,
clientCtx.GetFromAddress().String(),
fulfillerAddress,
operatorAddress,
operatorFeeAddress,
fee,
price,
fulfillerFeePart,
operatorFeeShare,
settlementValidated,
)

Expand All @@ -153,8 +146,7 @@ func NewFulfillOrderAuthorizedTxCmd() *cobra.Command {
cmd.Flags().Bool(FlagSettlementValidated, false, "Settlement validated flag")
cmd.Flags().String(FlagRollappId, "", "Rollapp ID")
cmd.Flags().String(FlagPrice, "", "Maximum price")
cmd.Flags().String(FlagOperatorFeePart, "", "Operator fee part")
cmd.Flags().String(FlagOperatorAddress, "", "Operator address")
cmd.Flags().String(FlagOperatorFeeShare, "", "Operator fee share")
cmd.Flags().String(FlagOperatorFeeAddress, "", "Operator fee address")
return cmd
}
Expand Down
2 changes: 0 additions & 2 deletions x/eibc/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func NewMsgFulfillOrderAuthorized(
orderId,
rollappId,
granterAddress,
operatorAddress,
operatorFeeAddress,
expectedFee string,
price sdk.Coins,
Expand All @@ -70,7 +69,6 @@ func NewMsgFulfillOrderAuthorized(
return &MsgFulfillOrderAuthorized{
OrderId: orderId,
RollappId: rollappId,
OperatorAddress: operatorAddress,
LpAddress: granterAddress,
OperatorFeeAddress: operatorFeeAddress,
ExpectedFee: expectedFee,
Expand Down
Loading

0 comments on commit 0382bbc

Please sign in to comment.