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

feat: axelar GMP relaying #304

Merged
merged 14 commits into from
Nov 9, 2023
34 changes: 27 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ import (
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v7/modules/core"
ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client"
Expand All @@ -98,11 +97,17 @@ import (
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/spf13/cast"

ibctransfer "github.com/ojo-network/ojo/app/ibctransfer"

"github.com/ojo-network/ojo/util/genmap"
"github.com/ojo-network/ojo/x/oracle"
oraclekeeper "github.com/ojo-network/ojo/x/oracle/keeper"
oracletypes "github.com/ojo-network/ojo/x/oracle/types"

"github.com/ojo-network/ojo/x/gmp"
gmpkeeper "github.com/ojo-network/ojo/x/gmp/keeper"
gmptypes "github.com/ojo-network/ojo/x/gmp/types"

"github.com/ojo-network/ojo/x/airdrop"
airdropkeeper "github.com/ojo-network/ojo/x/airdrop/keeper"
airdroptypes "github.com/ojo-network/ojo/x/airdrop/types"
Expand Down Expand Up @@ -157,6 +162,7 @@ var (
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
oracle.AppModuleBasic{},
gmp.AppModuleBasic{},
airdrop.AppModuleBasic{},
consensus.AppModuleBasic{},
ibctm.AppModuleBasic{},
Expand All @@ -172,6 +178,7 @@ var (
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
oracletypes.ModuleName: {authtypes.Minter},
gmptypes.ModuleName: {authtypes.Minter},
airdroptypes.ModuleName: {authtypes.Minter},
}
)
Expand Down Expand Up @@ -223,10 +230,11 @@ type App struct {
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
TransferKeeper ibctransfer.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
GroupKeeper groupkeeper.Keeper
OracleKeeper oraclekeeper.Keeper
GmpKeeper gmpkeeper.Keeper
AirdropKeeper airdropkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper

Expand Down Expand Up @@ -276,7 +284,8 @@ func New(
crisistypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey,
feegrant.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
consensusparamtypes.StoreKey, group.StoreKey, oracletypes.StoreKey, airdroptypes.StoreKey,
consensusparamtypes.StoreKey, group.StoreKey, oracletypes.StoreKey, gmptypes.StoreKey,
airdroptypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -423,6 +432,14 @@ func New(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.GmpKeeper = gmpkeeper.NewKeeper(
appCodec,
keys[gmptypes.ModuleName],
app.OracleKeeper,
app.TransferKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.AirdropKeeper = airdropkeeper.NewKeeper(
appCodec,
keys[airdroptypes.ModuleName],
Expand Down Expand Up @@ -456,7 +473,7 @@ func New(
)

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
app.TransferKeeper = ibctransfer.NewKeeper(
appCodec,
keys[ibctransfertypes.StoreKey],
app.GetSubspace(ibctransfertypes.ModuleName),
Expand All @@ -467,8 +484,8 @@ func New(
app.BankKeeper,
scopedTransferKeeper,
)
transferModule := transfer.NewAppModule(app.TransferKeeper)
transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)
transferModule := NewIBCTransferModule(app.TransferKeeper)
transferIBCModule := NewIBCAppModule(app.TransferKeeper)

// Create evidence Keeper for to register the IBC light client misbehavior evidence route
evidenceKeeper := evidencekeeper.NewKeeper(
Expand Down Expand Up @@ -546,6 +563,7 @@ func New(
params.NewAppModule(app.ParamsKeeper),
transferModule,
oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
gmp.NewAppModule(appCodec, app.GmpKeeper, app.OracleKeeper),
airdrop.NewAppModule(appCodec, app.AirdropKeeper, app.AccountKeeper, app.BankKeeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
)
Expand Down Expand Up @@ -576,6 +594,7 @@ func New(
paramstypes.ModuleName,
vestingtypes.ModuleName,
oracletypes.ModuleName,
gmptypes.ModuleName,
airdroptypes.ModuleName,
consensusparamtypes.ModuleName,
)
Expand All @@ -601,6 +620,7 @@ func New(
upgradetypes.ModuleName,
vestingtypes.ModuleName,
oracletypes.ModuleName,
gmptypes.ModuleName,
airdroptypes.ModuleName,
consensusparamtypes.ModuleName,
)
Expand All @@ -616,7 +636,7 @@ func New(
minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, ibctransfertypes.ModuleName,
ibcexported.ModuleName, evidencetypes.ModuleName, authz.ModuleName, feegrant.ModuleName,
group.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName,
oracletypes.ModuleName, airdroptypes.ModuleName, consensusparamtypes.ModuleName,
oracletypes.ModuleName, gmptypes.ModuleName, airdroptypes.ModuleName, consensusparamtypes.ModuleName,
}
app.mm.SetOrderInitGenesis(genesisModuleOrder...)
app.mm.SetOrderExportGenesis(genesisModuleOrder...)
Expand Down
62 changes: 62 additions & 0 deletions app/ibctransfer/ibctransfer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package ibctransfer

import (
"context"

"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper"
types "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
)

type Keeper struct {
ibctransferkeeper.Keeper

storeKey storetypes.StoreKey
cdc codec.BinaryCodec
paramSpace paramtypes.Subspace

ics4Wrapper porttypes.ICS4Wrapper
channelKeeper types.ChannelKeeper
portKeeper types.PortKeeper
authKeeper types.AccountKeeper
bankKeeper types.BankKeeper
scopedKeeper exported.ScopedKeeper
}

func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.MsgTransferResponse, error) {
// TODO: Custom IBC validation logic
return k.Keeper.Transfer(goCtx, msg)
}

// NewKeeper creates a new IBC transfer Keeper instance
func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
ics4Wrapper porttypes.ICS4Wrapper, channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper,
authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, scopedKeeper exported.ScopedKeeper,
) Keeper {
// ensure ibc transfer module account is set
if addr := authKeeper.GetModuleAddress(types.ModuleName); addr == nil {
panic("the IBC transfer module account has not been set")
}

// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}

return Keeper{
cdc: cdc,
storeKey: key,
paramSpace: paramSpace,
ics4Wrapper: ics4Wrapper,
channelKeeper: channelKeeper,
portKeeper: portKeeper,
authKeeper: authKeeper,
bankKeeper: bankKeeper,
scopedKeeper: scopedKeeper,
}
}
30 changes: 30 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer"

"github.com/ojo-network/ojo/app/ibctransfer"
appparams "github.com/ojo-network/ojo/app/params"
)

Expand Down Expand Up @@ -130,3 +132,31 @@ func (SlashingModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {

return cdc.MustMarshalJSON(genState)
}

// IBCTransferModule defines a custom wrapper around the IBC Transfer AppModuleBasic
// so that we can use a custom Keeper.
type IBCTransferModule struct {
transfer.AppModuleBasic
keeper ibctransfer.Keeper
}

// NewIBCTransferModule creates a new 20-transfer module
func NewIBCTransferModule(k ibctransfer.Keeper) IBCTransferModule {
return IBCTransferModule{
keeper: k,
}
}

// IBCAppModule is a custom wrapper around IBCModule, which
// implements the ICS26 interface for transfer given the transfer keeper.
type IBCAppModule struct {
transfer.IBCModule
keeper ibctransfer.Keeper
}

// NewIBCAppModule creates a new IBCModule given the keeper
func NewIBCAppModule(k ibctransfer.Keeper) IBCAppModule {
return IBCAppModule{
keeper: k,
}
}
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/v7 v7.2.1
github.com/ethereum/go-ethereum v1.12.1
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.3
github.com/golangci/golangci-lint v1.55.0
Expand Down Expand Up @@ -147,7 +148,7 @@ require (
github.com/golang/glog v1.1.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 // indirect
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a // indirect
github.com/golangci/go-misc v0.0.0-20220329215616-d24fe342adfe // indirect
Expand Down Expand Up @@ -187,6 +188,7 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
Expand Down
9 changes: 7 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/esimonov/ifshort v1.0.4 h1:6SID4yGWfRae/M7hkVDVVyppy8q/v9OuxNdmjLQStBA=
github.com/esimonov/ifshort v1.0.4/go.mod h1:Pe8zjlRrJ80+q2CxHLfEOfTwxCZ4O+MuhcHcfgNWTk0=
github.com/ethereum/go-ethereum v1.10.17/go.mod h1:Lt5WzjM07XlXc95YzrhosmR4J9Ahd6X2wyEV2SvGhk0=
github.com/ethereum/go-ethereum v1.12.1 h1:1kXDPxhLfyySuQYIfRxVBGYuaHdxNNxevA73vjIwsgk=
github.com/ethereum/go-ethereum v1.12.1/go.mod h1:zKetLweqBR8ZS+1O9iJWI8DvmmD2NzD19apjEWDCsnw=
github.com/ettle/strcase v0.1.1 h1:htFueZyVeE1XNnMEfbqp5r67qAN/4r6ya1ysq8Q+Zcw=
github.com/ettle/strcase v0.1.1/go.mod h1:hzDLsPC7/lwKyBOywSHEP89nt2pDgdy+No1NBA9o9VY=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
Expand Down Expand Up @@ -720,8 +722,9 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 h1:23T5iq8rbUYlhpt5DB4XJkc6BU31uODLD1o1gKvZmD0=
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2/go.mod h1:k9Qvh+8juN+UKMCS/3jFtGICgW8O96FVaZsaxdzDkR4=
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a h1:w8hkcTqaFpzKqonE9uMCefW1WDie15eSP/4MssdenaM=
Expand Down Expand Up @@ -790,8 +793,8 @@ github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 h1:4/hN5RUoecvl+RmJRE2YxKWtnnQls6rQjjW5oV7qg2U=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/s2a-go v0.1.4 h1:1kZ/sQM3srePvKs3tXAvQzo66XfcReoqFpIpIccE7Oc=
github.com/google/s2a-go v0.1.4/go.mod h1:Ej+mSEMGRnqRzjc7VtF+jdBwYG5fuJfiZ8ELkjEwM0A=
Expand Down Expand Up @@ -913,6 +916,8 @@ github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUq
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw=
github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o=
github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/go-assert v1.1.5 h1:fjemmA7sSfYHJD7CUqs9qTwwfdNAx7/j2/ZlHXzNB3c=
github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0JrPVhn/06U=
Expand Down
12 changes: 12 additions & 0 deletions proto/ojo/gmp/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";
package ojo.gmp.v1;

import "gogoproto/gogo.proto";
import "ojo/gmp/v1/gmp.proto";

option go_package = "github.com/ojo-network/ojo/x/gmp/types";

// GenesisState represents the genesis state of the gmp module.
message GenesisState {
Params params = 1 [ (gogoproto.nullable) = false ];
}
38 changes: 38 additions & 0 deletions proto/ojo/gmp/v1/gmp.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
syntax = "proto3";
package ojo.gmp.v1;

import "gogoproto/gogo.proto";

option go_package = "github.com/ojo-network/ojo/x/gmp/types";

option (gogoproto.goproto_getters_all) = false;

// Params defines the parameters for the gmp module.
message Params {
// The axelar address that we'll send IBC transactions to.
string gmp_address = 1;

// The channel over which we communicate with axelar.
string gmp_channel = 2;

// The amount of time we'll wait for a response from axelar before timing out.
int64 gmp_timeout = 3;
}

// GmpMessage defines the GMP message that we encode in the
// IBC memo field and send to Axelar.
//
// Ref: https://github.com/axelarnetwork/evm-cosmos-gmp-sample
message GmpMessage {
// destination_chain is the destination chain of the message
string destination_chain = 1;

// destination_address is the destination address of the message
string destination_address = 2;

// payload is the encoded payload of the message (exchange rates)
bytes payload = 3;

// type is an enum that specifies the type of message
int64 type = 4;
}
25 changes: 25 additions & 0 deletions proto/ojo/gmp/v1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto3";
package ojo.gmp.v1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "ojo/gmp/v1/gmp.proto";

option go_package = "github.com/ojo-network/ojo/x/gmp/types";

// Query defines the gRPC querier service for the gmp module
service Query {
// Params queries all parameters.
rpc Params(ParamsRequest) returns (ParamsResponse) {
option (google.api.http).get = "/ojo/gmp/v1/params";
}
}

// ParamsRequest is the request type for the Query/Params RPC method.
message ParamsRequest {}

// ParamsResponse is the response type for the Query/Params RPC method.
message ParamsResponse {
// params defines the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];
}
Loading
Loading