Skip to content

Commit

Permalink
Merge branch 'trinity/sdk50' into trinity/testnet-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
trinitys7 committed Nov 4, 2024
2 parents 5ba9bad + ff11ac9 commit 946da07
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 12 deletions.
1 change: 0 additions & 1 deletion app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ func createTx(priv *osecp256k1.PrivKey, msgs ...sdk.Msg) (sdk.Tx, error) {
context.TODO(), defaultSignMode, signerData,
txBuilder, priv, encodingConfig.TxConfig, 0,
)

if err != nil {
return nil, err
}
Expand Down
42 changes: 41 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"fmt"
"io"
"io/fs"
"maps"
"net/http"
"os"
"path/filepath"

"github.com/ethereum/go-ethereum/common"
"github.com/realiotech/realio-network/app/ante"
"github.com/realiotech/realio-network/client/docs"
"github.com/realiotech/realio-network/crypto/ethsecp256k1"
Expand Down Expand Up @@ -40,7 +42,11 @@ import (
srvflags "github.com/evmos/os/server/flags"
ethermint "github.com/evmos/os/types"

"github.com/evmos/os/precompiles/bech32"
"github.com/evmos/os/precompiles/p256"
stakingprecompile "github.com/evmos/os/precompiles/staking"
"github.com/evmos/os/x/evm"
"github.com/evmos/os/x/evm/core/vm"
evmkeeper "github.com/evmos/os/x/evm/keeper"
evmtypes "github.com/evmos/os/x/evm/types"
"github.com/evmos/os/x/feemarket"
Expand Down Expand Up @@ -159,7 +165,8 @@ import (
)

const (
Name = "realio-network"
Name = "realio-network"
bech32PrecompileBaseGas = 6_000
)

var (
Expand Down Expand Up @@ -553,6 +560,9 @@ func New(
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack)
app.IBCKeeper.SetRouter(ibcRouter)

app.EvmKeeper.WithStaticPrecompiles(
RealioPrecompile(*app.StakingKeeper, app.AuthzKeeper),
)
/**** Module Options ****/

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
Expand Down Expand Up @@ -1089,6 +1099,36 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
return paramsKeeper
}

func RealioPrecompile(
stakingKeeper stakingkeeper.Keeper,
authzKeeper authzkeeper.Keeper,
) map[common.Address]vm.PrecompiledContract {
// Clone the mapping from the latest EVM fork.
precompiles := maps.Clone(vm.PrecompiledContractsBerlin)

// secp256r1 precompile as per EIP-7212
p256Precompile := &p256.Precompile{}

bech32Precompile, err := bech32.NewPrecompile(bech32PrecompileBaseGas)
if err != nil {
panic(fmt.Errorf("failed to instantiate bech32 precompile: %w", err))
}

stakingPrecompile, err := stakingprecompile.NewPrecompile(stakingKeeper, authzKeeper)
if err != nil {
panic(fmt.Errorf("failed to instantiate staking precompile: %w", err))
}

// Stateless precompiles
precompiles[bech32Precompile.Address()] = bech32Precompile
precompiles[p256Precompile.Address()] = p256Precompile

// Stateful precompiles
precompiles[stakingPrecompile.Address()] = stakingPrecompile

return precompiles
}

func RealioSigVerificationGasConsumer(
meter storetypes.GasMeter, sig signing.SignatureV2, params authtypes.Params,
) error {
Expand Down
8 changes: 8 additions & 0 deletions app/upgrades/v2/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ func CreateUpgradeHandler(
return nil, err
}

evmParams := evmtypes.DefaultParams()
evmParams.ActiveStaticPrecompiles = []string{
evmtypes.StakingPrecompileAddress,
}
err = evmKeeper.SetParams(sdkCtx, evmParams)
if err != nil {
return nil, err
}
return newVM, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/asset/client/cli/query_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func CmdQueryParams() *cobra.Command {
Use: "params",
Short: "shows the parameters of the module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)
Expand Down
2 changes: 1 addition & 1 deletion x/asset/client/cli/query_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func CmdQueryTokens() *cobra.Command {
Use: "tokens",
Short: "shows the tokens of the module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)
Expand Down
2 changes: 1 addition & 1 deletion x/asset/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ExportGenesis(ctx context.Context, k keeper.Keeper) *types.GenesisState {
}
genesis.Params = params
tokens := []types.Token{}
err = k.Token.Walk(ctx, nil, func(symbol string, token types.Token) (stop bool, err error) {
err = k.Token.Walk(ctx, nil, func(_ string, token types.Token) (stop bool, err error) {
tokens = append(tokens, token)
return false, nil
})
Expand Down
2 changes: 1 addition & 1 deletion x/asset/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (q queryServer) Tokens(c context.Context, req *types.QueryTokensRequest) (*
}

tokens := []types.Token{}
err := q.k.Token.Walk(c, nil, func(symbol string, token types.Token) (stop bool, err error) {
err := q.k.Token.Walk(c, nil, func(_ string, token types.Token) (stop bool, err error) {
tokens = append(tokens, token)
return false, nil
})
Expand Down
6 changes: 3 additions & 3 deletions x/bridge/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func CmdQueryParams() *cobra.Command {
Use: "params",
Short: "shows the parameters of the module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)
Expand All @@ -59,7 +59,7 @@ func CmdQueryRateLimits() *cobra.Command {
Use: "ratelimits",
Short: "shows the ratelimits of the module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)
Expand Down Expand Up @@ -108,7 +108,7 @@ func CmdQueryEpochInfo() *cobra.Command {
Use: "epoch-info",
Short: "shows the epoch info of the module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)
Expand Down
6 changes: 3 additions & 3 deletions x/mint/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func GetCmdQueryParams() *cobra.Command {
Use: "params",
Short: "Query the current minting parameters",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
Expand Down Expand Up @@ -66,7 +66,7 @@ func GetCmdQueryInflation() *cobra.Command {
Use: "inflation",
Short: "Query the current minting inflation value",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
Expand Down Expand Up @@ -95,7 +95,7 @@ func GetCmdQueryAnnualProvisions() *cobra.Command {
Use: "annual-provisions",
Short: "Query the current minting annual provisions value",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
Expand Down

0 comments on commit 946da07

Please sign in to comment.