Skip to content

Commit

Permalink
feat: wire new modules into MilkApp
Browse files Browse the repository at this point in the history
  • Loading branch information
hallazzang committed May 10, 2024
1 parent 057b1c6 commit fbf8d33
Show file tree
Hide file tree
Showing 25 changed files with 456 additions and 328 deletions.
110 changes: 104 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ import (
"github.com/cosmos/cosmos-sdk/x/group"
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/gogoproto/proto"

// ibc imports
"github.com/Stride-Labs/ibc-rate-limiting/ratelimit"
ratelimitkeeper "github.com/Stride-Labs/ibc-rate-limiting/ratelimit/keeper"
ratelimittypes "github.com/Stride-Labs/ibc-rate-limiting/ratelimit/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward"
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/keeper"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types"
Expand Down Expand Up @@ -143,6 +147,21 @@ import (
appkeepers "github.com/milkyway-labs/milk/app/keepers"
"github.com/milkyway-labs/milk/x/bank"
bankkeeper "github.com/milkyway-labs/milk/x/bank/keeper"
"github.com/milkyway-labs/milk/x/epochs"
epochskeeper "github.com/milkyway-labs/milk/x/epochs/keeper"
epochstypes "github.com/milkyway-labs/milk/x/epochs/types"
"github.com/milkyway-labs/milk/x/icacallbacks"
icacallbackskeeper "github.com/milkyway-labs/milk/x/icacallbacks/keeper"
icacallbackstypes "github.com/milkyway-labs/milk/x/icacallbacks/types"
"github.com/milkyway-labs/milk/x/interchainquery"
icqkeeper "github.com/milkyway-labs/milk/x/interchainquery/keeper"
icqtypes "github.com/milkyway-labs/milk/x/interchainquery/types"
"github.com/milkyway-labs/milk/x/records"
recordsmodulekeeper "github.com/milkyway-labs/milk/x/records/keeper"
recordstypes "github.com/milkyway-labs/milk/x/records/types"
"github.com/milkyway-labs/milk/x/stakeibc"
stakeibckeeper "github.com/milkyway-labs/milk/x/stakeibc/keeper"
stakeibctypes "github.com/milkyway-labs/milk/x/stakeibc/types"
"github.com/milkyway-labs/milk/x/tokenfactory"
tokenfactorykeeper "github.com/milkyway-labs/milk/x/tokenfactory/keeper"
tokenfactorytypes "github.com/milkyway-labs/milk/x/tokenfactory/types"
Expand Down Expand Up @@ -178,9 +197,12 @@ var (
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
// x/auction's module account must be instantiated upon genesis to accrue auction rewards not
// distributed to proposers
auctiontypes.ModuleName: nil,
opchildtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
auctiontypes.ModuleName: nil,
opchildtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
icqtypes.ModuleName: nil,
stakeibctypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
stakeibctypes.RewardCollectorName: nil,

// slinky oracle permissions
oracletypes.ModuleName: nil,
Expand Down Expand Up @@ -242,6 +264,13 @@ type MilkApp struct {
TokenFactoryKeeper *tokenfactorykeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
ForwardingKeeper *forwardingkeeper.Keeper
RateLimitKeeper ratelimitkeeper.Keeper

EpochsKeeper epochskeeper.Keeper
InterchainQueryKeeper icqkeeper.Keeper
ICACallbacksKeeper icacallbackskeeper.Keeper
RecordsKeeper recordsmodulekeeper.Keeper
StakeIBCKeeper stakeibckeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -301,6 +330,8 @@ func NewMilkApp(
ibcfeetypes.StoreKey, wasmtypes.StoreKey, opchildtypes.StoreKey,
auctiontypes.StoreKey, packetforwardtypes.StoreKey, oracletypes.StoreKey,
tokenfactorytypes.StoreKey, ibchookstypes.StoreKey, forwardingtypes.StoreKey,
ratelimittypes.StoreKey, epochstypes.StoreKey, icqtypes.StoreKey,
icacallbackstypes.StoreKey, recordstypes.StoreKey, stakeibctypes.StoreKey,
)
tkeys := storetypes.NewTransientStoreKeys(forwardingtypes.TransientStoreKey)
memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -346,7 +377,6 @@ func NewMilkApp(
app.ScopedICAControllerKeeper = app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
app.ScopedICAAuthKeeper = app.CapabilityKeeper.ScopeToModule(icaauthtypes.ModuleName)
app.ScopedWasmKeeper = app.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName)

app.CapabilityKeeper.Seal()

// add keepers
Expand Down Expand Up @@ -491,6 +521,16 @@ func NewMilkApp(
)
app.BankKeeper.AppendSendRestriction(app.ForwardingKeeper.SendRestrictionFn)

app.RateLimitKeeper = *ratelimitkeeper.NewKeeper(
appCodec,
keys[ratelimittypes.StoreKey],
paramstypes.Subspace{}, // XXX
authorityAddr,
app.BankKeeper,
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.ChannelKeeper, // ICS4Wrapper
)

////////////////////////////
// Transfer configuration //
////////////////////////////
Expand Down Expand Up @@ -553,7 +593,7 @@ func NewMilkApp(
// receive: wasm -> packet forward -> forwarding -> transfer
transferStack,
ibchooks.NewICS4Middleware(
nil, /* ics4wrapper: not used */
app.RateLimitKeeper,
ibcwasmhooks.NewWasmHooks(appCodec, ac, app.WasmKeeper),
),
app.IBCHooksKeeper,
Expand Down Expand Up @@ -633,7 +673,7 @@ func NewMilkApp(
// receive: hook -> wasm
wasmIBCModule,
ibchooks.NewICS4Middleware(
nil, /* ics4wrapper: not used */
app.RateLimitKeeper,
ibcwasmhooks.NewWasmHooks(appCodec, ac, app.WasmKeeper),
),
app.IBCHooksKeeper,
Expand Down Expand Up @@ -733,6 +773,49 @@ func NewMilkApp(

app.BankKeeper.SetHooks(app.TokenFactoryKeeper.Hooks())

app.ICACallbacksKeeper = *icacallbackskeeper.NewKeeper(
appCodec,
keys[icacallbackstypes.StoreKey],
keys[icacallbackstypes.MemStoreKey],
*app.IBCKeeper,
)

app.InterchainQueryKeeper = icqkeeper.NewKeeper(appCodec, keys[icqtypes.StoreKey], app.IBCKeeper)

app.RecordsKeeper = *recordsmodulekeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[recordstypes.StoreKey]),
keys[recordstypes.StoreKey],
keys[recordstypes.MemStoreKey],
app.AccountKeeper,
*app.TransferKeeper,
*app.IBCKeeper,
app.ICACallbacksKeeper,
)

app.StakeIBCKeeper = stakeibckeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[stakeibctypes.StoreKey]),
keys[stakeibctypes.StoreKey],
keys[stakeibctypes.MemStoreKey],
authorityAddr,
app.AccountKeeper,
app.BankKeeper,
*app.ICAControllerKeeper,
*app.IBCKeeper,
app.InterchainQueryKeeper,
app.RecordsKeeper,
app.ICACallbacksKeeper,
app.RateLimitKeeper,
)

epochsKeeper := epochskeeper.NewKeeper(appCodec, keys[epochstypes.StoreKey])
app.EpochsKeeper = *epochsKeeper.SetHooks(
epochstypes.NewMultiEpochHooks(
app.StakeIBCKeeper.Hooks(),
),
)

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

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
Expand Down Expand Up @@ -768,8 +851,15 @@ func NewMilkApp(
packetforward.NewAppModule(app.PacketForwardKeeper, nil),
ibchooks.NewAppModule(appCodec, *app.IBCHooksKeeper),
forwarding.NewAppModule(app.ForwardingKeeper),
ratelimit.NewAppModule(appCodec, app.RateLimitKeeper),
// slinky modules
oracle.NewAppModule(appCodec, *app.OracleKeeper),
// liquid staking modules
stakeibc.NewAppModule(appCodec, app.StakeIBCKeeper, app.AccountKeeper, app.BankKeeper),
epochs.NewAppModule(appCodec, app.EpochsKeeper),
interchainquery.NewAppModule(appCodec, app.InterchainQueryKeeper),
records.NewAppModule(appCodec, app.RecordsKeeper, app.AccountKeeper, app.BankKeeper),
icacallbacks.NewAppModule(appCodec, app.ICACallbacksKeeper, app.AccountKeeper, app.BankKeeper),
)

if err := app.setupIndexer(appOpts, homePath, ac, vc, appCodec); err != nil {
Expand Down Expand Up @@ -803,6 +893,9 @@ func NewMilkApp(
authz.ModuleName,
ibcexported.ModuleName,
oracletypes.ModuleName,
stakeibctypes.ModuleName,
epochstypes.ModuleName,
ratelimittypes.ModuleName,
)

app.ModuleManager.SetOrderEndBlockers(
Expand All @@ -812,6 +905,9 @@ func NewMilkApp(
group.ModuleName,
oracletypes.ModuleName,
forwardingtypes.ModuleName,
stakeibctypes.ModuleName,
icqtypes.ModuleName,
ratelimittypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand All @@ -827,6 +923,8 @@ func NewMilkApp(
ibcfeetypes.ModuleName, auctiontypes.ModuleName,
wasmtypes.ModuleName, oracletypes.ModuleName, packetforwardtypes.ModuleName,
tokenfactorytypes.ModuleName, ibchookstypes.ModuleName, forwardingtypes.ModuleName,
stakeibctypes.ModuleName, epochstypes.ModuleName, icqtypes.ModuleName,
recordstypes.ModuleName, ratelimittypes.ModuleName, icacallbackstypes.ModuleName,
}

app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...)
Expand Down
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/cosmos/ibc-go/modules/capability v1.0.0
github.com/cosmos/ibc-go/v8 v8.2.1
github.com/cosmos/ics23/go v0.10.0
github.com/cosmos/interchain-security/v5 v5.0.0-alpha1
github.com/cosmos/interchain-security/v5 v5.0.0-alpha1 // indirect
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.4
github.com/gorilla/mux v1.8.1
Expand Down Expand Up @@ -272,4 +272,8 @@ replace (
github.com/skip-mev/slinky => github.com/initia-labs/slinky v0.0.0-20240418051646-d45167cc66b1
)

replace github.com/Stride-Labs/ibc-rate-limiting => github.com/milkyway-labs/ibc-rate-limiting v0.0.0-20240509215339-45e398477ad5
// milk custom
replace (
github.com/Stride-Labs/ibc-rate-limiting => github.com/milkyway-labs/ibc-rate-limiting v0.0.0-20240510185844-cc324d1f9af7
github.com/cosmos/relayer/v2 => github.com/milkyway-labs/relayer/v2 v2.0.0-20240510185220-0492766a512d
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,6 @@ github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo=
github.com/cosmos/keyring v1.2.0/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA=
github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM=
github.com/cosmos/ledger-cosmos-go v0.13.3/go.mod h1:HENcEP+VtahZFw38HZ3+LS3Iv5XV6svsnkk9vdJtLr8=
github.com/cosmos/relayer/v2 v2.5.2 h1:AF0MOo1GvJo94QNB996fBHdKlH+vrIY3JcFNrIvZNP0=
github.com/cosmos/relayer/v2 v2.5.2/go.mod h1:h4Ng2QsVpxExIq5S+WvLr8slDb9MSBh82gQS4DeMwDo=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down Expand Up @@ -907,8 +905,10 @@ github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/milkyway-labs/ibc-rate-limiting v0.0.0-20240509215339-45e398477ad5 h1:1QBEsR4IX53rUHE3EB4VzWiGfEyB+owTivjJU4+zYAM=
github.com/milkyway-labs/ibc-rate-limiting v0.0.0-20240509215339-45e398477ad5/go.mod h1:YAf80eEQ4bdg5qXP4EI8eCxzhhWfqwiy9DoP8JXXg60=
github.com/milkyway-labs/ibc-rate-limiting v0.0.0-20240510185844-cc324d1f9af7 h1:iue7YjSR+prnheC/GnmYctAmMkpA5taCIwvcMwLP3GM=
github.com/milkyway-labs/ibc-rate-limiting v0.0.0-20240510185844-cc324d1f9af7/go.mod h1:YAf80eEQ4bdg5qXP4EI8eCxzhhWfqwiy9DoP8JXXg60=
github.com/milkyway-labs/relayer/v2 v2.0.0-20240510185220-0492766a512d h1:2nNoD9y1Ucp9swVydBI4JrW/pyGp5cbo5IXAlFzlmyc=
github.com/milkyway-labs/relayer/v2 v2.0.0-20240510185220-0492766a512d/go.mod h1:h4Ng2QsVpxExIq5S+WvLr8slDb9MSBh82gQS4DeMwDo=
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
Expand Down
3 changes: 3 additions & 0 deletions proto/stride/icacallbacks/tx.proto
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
syntax = "proto3";
package stride.icacallbacks;

import "cosmos/msg/v1/msg.proto";

// this line is used by starport scaffolding # proto/tx/import

option go_package = "github.com/milkyway-labs/milk/x/icacallbacks/types";

// Msg defines the Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;
// this line is used by starport scaffolding # proto/tx/rpc
}

Expand Down
2 changes: 2 additions & 0 deletions proto/stride/interchainquery/v1/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package stride.interchainquery.v1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "google/api/annotations.proto";
import "tendermint/crypto/proof.proto";

option go_package = "github.com/milkyway-labs/milk/x/interchainquery/types";

// Msg defines the interchainquery Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;
// SubmitQueryResponse defines a method for submit query responses.
rpc SubmitQueryResponse(MsgSubmitQueryResponse)
returns (MsgSubmitQueryResponseResponse) {
Expand Down
1 change: 1 addition & 0 deletions proto/stride/stakeibc/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import "amino/amino.proto";

// Msg defines the Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;
rpc LiquidStake(MsgLiquidStake) returns (MsgLiquidStakeResponse);
rpc LSMLiquidStake(MsgLSMLiquidStake) returns (MsgLSMLiquidStakeResponse);
rpc RedeemStake(MsgRedeemStake) returns (MsgRedeemStakeResponse);
Expand Down
1 change: 1 addition & 0 deletions scripts/protoc-swagger-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mkdir -p ./tmp-swagger-gen
cd proto
proto_dirs=$(find \
./milk \
./stride \
../third_party/cosmos-sdk/proto/cosmos \
../third_party/ibc-go/proto/ibc \
../third_party/initia/proto \
Expand Down
18 changes: 12 additions & 6 deletions scripts/protocgen-pulsar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ echo "Cleaning API directory"

echo "Generating API module"

generate_api() {
package="$1"
proto_dirs=$(find $package -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do
for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do
buf generate --template buf.gen.pulsar.yaml $file
done
done
}

# exclude ibc modules
cd proto
proto_dirs=$(find ./milk -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do
for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do
buf generate --template buf.gen.pulsar.yaml $file
done
done
generate_api "./milk"
generate_api "./stride"
cd ..
7 changes: 4 additions & 3 deletions utils/module_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package utils
// Allows the safe creation of module accounts in the event that an account has already been initialized at an address

import (
"context"
"errors"
"fmt"
"reflect"
Expand All @@ -15,9 +16,9 @@ import (
)

type AccountKeeper interface {
NewAccount(sdk.Context, authtypes.AccountI) authtypes.AccountI
GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
SetAccount(ctx sdk.Context, acc authtypes.AccountI)
NewAccount(context.Context, sdk.AccountI) sdk.AccountI
GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI
SetAccount(ctx context.Context, acc sdk.AccountI)
}

// CanCreateModuleAccountAtAddr tells us if we can safely make a module account at
Expand Down
30 changes: 15 additions & 15 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
errorsmod "cosmossdk.io/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

milkapp "github.com/milkyway-labs/milk/app"
icacallbacktypes "github.com/milkyway-labs/milk/x/icacallbacks/types"
recordstypes "github.com/milkyway-labs/milk/x/records/types"
)
Expand Down Expand Up @@ -196,20 +195,21 @@ func ContainsString(s []string, e string) bool {
return false
}

// Convert any bech32 to stride address
func ConvertAddressToStrideAddress(address string) string {
_, bz, err := bech32.DecodeAndConvert(address)
if err != nil {
return ""
}

bech32Addr, err := bech32.ConvertAndEncode(milkapp.AccountAddressPrefix, bz)
if err != nil {
return ""
}

return bech32Addr
}
// XXX
//// Convert any bech32 to stride address
//func ConvertAddressToStrideAddress(address string) string {
// _, bz, err := bech32.DecodeAndConvert(address)
// if err != nil {
// return ""
// }
//
// bech32Addr, err := bech32.ConvertAndEncode(milkapp.AccountAddressPrefix, bz) // XXX
// if err != nil {
// return ""
// }
//
// return bech32Addr
//}

// Returns a log string with a chainId and tab as the prefix
// Ex:
Expand Down
Loading

0 comments on commit fbf8d33

Please sign in to comment.