Skip to content

Commit

Permalink
OTE-558 Add scaffolding for module (#1941)
Browse files Browse the repository at this point in the history
Add accountplus module scafolding
  • Loading branch information
jerryfan01234 authored Jul 23, 2024
1 parent e86691c commit f3af0fe
Show file tree
Hide file tree
Showing 22 changed files with 457 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import { DeepPartial } from "../../helpers";
/** Module genesis state */

export interface GenesisState {
/** Module genesis state */
accounts: AccountState[];
}
/** Module genesis state */

export interface GenesisStateSDKType {
/** Module genesis state */
accounts: AccountStateSDKType[];
}

Expand Down
5 changes: 4 additions & 1 deletion proto/dydxprotocol/accountplus/accountplus.proto
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
syntax = "proto3";
package dydxprotocol.accountplus;

import "gogoproto/gogo.proto";

option go_package = "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types";

// Account State
message AccountState {
string address = 1;
TimestampNonceDetails timestamp_nonce_details = 2;
TimestampNonceDetails timestamp_nonce_details = 2
[ (gogoproto.nullable) = false ];
}

// Timestamp nonce details
Expand Down
5 changes: 4 additions & 1 deletion proto/dydxprotocol/accountplus/genesis.proto
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
syntax = "proto3";
package dydxprotocol.accountplus;

import "gogoproto/gogo.proto";
import "dydxprotocol/accountplus/accountplus.proto";

option go_package = "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types";

// Module genesis state
message GenesisState { repeated AccountState accounts = 1; }
message GenesisState {
repeated AccountState accounts = 1 [ (gogoproto.nullable) = false ];
}
16 changes: 16 additions & 0 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ import (
daemontypes "github.com/dydxprotocol/v4-chain/protocol/daemons/types"

// Modules
accountplusmodule "github.com/dydxprotocol/v4-chain/protocol/x/accountplus"
accountplusmodulekeeper "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/keeper"
accountplusmoduletypes "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types"
assetsmodule "github.com/dydxprotocol/v4-chain/protocol/x/assets"
assetsmodulekeeper "github.com/dydxprotocol/v4-chain/protocol/x/assets/keeper"
assetsmoduletypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types"
Expand Down Expand Up @@ -294,6 +297,7 @@ type App struct {
FeeGrantKeeper feegrantkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
GovPlusKeeper govplusmodulekeeper.Keeper
AccountPlusKeeper accountplusmodulekeeper.Keeper

MarketMapKeeper marketmapmodulekeeper.Keeper

Expand Down Expand Up @@ -450,6 +454,7 @@ func New(
govplusmoduletypes.StoreKey,
vaultmoduletypes.StoreKey,
revsharemoduletypes.StoreKey,
accountplusmoduletypes.StoreKey,
marketmapmoduletypes.StoreKey,
)
keys[authtypes.StoreKey] = keys[authtypes.StoreKey].WithLocking()
Expand Down Expand Up @@ -1165,6 +1170,12 @@ func New(
)
listingModule := listingmodule.NewAppModule(appCodec, app.ListingKeeper)

app.AccountPlusKeeper = *accountplusmodulekeeper.NewKeeper(
appCodec,
keys[govplusmoduletypes.StoreKey],
)
accountplusModule := accountplusmodule.NewAppModule(appCodec, app.AccountPlusKeeper)

/**** Module Options ****/

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
Expand Down Expand Up @@ -1235,6 +1246,7 @@ func New(
vaultModule,
listingModule,
revShareModule,
accountplusModule,
marketmapModule,
)

Expand Down Expand Up @@ -1285,6 +1297,7 @@ func New(
vaultmoduletypes.ModuleName,
listingmoduletypes.ModuleName,
revsharemoduletypes.ModuleName,
accountplusmoduletypes.ModuleName,
marketmapmoduletypes.ModuleName,
)

Expand Down Expand Up @@ -1331,6 +1344,7 @@ func New(
vaultmoduletypes.ModuleName,
listingmoduletypes.ModuleName,
revsharemoduletypes.ModuleName,
accountplusmoduletypes.ModuleName,
marketmapmoduletypes.ModuleName,
authz.ModuleName, // No-op.
blocktimemoduletypes.ModuleName, // Must be last
Expand Down Expand Up @@ -1378,6 +1392,7 @@ func New(
vaultmoduletypes.ModuleName,
listingmoduletypes.ModuleName,
revsharemoduletypes.ModuleName,
accountplusmoduletypes.ModuleName,
marketmapmoduletypes.ModuleName,
authz.ModuleName,
)
Expand Down Expand Up @@ -1421,6 +1436,7 @@ func New(
vaultmoduletypes.ModuleName,
listingmoduletypes.ModuleName,
revsharemoduletypes.ModuleName,
accountplusmoduletypes.ModuleName,
marketmapmoduletypes.ModuleName,
authz.ModuleName,

Expand Down
6 changes: 4 additions & 2 deletions protocol/app/app_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package app_test

import (
marketmapmodule "github.com/skip-mev/slinky/x/marketmap"
"reflect"
"strings"
"testing"
"time"

listingmodule "github.com/dydxprotocol/v4-chain/protocol/x/listing"
marketmapmodule "github.com/skip-mev/slinky/x/marketmap"

evidencemodule "cosmossdk.io/x/evidence"
feegrantmodule "cosmossdk.io/x/feegrant/module"
Expand All @@ -34,6 +33,7 @@ import (
custommodule "github.com/dydxprotocol/v4-chain/protocol/app/module"
"github.com/dydxprotocol/v4-chain/protocol/mocks"
testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app"
accountplusmodule "github.com/dydxprotocol/v4-chain/protocol/x/accountplus"
assetsmodule "github.com/dydxprotocol/v4-chain/protocol/x/assets"
blocktimemodule "github.com/dydxprotocol/v4-chain/protocol/x/blocktime"
bridgemodule "github.com/dydxprotocol/v4-chain/protocol/x/bridge"
Expand All @@ -42,6 +42,7 @@ import (
epochsmodule "github.com/dydxprotocol/v4-chain/protocol/x/epochs"
feetiersmodule "github.com/dydxprotocol/v4-chain/protocol/x/feetiers"
govplusmodule "github.com/dydxprotocol/v4-chain/protocol/x/govplus"
listingmodule "github.com/dydxprotocol/v4-chain/protocol/x/listing"
perpetualsmodule "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals"
pricesmodule "github.com/dydxprotocol/v4-chain/protocol/x/prices"
ratelimitmodule "github.com/dydxprotocol/v4-chain/protocol/x/ratelimit"
Expand Down Expand Up @@ -220,6 +221,7 @@ func TestModuleBasics(t *testing.T) {
vaultmodule.AppModuleBasic{},
listingmodule.AppModuleBasic{},
revsharemodule.AppModuleBasic{},
accountplusmodule.AppModuleBasic{},

// slinky marketmap
marketmapmodule.AppModuleBasic{},
Expand Down
2 changes: 2 additions & 0 deletions protocol/app/basic_manager/basic_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
listingmodule "github.com/dydxprotocol/v4-chain/protocol/x/listing"

custommodule "github.com/dydxprotocol/v4-chain/protocol/app/module"
accountplusmodule "github.com/dydxprotocol/v4-chain/protocol/x/accountplus"
assetsmodule "github.com/dydxprotocol/v4-chain/protocol/x/assets"
blocktimemodule "github.com/dydxprotocol/v4-chain/protocol/x/blocktime"
bridgemodule "github.com/dydxprotocol/v4-chain/protocol/x/bridge"
Expand Down Expand Up @@ -99,5 +100,6 @@ var (
revsharemodule.AppModuleBasic{},
listingmodule.AppModuleBasic{},
marketmapmodule.AppModuleBasic{},
accountplusmodule.AppModuleBasic{},
)
)
3 changes: 3 additions & 0 deletions protocol/app/testdata/default_genesis_state.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
"delegator_starting_infos": [],
"validator_slash_events": []
},
"dydxaccountplus": {
"accounts": []
},
"epochs": {
"epoch_info_list": [
{
Expand Down
2 changes: 2 additions & 0 deletions protocol/app/upgrades/v6.0.0/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
marketmapmoduletypes "github.com/skip-mev/slinky/x/marketmap/types"

"github.com/dydxprotocol/v4-chain/protocol/app/upgrades"
accountplustypes "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types"
listingtypes "github.com/dydxprotocol/v4-chain/protocol/x/listing/types"
revsharetypes "github.com/dydxprotocol/v4-chain/protocol/x/revshare/types"
)
Expand All @@ -22,6 +23,7 @@ var (
listingtypes.StoreKey,
revsharetypes.StoreKey,
marketmapmoduletypes.StoreKey,
accountplustypes.StoreKey,
},
},
}
Expand Down
5 changes: 4 additions & 1 deletion protocol/scripts/genesis/sample_pregenesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,9 @@
"validator_historical_rewards": [],
"validator_slash_events": []
},
"dydxaccountplus": {
"accounts": []
},
"epochs": {
"epoch_info_list": [
{
Expand Down Expand Up @@ -1859,7 +1862,7 @@
]
}
},
"app_version": "5.0.0-dev0-385-gb5b86472",
"app_version": "5.0.0-dev0-378-ge9777b09",
"chain_id": "dydx-sample-1",
"consensus": {
"params": {
Expand Down
3 changes: 3 additions & 0 deletions protocol/testing/containertest/preupgrade_genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,9 @@
"delegator_starting_infos": [],
"validator_slash_events": []
},
"dydxaccountplus": {
"accounts": []
},
"epochs": {
"epoch_info_list": [
{
Expand Down
10 changes: 7 additions & 3 deletions protocol/x/accountplus/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, data types.GenesisState) {
}
}

func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
return types.GenesisState{
Accounts: k.GetAllAccountStates(ctx),
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
accounts, err := k.GetAllAccountStates(ctx)
if err != nil {
panic(err)
}
return &types.GenesisState{
Accounts: accounts,
}
}
Loading

0 comments on commit f3af0fe

Please sign in to comment.