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

Add channel selector from chainID #2172

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (staking-precompile) [#2122](https://github.com/evmos/evmos/pull/2122) Replace bech32 address with EVM hex address for `CreateValidator` function and remove delegator address argument.
- (app) [#2139](https://github.com/evmos/evmos/pull/2139) Remove old upgrade handlers logic.
- (app) [#2138](https://github.com/evmos/evmos/pull/2138) Replace imports of store related types and functions to use Cosmos-SDK `store/types` package.
- (outpost) [#2171](https://github.com/evmos/evmos/pull/2171) Add channelID selector based on the ChainID.

### Bug Fixes

Expand Down
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,11 @@ func NewEvmos(
app.AccountKeeper, app.BankKeeper, scopedTransferKeeper,
app.Erc20Keeper, // Add ERC20 Keeper for ERC20 transfers
)

chainID := bApp.ChainID()
// We call this after setting the hooks to ensure that the hooks are set on the keeper
evmKeeper.WithPrecompiles(
evmkeeper.AvailablePrecompiles(
chainID,
*stakingKeeper,
app.DistrKeeper,
app.BankKeeper,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ replace (
// use cosmos fork of keyring
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
// use Cosmos-SDK fork to enable Ledger functionality
github.com/cosmos/cosmos-sdk => github.com/evmos/cosmos-sdk v0.47.5-evmos
github.com/cosmos/cosmos-sdk => github.com/evmos/cosmos-sdk v0.47.5-evmos.2
// use Evmos geth fork
github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26-evmos-rc2
// Security Advisory https://github.com/advisories/GHSA-h395-qcrw-5vmq
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.m
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evmos/cosmos-sdk v0.47.5-evmos h1:whqu51IyyDeINswUPNxDrm1WsvD7Bzo8XR71Ttt3DIc=
github.com/evmos/cosmos-sdk v0.47.5-evmos/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c=
github.com/evmos/cosmos-sdk v0.47.5-evmos.2 h1:fyhM0NYw/FnP4ZBXzQ7k+G4fXhfdU07MONoYrGlOCpc=
github.com/evmos/cosmos-sdk v0.47.5-evmos.2/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c=
github.com/evmos/go-ethereum v1.10.26-evmos-rc2 h1:tYghk1ZZ8X4/OQ4YI9hvtm8aSN8OSqO0g9vo/sCMdBo=
github.com/evmos/go-ethereum v1.10.26-evmos-rc2/go.mod h1:/6CsT5Ceen2WPLI/oCA3xMcZ5sWMF/D46SjM/ayY0Oo=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
Expand Down
7 changes: 4 additions & 3 deletions precompiles/outposts/osmosis/osmosis.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ const (
OsmosisOutpostAddress = "0x0000000000000000000000000000000000000901"

// XCSContract address for Osmosis testnet.
XCSContractTestnet = "osmo18rj46qcpr57m3qncrj9cuzm0gn3km08w5jxxlnw002c9y7xex5xsu74ytz"
// XCSContract address for Osmosis mainnet.
XCSContractMainnet = ""
XCSContractTestnet = "osmo1a34wxsxjwvtz3ua4hnkh4lv3d4qrgry0fhkasppplphwu5k538tqcyms9x"
//
// TODO: change it with the correct mainnet one
XCSContractMainnet = "osmo18rj46qcpr57m3qncrj9cuzm0gn3km08w5jxxlnw002c9y7xex5xsu74ytz"
)

var _ vm.PrecompiledContract = &Precompile{}
Expand Down
38 changes: 32 additions & 6 deletions x/evm/keeper/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (

"github.com/evmos/evmos/v16/precompiles/bech32"

"golang.org/x/exp/maps"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"golang.org/x/exp/maps"

sdk "github.com/cosmos/cosmos-sdk/types"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
Expand All @@ -30,14 +29,17 @@ import (
"github.com/evmos/evmos/v16/precompiles/p256"
stakingprecompile "github.com/evmos/evmos/v16/precompiles/staking"
vestingprecompile "github.com/evmos/evmos/v16/precompiles/vesting"
"github.com/evmos/evmos/v16/utils"
erc20Keeper "github.com/evmos/evmos/v16/x/erc20/keeper"
transferkeeper "github.com/evmos/evmos/v16/x/ibc/transfer/keeper"
evmostransfertypes "github.com/evmos/evmos/v16/x/ibc/transfer/types"
vestingkeeper "github.com/evmos/evmos/v16/x/vesting/keeper"
)

// AvailablePrecompiles returns the list of all available precompiled contracts.
// NOTE: this should only be used during initialization of the Keeper.
func AvailablePrecompiles(
chainID string,
stakingKeeper stakingkeeper.Keeper,
distributionKeeper distributionkeeper.Keeper,
bankKeeper bankkeeper.Keeper,
Expand Down Expand Up @@ -83,15 +85,39 @@ func AvailablePrecompiles(
panic(fmt.Errorf("failed to instantiate bank precompile: %w", err))
}

strideOutpost, err := strideoutpost.NewPrecompile(transfertypes.PortID, "channel-25", transferKeeper, erc20Keeper, authzKeeper, stakingKeeper)
var strideChannelID, osmosisChannelID, xcsv1Contract string
if utils.IsMainnet(chainID) {
osmosisChannelID = evmostransfertypes.OsmosisMainnetChannelID
strideChannelID = evmostransfertypes.StrideMainnetChannelID
xcsv1Contract = osmosisoutpost.XCSContractMainnet
} else {
osmosisChannelID = evmostransfertypes.OsmosisTestnetChannelID
strideChannelID = evmostransfertypes.StrideTestnetChannelID
xcsv1Contract = osmosisoutpost.XCSContractMainnet
}

strideOutpost, err := strideoutpost.NewPrecompile(
transfertypes.PortID,
strideChannelID,
transferKeeper,
erc20Keeper,
authzKeeper,
stakingKeeper,
)
if err != nil {
panic(fmt.Errorf("failed to instantiate stride outpost: %w", err))
}

osmosisOutpost, err := osmosisoutpost.NewPrecompile(
transfertypes.PortID, "channel-215",
osmosisoutpost.XCSContractTestnet,
authzKeeper, bankKeeper, transferKeeper, stakingKeeper, erc20Keeper, channelKeeper,
transfertypes.PortID,
osmosisChannelID,
xcsv1Contract,
authzKeeper,
bankKeeper,
transferKeeper,
stakingKeeper,
erc20Keeper,
channelKeeper,
)
if err != nil {
panic(fmt.Errorf("failed to instantiate osmosis outpost: %w", err))
Expand Down
15 changes: 15 additions & 0 deletions x/ibc/transfer/types/channels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright Tharsis Labs Ltd.(Evmos)
// SPDX-License-Identifier:ENCL-1.0(https://github.com/evmos/evmos/blob/main/LICENSE)
package types

// Osmosis channels
const (
OsmosisTestnetChannelID = "channel-215"
OsmosisMainnetChannelID = "channel-0"
)

// Stride channels
const (
StrideTestnetChannelID = "channel-25"
StrideMainnetChannelID = "channel-25"
)