Skip to content

Commit

Permalink
gasless module initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnukumavat committed Feb 25, 2024
1 parent bc2c40b commit c902679
Show file tree
Hide file tree
Showing 45 changed files with 2,266 additions and 19 deletions.
30 changes: 27 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ import (
liquidationsV2keeper "github.com/comdex-official/comdex/x/liquidationsV2/keeper"
liquidationsV2types "github.com/comdex-official/comdex/x/liquidationsV2/types"

"github.com/comdex-official/comdex/x/gasless"
gaslessclient "github.com/comdex-official/comdex/x/gasless/client"
gaslesskeeper "github.com/comdex-official/comdex/x/gasless/keeper"
gaslesstypes "github.com/comdex-official/comdex/x/gasless/types"

"github.com/comdex-official/comdex/x/auctionsV2"
auctionsV2client "github.com/comdex-official/comdex/x/auctionsV2/client"
auctionsV2keeper "github.com/comdex-official/comdex/x/auctionsV2/keeper"
Expand Down Expand Up @@ -248,6 +253,7 @@ func GetGovProposalHandlers() []govclient.ProposalHandler {
proposalHandlers = append(proposalHandlers, liquidityclient.LiquidityProposalHandler...)
proposalHandlers = append(proposalHandlers, liquidationsV2client.LiquidationsV2Handler...)
proposalHandlers = append(proposalHandlers, auctionsV2client.AuctionsV2Handler...)
proposalHandlers = append(proposalHandlers, gaslessclient.GaslessProposalHandler...)

return proposalHandlers
}
Expand Down Expand Up @@ -306,6 +312,7 @@ var (
ibcfee.AppModuleBasic{},
liquidationsV2.AppModuleBasic{},
auctionsV2.AppModuleBasic{},
gasless.AppModuleBasic{},
icq.AppModuleBasic{},
ibchooks.AppModuleBasic{},
packetforward.AppModuleBasic{},
Expand Down Expand Up @@ -388,6 +395,7 @@ type App struct {
Rewardskeeper rewardskeeper.Keeper
NewliqKeeper liquidationsV2keeper.Keeper
NewaucKeeper auctionsV2keeper.Keeper
GaslessKeeper gaslesskeeper.Keeper

// IBC modules
// transfer module
Expand Down Expand Up @@ -434,7 +442,8 @@ func New(
markettypes.StoreKey, bandoraclemoduletypes.StoreKey, lockertypes.StoreKey,
wasm.StoreKey, authzkeeper.StoreKey, auctiontypes.StoreKey, tokenminttypes.StoreKey,
rewardstypes.StoreKey, feegrant.StoreKey, liquiditytypes.StoreKey, esmtypes.ModuleName, lendtypes.StoreKey,
liquidationsV2types.StoreKey, auctionsV2types.StoreKey, ibchookstypes.StoreKey, packetforwardtypes.StoreKey, icqtypes.StoreKey, consensusparamtypes.StoreKey, crisistypes.StoreKey,
liquidationsV2types.StoreKey, auctionsV2types.StoreKey, gaslesstypes.StoreKey,
ibchookstypes.StoreKey, packetforwardtypes.StoreKey, icqtypes.StoreKey, consensusparamtypes.StoreKey, crisistypes.StoreKey,
)
)

Expand Down Expand Up @@ -489,6 +498,7 @@ func New(
app.ParamsKeeper.Subspace(rewardstypes.ModuleName)
app.ParamsKeeper.Subspace(liquidationsV2types.ModuleName)
app.ParamsKeeper.Subspace(auctionsV2types.ModuleName)
app.ParamsKeeper.Subspace(gaslesstypes.ModuleName)
app.ParamsKeeper.Subspace(icqtypes.ModuleName)
app.ParamsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())

Expand Down Expand Up @@ -881,6 +891,14 @@ func New(
&app.TokenmintKeeper,
)

app.GaslessKeeper = gaslesskeeper.NewKeeper(
app.cdc,
app.keys[gaslesstypes.StoreKey],
app.GetSubspace(gaslesstypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
)

// ICQ Keeper
icqKeeper := icqkeeper.NewKeeper(
appCodec,
Expand All @@ -907,7 +925,7 @@ func New(
}
supportedFeatures := "iterator,staking,stargate,comdex,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3"

wasmOpts = append(cwasm.RegisterCustomPlugins(&app.LockerKeeper, &app.TokenmintKeeper, &app.AssetKeeper, &app.Rewardskeeper, &app.CollectorKeeper, &app.LiquidationKeeper, &app.AuctionKeeper, &app.EsmKeeper, &app.VaultKeeper, &app.LendKeeper, &app.LiquidityKeeper, &app.MarketKeeper), wasmOpts...)
wasmOpts = append(cwasm.RegisterCustomPlugins(&app.LockerKeeper, &app.TokenmintKeeper, &app.AssetKeeper, &app.Rewardskeeper, &app.CollectorKeeper, &app.LiquidationKeeper, &app.AuctionKeeper, &app.EsmKeeper, &app.VaultKeeper, &app.LendKeeper, &app.LiquidityKeeper, &app.MarketKeeper, &app.GaslessKeeper), wasmOpts...)

app.WasmKeeper = wasmkeeper.NewKeeper(
app.cdc,
Expand Down Expand Up @@ -946,7 +964,8 @@ func New(
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IbcKeeper.ClientKeeper)).
AddRoute(liquiditytypes.RouterKey, liquidity.NewLiquidityProposalHandler(app.LiquidityKeeper)).
AddRoute(liquidationsV2types.RouterKey, liquidationsV2.NewLiquidationsV2Handler(app.NewliqKeeper)).
AddRoute(auctionsV2types.RouterKey, auctionsV2.NewAuctionsV2Handler(app.NewaucKeeper))
AddRoute(auctionsV2types.RouterKey, auctionsV2.NewAuctionsV2Handler(app.NewaucKeeper)).
AddRoute(gaslesstypes.RouterKey, gasless.NewGaslessProposalHandler(app.GaslessKeeper))

if len(wasmEnabledProposals) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, wasmEnabledProposals))
Expand Down Expand Up @@ -1052,6 +1071,7 @@ func New(
rewards.NewAppModule(app.cdc, app.Rewardskeeper, app.AccountKeeper, app.BankKeeper),
liquidationsV2.NewAppModule(app.cdc, app.NewliqKeeper, app.AccountKeeper, app.BankKeeper),
auctionsV2.NewAppModule(app.cdc, app.NewaucKeeper, app.BankKeeper),
gasless.NewAppModule(app.cdc, app.GaslessKeeper, app.AccountKeeper, app.BankKeeper),
ibchooks.NewAppModule(app.AccountKeeper),
icq.NewAppModule(*app.ICQKeeper),
packetforward.NewAppModule(app.PacketForwardKeeper),
Expand Down Expand Up @@ -1097,6 +1117,7 @@ func New(
esmtypes.ModuleName,
liquidationsV2types.ModuleName,
auctionsV2types.ModuleName,
gaslesstypes.ModuleName,
ibchookstypes.ModuleName,
icqtypes.ModuleName,
packetforwardtypes.ModuleName,
Expand Down Expand Up @@ -1140,6 +1161,7 @@ func New(
esmtypes.ModuleName,
liquidationsV2types.ModuleName,
auctionsV2types.ModuleName,
gaslesstypes.ModuleName,
ibchookstypes.ModuleName,
icqtypes.ModuleName,
packetforwardtypes.ModuleName,
Expand Down Expand Up @@ -1187,6 +1209,7 @@ func New(
crisistypes.ModuleName,
liquidationsV2types.ModuleName,
auctionsV2types.ModuleName,
gaslesstypes.ModuleName,
ibchookstypes.ModuleName,
icqtypes.ModuleName,
packetforwardtypes.ModuleName,
Expand Down Expand Up @@ -1447,6 +1470,7 @@ func (a *App) ModuleAccountsPermissions() map[string][]string {
rewardstypes.ModuleName: {authtypes.Minter, authtypes.Burner},
liquidationsV2types.ModuleName: {authtypes.Minter, authtypes.Burner},
auctionsV2types.ModuleName: {authtypes.Minter, authtypes.Burner},
gaslesstypes.ModuleName: nil,
icatypes.ModuleName: nil,
ibcfeetypes.ModuleName: nil,
assettypes.ModuleName: nil,
Expand Down
8 changes: 6 additions & 2 deletions app/wasm/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/comdex-official/comdex/app/wasm/bindings"
assetkeeper "github.com/comdex-official/comdex/x/asset/keeper"
collectorkeeper "github.com/comdex-official/comdex/x/collector/keeper"
gaslessKeeper "github.com/comdex-official/comdex/x/gasless/keeper"
liquidityKeeper "github.com/comdex-official/comdex/x/liquidity/keeper"
lockerkeeper "github.com/comdex-official/comdex/x/locker/keeper"
lockertypes "github.com/comdex-official/comdex/x/locker/types"
Expand All @@ -27,7 +28,8 @@ import (

func CustomMessageDecorator(lockerKeeper lockerkeeper.Keeper, rewardsKeeper rewardskeeper.Keeper,
assetKeeper assetkeeper.Keeper, collectorKeeper collectorkeeper.Keeper, liquidationKeeper liquidationkeeper.Keeper,
auctionKeeper auctionkeeper.Keeper, tokenMintKeeper tokenmintkeeper.Keeper, esmKeeper esmkeeper.Keeper, vaultKeeper vaultkeeper.Keeper, liquiditykeeper liquidityKeeper.Keeper,
auctionKeeper auctionkeeper.Keeper, tokenMintKeeper tokenmintkeeper.Keeper, esmKeeper esmkeeper.Keeper,
vaultKeeper vaultkeeper.Keeper, liquiditykeeper liquidityKeeper.Keeper, gaslesskeeper gaslessKeeper.Keeper,
) func(wasmkeeper.Messenger) wasmkeeper.Messenger {
return func(old wasmkeeper.Messenger) wasmkeeper.Messenger {
return &CustomMessenger{
Expand All @@ -42,6 +44,7 @@ func CustomMessageDecorator(lockerKeeper lockerkeeper.Keeper, rewardsKeeper rewa
esmKeeper: esmKeeper,
vaultKeeper: vaultKeeper,
liquiditykeeper: liquiditykeeper,
gaslesskeeper: gaslesskeeper,
}
}
}
Expand All @@ -58,6 +61,7 @@ type CustomMessenger struct {
esmKeeper esmkeeper.Keeper
vaultKeeper vaultkeeper.Keeper
liquiditykeeper liquidityKeeper.Keeper
gaslesskeeper gaslessKeeper.Keeper
}

var _ wasmkeeper.Messenger = (*CustomMessenger)(nil)
Expand Down Expand Up @@ -564,7 +568,7 @@ func (m *CustomMessenger) ExecuteAddEmissionRewards(ctx sdk.Context, contractAdd
if contractAddr.String() != comdex1[1] {
return nil, nil, sdkerrors.ErrInvalidAddress
}
}else if ctx.ChainID() == "comdex-test3" {
} else if ctx.ChainID() == "comdex-test3" {
if contractAddr.String() != testnet3[1] {
return nil, nil, sdkerrors.ErrInvalidAddress
}
Expand Down
6 changes: 5 additions & 1 deletion app/wasm/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
assetKeeper "github.com/comdex-official/comdex/x/asset/keeper"
collectorkeeper "github.com/comdex-official/comdex/x/collector/keeper"
esmKeeper "github.com/comdex-official/comdex/x/esm/keeper"
gaslessKeeper "github.com/comdex-official/comdex/x/gasless/keeper"
lendKeeper "github.com/comdex-official/comdex/x/lend/keeper"
liquidationKeeper "github.com/comdex-official/comdex/x/liquidation/keeper"
liquidityKeeper "github.com/comdex-official/comdex/x/liquidity/keeper"
Expand All @@ -27,6 +28,7 @@ type QueryPlugin struct {
lendKeeper *lendKeeper.Keeper
liquidityKeeper *liquidityKeeper.Keeper
marketKeeper *marketKeeper.Keeper
gaslessKeeper *gaslessKeeper.Keeper
}

func NewQueryPlugin(
Expand All @@ -41,6 +43,7 @@ func NewQueryPlugin(
lendKeeper *lendKeeper.Keeper,
liquidityKeeper *liquidityKeeper.Keeper,
marketKeeper *marketKeeper.Keeper,
gaslessKeeper *gaslessKeeper.Keeper,
) *QueryPlugin {
return &QueryPlugin{
assetKeeper: assetKeeper,
Expand All @@ -54,6 +57,7 @@ func NewQueryPlugin(
lendKeeper: lendKeeper,
liquidityKeeper: liquidityKeeper,
marketKeeper: marketKeeper,
gaslessKeeper: gaslessKeeper,
}
}

Expand Down Expand Up @@ -209,7 +213,7 @@ func (qp QueryPlugin) WasmGetPools(ctx sdk.Context, appID uint64) (pools []uint6

func (qp QueryPlugin) WasmGetAssetPrice(ctx sdk.Context, assetID uint64) (twa uint64, found bool) {
assetTwa, found := qp.marketKeeper.GetTwa(ctx, assetID)
if found && assetTwa.IsPriceActive{
if found && assetTwa.IsPriceActive {
return assetTwa.Twa, true
}
return 0, false
Expand Down
27 changes: 18 additions & 9 deletions app/wasm/test/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func TestWhitelistAssetLocker(t *testing.T) {
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper,
&comdex.MarketKeeper)
&comdex.MarketKeeper,
&comdex.GaslessKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgWhiteListAssetLocker
Expand Down Expand Up @@ -67,7 +68,8 @@ func TestAddMsgAddExtendedPairsVault(t *testing.T) {
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper,
&comdex.MarketKeeper)
&comdex.MarketKeeper,
&comdex.GaslessKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgAddExtendedPairsVault
Expand Down Expand Up @@ -125,7 +127,8 @@ func TestMsgSetCollectorLookupTable(t *testing.T) {
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper,
&comdex.MarketKeeper)
&comdex.MarketKeeper,
&comdex.GaslessKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgSetCollectorLookupTable
Expand Down Expand Up @@ -177,7 +180,8 @@ func TestMsgSetAuctionMappingForApp(t *testing.T) {
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper,
&comdex.MarketKeeper)
&comdex.MarketKeeper,
&comdex.GaslessKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgSetAuctionMappingForApp
Expand Down Expand Up @@ -228,7 +232,8 @@ func TestMsgUpdateCollectorLookupTable(t *testing.T) {
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper,
&comdex.MarketKeeper)
&comdex.MarketKeeper,
&comdex.GaslessKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgUpdateCollectorLookupTable
Expand Down Expand Up @@ -280,7 +285,8 @@ func TestMsgUpdatePairsVault(t *testing.T) {
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper,
&comdex.MarketKeeper)
&comdex.MarketKeeper,
&comdex.GaslessKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgUpdatePairsVault
Expand Down Expand Up @@ -336,7 +342,8 @@ func TestMsgWhitelistAppIDLiquidation(t *testing.T) {
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper,
&comdex.MarketKeeper)
&comdex.MarketKeeper,
&comdex.GaslessKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgWhitelistAppIDLiquidation
Expand Down Expand Up @@ -384,7 +391,8 @@ func TestMsgRemoveWhitelistAppIDLiquidation(t *testing.T) {
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper,
&comdex.MarketKeeper)
&comdex.MarketKeeper,
&comdex.GaslessKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgRemoveWhitelistAppIDLiquidation
Expand Down Expand Up @@ -428,7 +436,8 @@ func TestMsgAddAuctionParams(t *testing.T) {
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper,
&comdex.MarketKeeper)
&comdex.MarketKeeper,
&comdex.GaslessKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgAddAuctionParams
Expand Down
8 changes: 5 additions & 3 deletions app/wasm/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
auctionKeeper "github.com/comdex-official/comdex/x/auction/keeper"
collectorKeeper "github.com/comdex-official/comdex/x/collector/keeper"
esmKeeper "github.com/comdex-official/comdex/x/esm/keeper"
gaslessKeeper "github.com/comdex-official/comdex/x/gasless/keeper"
lendKeeper "github.com/comdex-official/comdex/x/lend/keeper"
liquidationKeeper "github.com/comdex-official/comdex/x/liquidation/keeper"
liquidityKeeper "github.com/comdex-official/comdex/x/liquidity/keeper"
lockerkeeper "github.com/comdex-official/comdex/x/locker/keeper"
marketKeeper "github.com/comdex-official/comdex/x/market/keeper"
rewardsKeeper "github.com/comdex-official/comdex/x/rewards/keeper"
tokenMintkeeper "github.com/comdex-official/comdex/x/tokenmint/keeper"
vaultKeeper "github.com/comdex-official/comdex/x/vault/keeper"
marketKeeper "github.com/comdex-official/comdex/x/market/keeper"
)

func RegisterCustomPlugins(
Expand All @@ -31,14 +32,15 @@ func RegisterCustomPlugins(
lend *lendKeeper.Keeper,
liquidity *liquidityKeeper.Keeper,
market *marketKeeper.Keeper,
gasless *gaslessKeeper.Keeper,
) []wasmkeeper.Option {
comdexQueryPlugin := NewQueryPlugin(asset, locker, tokenMint, rewards, collector, liquidation, esm, vault, lend, liquidity, market)
comdexQueryPlugin := NewQueryPlugin(asset, locker, tokenMint, rewards, collector, liquidation, esm, vault, lend, liquidity, market, gasless)

appDataQueryPluginOpt := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{
Custom: CustomQuerier(comdexQueryPlugin),
})
messengerDecoratorOpt := wasmkeeper.WithMessageHandlerDecorator(
CustomMessageDecorator(*locker, *rewards, *asset, *collector, *liquidation, *auction, *tokenMint, *esm, *vault, *liquidity),
CustomMessageDecorator(*locker, *rewards, *asset, *collector, *liquidation, *auction, *tokenMint, *esm, *vault, *liquidity, *gasless),
)

return []wasm.Option{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-apps/modules/async-icq/v7 v7.0.0
github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20230803181732-7c8f814d3b79
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
Expand Down Expand Up @@ -138,7 +139,6 @@ require (
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
Expand Down
9 changes: 9 additions & 0 deletions proto/comdex/gasless/v1beta1/gasless.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";
package comdex.gasless.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/comdex-official/comdex/x/gasless/types";
option (gogoproto.goproto_getters_all) = false;
13 changes: 13 additions & 0 deletions proto/comdex/gasless/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";
package comdex.gasless.v1beta1;

import "gogoproto/gogo.proto";
import "comdex/gasless/v1beta1/params.proto";

option go_package = "github.com/comdex-official/comdex/x/gasless/types";
option (gogoproto.goproto_getters_all) = false;

// GenesisState defines the gasless module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
}
8 changes: 8 additions & 0 deletions proto/comdex/gasless/v1beta1/gov.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
syntax = "proto3";
package comdex.gasless.v1beta1;

import "gogoproto/gogo.proto";

option go_package = "github.com/comdex-official/comdex/x/gasless/types";
option (gogoproto.equal_all) = false;
option (gogoproto.goproto_getters_all) = false;
10 changes: 10 additions & 0 deletions proto/comdex/gasless/v1beta1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";
package comdex.gasless.v1beta1;

import "gogoproto/gogo.proto";

option go_package = "github.com/comdex-official/comdex/x/gasless/types";
option (gogoproto.goproto_getters_all) = false;

// Params defines the parameters for the module.
message Params {}
Loading

0 comments on commit c902679

Please sign in to comment.