mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-25 15:55:18 +00:00
Add Ethereum bridge module (#1211)
* Add bridge module * Add bridge module to app * Add relayer/user address, bridge params to init chain script * Update bridge to v0.1.0 * Enable bridge, add min withdraw limits in devnet script * update to v0.1.1 * Move savings, evmutil, bridge initgenesis orders Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
This commit is contained in:
parent
812b03af2a
commit
8aa176f05a
56
app/app.go
56
app/app.go
@ -92,6 +92,10 @@ import (
|
|||||||
feemarketkeeper "github.com/tharsis/ethermint/x/feemarket/keeper"
|
feemarketkeeper "github.com/tharsis/ethermint/x/feemarket/keeper"
|
||||||
feemarkettypes "github.com/tharsis/ethermint/x/feemarket/types"
|
feemarkettypes "github.com/tharsis/ethermint/x/feemarket/types"
|
||||||
|
|
||||||
|
"github.com/kava-labs/kava-bridge/x/bridge"
|
||||||
|
bridgekeeper "github.com/kava-labs/kava-bridge/x/bridge/keeper"
|
||||||
|
bridgetypes "github.com/kava-labs/kava-bridge/x/bridge/types"
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app/ante"
|
"github.com/kava-labs/kava/app/ante"
|
||||||
kavaparams "github.com/kava-labs/kava/app/params"
|
kavaparams "github.com/kava-labs/kava/app/params"
|
||||||
"github.com/kava-labs/kava/x/auction"
|
"github.com/kava-labs/kava/x/auction"
|
||||||
@ -189,6 +193,7 @@ var (
|
|||||||
savings.AppModuleBasic{},
|
savings.AppModuleBasic{},
|
||||||
validatorvesting.AppModuleBasic{},
|
validatorvesting.AppModuleBasic{},
|
||||||
evmutil.AppModuleBasic{},
|
evmutil.AppModuleBasic{},
|
||||||
|
bridge.AppModuleBasic{},
|
||||||
)
|
)
|
||||||
|
|
||||||
// module account permissions
|
// module account permissions
|
||||||
@ -213,6 +218,7 @@ var (
|
|||||||
cdptypes.LiquidatorMacc: {authtypes.Minter, authtypes.Burner},
|
cdptypes.LiquidatorMacc: {authtypes.Minter, authtypes.Burner},
|
||||||
hardtypes.ModuleAccountName: {authtypes.Minter},
|
hardtypes.ModuleAccountName: {authtypes.Minter},
|
||||||
savingstypes.ModuleAccountName: nil,
|
savingstypes.ModuleAccountName: nil,
|
||||||
|
bridgetypes.ModuleName: {authtypes.Minter, authtypes.Burner},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -283,6 +289,8 @@ type App struct {
|
|||||||
incentiveKeeper incentivekeeper.Keeper
|
incentiveKeeper incentivekeeper.Keeper
|
||||||
savingsKeeper savingskeeper.Keeper
|
savingsKeeper savingskeeper.Keeper
|
||||||
|
|
||||||
|
bridgeKeeper bridgekeeper.Keeper
|
||||||
|
|
||||||
// make scoped keepers public for test purposes
|
// make scoped keepers public for test purposes
|
||||||
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
|
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
|
||||||
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
|
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
|
||||||
@ -336,7 +344,7 @@ func NewApp(
|
|||||||
issuancetypes.StoreKey, bep3types.StoreKey, pricefeedtypes.StoreKey,
|
issuancetypes.StoreKey, bep3types.StoreKey, pricefeedtypes.StoreKey,
|
||||||
swaptypes.StoreKey, cdptypes.StoreKey, hardtypes.StoreKey,
|
swaptypes.StoreKey, cdptypes.StoreKey, hardtypes.StoreKey,
|
||||||
committeetypes.StoreKey, incentivetypes.StoreKey, evmutiltypes.StoreKey,
|
committeetypes.StoreKey, incentivetypes.StoreKey, evmutiltypes.StoreKey,
|
||||||
savingstypes.StoreKey,
|
savingstypes.StoreKey, bridgetypes.StoreKey,
|
||||||
)
|
)
|
||||||
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey)
|
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey)
|
||||||
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
|
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
|
||||||
@ -380,6 +388,7 @@ func NewApp(
|
|||||||
ibctransferSubspace := app.paramsKeeper.Subspace(ibctransfertypes.ModuleName)
|
ibctransferSubspace := app.paramsKeeper.Subspace(ibctransfertypes.ModuleName)
|
||||||
feemarketSubspace := app.paramsKeeper.Subspace(feemarkettypes.ModuleName)
|
feemarketSubspace := app.paramsKeeper.Subspace(feemarkettypes.ModuleName)
|
||||||
evmSubspace := app.paramsKeeper.Subspace(evmtypes.ModuleName)
|
evmSubspace := app.paramsKeeper.Subspace(evmtypes.ModuleName)
|
||||||
|
bridgeSubspace := app.paramsKeeper.Subspace(bridgetypes.ModuleName)
|
||||||
|
|
||||||
bApp.SetParamStore(
|
bApp.SetParamStore(
|
||||||
app.paramsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable()),
|
app.paramsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable()),
|
||||||
@ -495,6 +504,23 @@ func NewApp(
|
|||||||
app.ModuleAccountAddrs(),
|
app.ModuleAccountAddrs(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// BridgeKeeper must be assigned before EvmKeeper hooks are set
|
||||||
|
app.bridgeKeeper = bridgekeeper.NewKeeper(
|
||||||
|
appCodec,
|
||||||
|
keys[bridgetypes.StoreKey],
|
||||||
|
bridgeSubspace,
|
||||||
|
app.bankKeeper,
|
||||||
|
app.accountKeeper,
|
||||||
|
app.evmKeeper,
|
||||||
|
)
|
||||||
|
|
||||||
|
app.evmKeeper = app.evmKeeper.SetHooks(
|
||||||
|
evmkeeper.NewMultiEvmHooks(
|
||||||
|
app.bridgeKeeper.WithdrawHooks(),
|
||||||
|
app.bridgeKeeper.ConversionHooks(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
govRouter := govtypes.NewRouter()
|
govRouter := govtypes.NewRouter()
|
||||||
govRouter.
|
govRouter.
|
||||||
AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
|
AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
|
||||||
@ -668,6 +694,7 @@ func NewApp(
|
|||||||
incentive.NewAppModule(app.incentiveKeeper, app.accountKeeper, app.bankKeeper, app.cdpKeeper),
|
incentive.NewAppModule(app.incentiveKeeper, app.accountKeeper, app.bankKeeper, app.cdpKeeper),
|
||||||
evmutil.NewAppModule(app.evmutilKeeper, app.bankKeeper),
|
evmutil.NewAppModule(app.evmutilKeeper, app.bankKeeper),
|
||||||
savings.NewAppModule(app.savingsKeeper, app.accountKeeper, app.bankKeeper),
|
savings.NewAppModule(app.savingsKeeper, app.accountKeeper, app.bankKeeper),
|
||||||
|
bridge.NewAppModule(app.bridgeKeeper, app.accountKeeper),
|
||||||
)
|
)
|
||||||
|
|
||||||
app.mm.SetOrderBeginBlockers(
|
app.mm.SetOrderBeginBlockers(
|
||||||
@ -704,7 +731,16 @@ func NewApp(
|
|||||||
vestingtypes.ModuleName,
|
vestingtypes.ModuleName,
|
||||||
pricefeedtypes.ModuleName,
|
pricefeedtypes.ModuleName,
|
||||||
validatorvestingtypes.ModuleName,
|
validatorvestingtypes.ModuleName,
|
||||||
authtypes.ModuleName, banktypes.ModuleName, govtypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, ibctransfertypes.ModuleName, paramstypes.ModuleName, evmutiltypes.ModuleName, savingstypes.ModuleName,
|
authtypes.ModuleName,
|
||||||
|
banktypes.ModuleName,
|
||||||
|
govtypes.ModuleName,
|
||||||
|
crisistypes.ModuleName,
|
||||||
|
genutiltypes.ModuleName,
|
||||||
|
ibctransfertypes.ModuleName,
|
||||||
|
paramstypes.ModuleName,
|
||||||
|
evmutiltypes.ModuleName,
|
||||||
|
savingstypes.ModuleName,
|
||||||
|
bridgetypes.ModuleName,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Warning: Some end blockers must run before others. Ensure the dependencies are understood before modifying this list.
|
// Warning: Some end blockers must run before others. Ensure the dependencies are understood before modifying this list.
|
||||||
@ -737,7 +773,16 @@ func NewApp(
|
|||||||
pricefeedtypes.ModuleName,
|
pricefeedtypes.ModuleName,
|
||||||
ibchost.ModuleName,
|
ibchost.ModuleName,
|
||||||
validatorvestingtypes.ModuleName,
|
validatorvestingtypes.ModuleName,
|
||||||
authtypes.ModuleName, banktypes.ModuleName, govtypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, ibctransfertypes.ModuleName, paramstypes.ModuleName, evmutiltypes.ModuleName, savingstypes.ModuleName,
|
authtypes.ModuleName,
|
||||||
|
banktypes.ModuleName,
|
||||||
|
govtypes.ModuleName,
|
||||||
|
crisistypes.ModuleName,
|
||||||
|
genutiltypes.ModuleName,
|
||||||
|
ibctransfertypes.ModuleName,
|
||||||
|
paramstypes.ModuleName,
|
||||||
|
evmutiltypes.ModuleName,
|
||||||
|
savingstypes.ModuleName,
|
||||||
|
bridgetypes.ModuleName,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Warning: Some init genesis methods must run before others. Ensure the dependencies are understood before modifying this list
|
// Warning: Some init genesis methods must run before others. Ensure the dependencies are understood before modifying this list
|
||||||
@ -766,6 +811,9 @@ func NewApp(
|
|||||||
hardtypes.ModuleName,
|
hardtypes.ModuleName,
|
||||||
incentivetypes.ModuleName, // reads cdp params, so must run after cdp genesis
|
incentivetypes.ModuleName, // reads cdp params, so must run after cdp genesis
|
||||||
committeetypes.ModuleName,
|
committeetypes.ModuleName,
|
||||||
|
evmutiltypes.ModuleName,
|
||||||
|
savingstypes.ModuleName,
|
||||||
|
bridgetypes.ModuleName,
|
||||||
genutiltypes.ModuleName, // runs arbitrary txs included in genisis state, so run after modules have been initialized
|
genutiltypes.ModuleName, // runs arbitrary txs included in genisis state, so run after modules have been initialized
|
||||||
crisistypes.ModuleName, // runs the invariants at genesis, should run after other modules
|
crisistypes.ModuleName, // runs the invariants at genesis, should run after other modules
|
||||||
// Add all remaining modules with an empty InitGenesis below since cosmos 0.45.0 requires it
|
// Add all remaining modules with an empty InitGenesis below since cosmos 0.45.0 requires it
|
||||||
@ -773,8 +821,6 @@ func NewApp(
|
|||||||
paramstypes.ModuleName,
|
paramstypes.ModuleName,
|
||||||
upgradetypes.ModuleName,
|
upgradetypes.ModuleName,
|
||||||
validatorvestingtypes.ModuleName,
|
validatorvestingtypes.ModuleName,
|
||||||
evmutiltypes.ModuleName,
|
|
||||||
savingstypes.ModuleName,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
app.mm.RegisterInvariants(&app.crisisKeeper)
|
app.mm.RegisterInvariants(&app.crisisKeeper)
|
||||||
|
@ -11,6 +11,14 @@ evmFaucetMnemonic="hundred flash cattle inquiry gorilla quick enact lazy galaxy
|
|||||||
# 0x3C854F92F726A7897C8B23F55B2D6E2C482EF3E0
|
# 0x3C854F92F726A7897C8B23F55B2D6E2C482EF3E0
|
||||||
# kava18jz5lyhhy6ncjlyty064kttw93yzaulq7rlptu
|
# kava18jz5lyhhy6ncjlyty064kttw93yzaulq7rlptu
|
||||||
|
|
||||||
|
userMnemonic="news tornado sponsor drastic dolphin awful plastic select true lizard width idle ability pigeon runway lift oppose isolate maple aspect safe jungle author hole"
|
||||||
|
# 0x7Bbf300890857b8c241b219C6a489431669b3aFA
|
||||||
|
# kava10wlnqzyss4accfqmyxwx5jy5x9nfkwh6qm7n4t
|
||||||
|
|
||||||
|
relayerMnemonic="never reject sniff east arctic funny twin feed upper series stay shoot vivid adapt defense economy pledge fetch invite approve ceiling admit gloom exit"
|
||||||
|
# 0xa2F728F997f62F47D4262a70947F6c36885dF9fa
|
||||||
|
# kava15tmj37vh7ch504px9fcfglmvx6y9m70646ev8t
|
||||||
|
|
||||||
DATA=~/.kava
|
DATA=~/.kava
|
||||||
# remove any old state and config
|
# remove any old state and config
|
||||||
rm -rf $DATA
|
rm -rf $DATA
|
||||||
@ -47,6 +55,14 @@ evmFaucetKeyName="evm-faucet"
|
|||||||
printf "$evmFaucetMnemonic\n" | $BINARY keys add $evmFaucetKeyName --eth --recover
|
printf "$evmFaucetMnemonic\n" | $BINARY keys add $evmFaucetKeyName --eth --recover
|
||||||
$BINARY add-genesis-account $evmFaucetKeyName 1000000000ukava
|
$BINARY add-genesis-account $evmFaucetKeyName 1000000000ukava
|
||||||
|
|
||||||
|
userKeyName="user"
|
||||||
|
printf "$userMnemonic\n" | $BINARY keys add $userKeyName --eth --recover
|
||||||
|
$BINARY add-genesis-account $userKeyName 1000000000ukava
|
||||||
|
|
||||||
|
relayerKeyName="relayer"
|
||||||
|
printf "$relayerMnemonic\n" | $BINARY keys add $relayerKeyName --eth --recover
|
||||||
|
$BINARY add-genesis-account $relayerKeyName 1000000000ukava
|
||||||
|
|
||||||
# Create a delegation tx for the validator and add to genesis
|
# Create a delegation tx for the validator and add to genesis
|
||||||
$BINARY gentx $validatorKeyName 1000000000ukava --keyring-backend test --chain-id $chainID
|
$BINARY gentx $validatorKeyName 1000000000ukava --keyring-backend test --chain-id $chainID
|
||||||
$BINARY collect-gentxs
|
$BINARY collect-gentxs
|
||||||
@ -59,3 +75,35 @@ sed -in-place='' 's/aphoton/akava/g' $DATA/config/genesis.json
|
|||||||
|
|
||||||
# Zero out the total supply so it gets recalculated during InitGenesis
|
# Zero out the total supply so it gets recalculated during InitGenesis
|
||||||
jq '.app_state.bank.supply = []' $DATA/config/genesis.json|sponge $DATA/config/genesis.json
|
jq '.app_state.bank.supply = []' $DATA/config/genesis.json|sponge $DATA/config/genesis.json
|
||||||
|
|
||||||
|
# Enable bridge
|
||||||
|
jq '.app_state.bridge.params.bridge_enabled = true' $DATA/config/genesis.json | sponge $DATA/config/genesis.json
|
||||||
|
|
||||||
|
# Set relayer to devnet relayer address
|
||||||
|
jq '.app_state.bridge.params.relayer = "kava15tmj37vh7ch504px9fcfglmvx6y9m70646ev8t"' $DATA/config/genesis.json | sponge $DATA/config/genesis.json
|
||||||
|
|
||||||
|
# Set enabled erc20 tokens to match local geth testnet
|
||||||
|
jq '.app_state.bridge.params.enabled_erc20_tokens = [
|
||||||
|
{
|
||||||
|
address: "0x6098c27D41ec6dc280c2200A737D443b0AaA2E8F",
|
||||||
|
name: "Wrapped ETH",
|
||||||
|
symbol: "WETH",
|
||||||
|
decimals: 18,
|
||||||
|
minimum_withdraw_amount: "10000000000000000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
address: "0x4Fb48E68842bb59f07569c623ACa5826b600F8F7",
|
||||||
|
name: "USDC",
|
||||||
|
symbol: "USDC",
|
||||||
|
decimals: 6,
|
||||||
|
minimum_withdraw_amount: "10000000"
|
||||||
|
}]' $DATA/config/genesis.json | sponge $DATA/config/genesis.json
|
||||||
|
|
||||||
|
# Set enabled conversion pairs - weth address is the first contract bridge module
|
||||||
|
# deploys
|
||||||
|
jq '.app_state.bridge.params.enabled_conversion_pairs = [
|
||||||
|
{
|
||||||
|
kava_erc20_address: "0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
||||||
|
denom: "erc20/weth",
|
||||||
|
}]' $DATA/config/genesis.json | sponge $DATA/config/genesis.json
|
||||||
|
|
||||||
|
7
go.mod
7
go.mod
@ -3,7 +3,7 @@ module github.com/kava-labs/kava
|
|||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cosmos/cosmos-proto v0.0.0-20211020182451-c7ca7198c2f8
|
github.com/cosmos/cosmos-proto v1.0.0-alpha6
|
||||||
github.com/cosmos/cosmos-sdk v0.45.1
|
github.com/cosmos/cosmos-sdk v0.45.1
|
||||||
github.com/cosmos/ibc-go/v3 v3.0.0
|
github.com/cosmos/ibc-go/v3 v3.0.0
|
||||||
github.com/ethereum/go-ethereum v1.10.16
|
github.com/ethereum/go-ethereum v1.10.16
|
||||||
@ -12,6 +12,7 @@ require (
|
|||||||
github.com/golang/protobuf v1.5.2
|
github.com/golang/protobuf v1.5.2
|
||||||
github.com/gorilla/mux v1.8.0
|
github.com/gorilla/mux v1.8.0
|
||||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0
|
github.com/grpc-ecosystem/grpc-gateway v1.16.0
|
||||||
|
github.com/kava-labs/kava-bridge v0.1.1
|
||||||
github.com/spf13/cast v1.4.1
|
github.com/spf13/cast v1.4.1
|
||||||
github.com/spf13/cobra v1.4.0
|
github.com/spf13/cobra v1.4.0
|
||||||
github.com/stretchr/testify v1.7.1
|
github.com/stretchr/testify v1.7.1
|
||||||
@ -21,7 +22,7 @@ require (
|
|||||||
google.golang.org/genproto v0.0.0-20220211171837-173942840c17
|
google.golang.org/genproto v0.0.0-20220211171837-173942840c17
|
||||||
google.golang.org/grpc v1.44.0
|
google.golang.org/grpc v1.44.0
|
||||||
google.golang.org/protobuf v1.28.0
|
google.golang.org/protobuf v1.28.0
|
||||||
sigs.k8s.io/yaml v1.2.0
|
sigs.k8s.io/yaml v1.3.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@ -32,6 +33,7 @@ require (
|
|||||||
github.com/StackExchange/wmi v1.2.1 // indirect
|
github.com/StackExchange/wmi v1.2.1 // indirect
|
||||||
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
|
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
|
||||||
github.com/Workiva/go-datastructures v1.0.53 // indirect
|
github.com/Workiva/go-datastructures v1.0.53 // indirect
|
||||||
|
github.com/allegro/bigcache v1.2.1 // indirect
|
||||||
github.com/armon/go-metrics v0.3.10 // indirect
|
github.com/armon/go-metrics v0.3.10 // indirect
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/bgentry/speakeasy v0.1.0 // indirect
|
github.com/bgentry/speakeasy v0.1.0 // indirect
|
||||||
@ -152,6 +154,7 @@ require (
|
|||||||
replace (
|
replace (
|
||||||
// Use the cosmos keyring code
|
// Use the cosmos keyring code
|
||||||
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
|
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
|
||||||
|
|
||||||
// See https://github.com/cosmos/cosmos-sdk/pull/10401, https://github.com/cosmos/cosmos-sdk/commit/0592ba6158cd0bf49d894be1cef4faeec59e8320
|
// See https://github.com/cosmos/cosmos-sdk/pull/10401, https://github.com/cosmos/cosmos-sdk/commit/0592ba6158cd0bf49d894be1cef4faeec59e8320
|
||||||
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0
|
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0
|
||||||
// Use the cosmos modified protobufs
|
// Use the cosmos modified protobufs
|
||||||
|
Loading…
Reference in New Issue
Block a user