* clear

* feat: Add everything

* fix: Commenht
This commit is contained in:
Prad Nukala
2025-10-03 14:45:52 -04:00
committed by GitHub
parent 43b4a11c06
commit 13e6c3e84d
1935 changed files with 655061 additions and 40058 deletions
+127
View File
@@ -0,0 +1,127 @@
// Package app provides EVM precompiled contracts configuration for the Sonr blockchain.
package app
import (
"fmt"
"maps"
evidencekeeper "cosmossdk.io/x/evidence/keeper"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
bankprecompile "github.com/cosmos/evm/precompiles/bank"
"github.com/cosmos/evm/precompiles/bech32"
distprecompile "github.com/cosmos/evm/precompiles/distribution"
evidenceprecompile "github.com/cosmos/evm/precompiles/evidence"
govprecompile "github.com/cosmos/evm/precompiles/gov"
ics20precompile "github.com/cosmos/evm/precompiles/ics20"
"github.com/cosmos/evm/precompiles/p256"
slashingprecompile "github.com/cosmos/evm/precompiles/slashing"
stakingprecompile "github.com/cosmos/evm/precompiles/staking"
erc20Keeper "github.com/cosmos/evm/x/erc20/keeper"
transferkeeper "github.com/cosmos/evm/x/ibc/transfer/keeper"
"github.com/cosmos/evm/x/vm/core/vm"
evmkeeper "github.com/cosmos/evm/x/vm/keeper"
channelkeeper "github.com/cosmos/ibc-go/v8/modules/core/04-channel/keeper"
"github.com/ethereum/go-ethereum/common"
)
// bech32PrecompileBaseGas defines the base gas cost for bech32 address conversion operations.
const bech32PrecompileBaseGas = 6_000
// NewAvailableStaticPrecompiles returns the list of all available static precompiled contracts from EVM.
// These precompiles provide native Cosmos SDK functionality accessible from EVM contracts,
// including staking, distribution, governance, bank transfers, IBC transfers, and more.
//
// The function initializes both stateless precompiles (bech32, p256) and stateful precompiles
// that interact with Cosmos SDK modules.
//
// NOTE: this should only be used during initialization of the Keeper.
func NewAvailableStaticPrecompiles(
stakingKeeper stakingkeeper.Keeper,
distributionKeeper distributionkeeper.Keeper,
bankKeeper bankkeeper.Keeper,
erc20Keeper erc20Keeper.Keeper,
authzKeeper authzkeeper.Keeper,
transferKeeper transferkeeper.Keeper,
channelKeeper channelkeeper.Keeper,
evmKeeper *evmkeeper.Keeper,
govKeeper govkeeper.Keeper,
slashingKeeper slashingkeeper.Keeper,
evidenceKeeper evidencekeeper.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))
}
distributionPrecompile, err := distprecompile.NewPrecompile(
distributionKeeper,
stakingKeeper,
authzKeeper,
evmKeeper,
)
if err != nil {
panic(fmt.Errorf("failed to instantiate distribution precompile: %w", err))
}
ibcTransferPrecompile, err := ics20precompile.NewPrecompile(
stakingKeeper,
transferKeeper,
channelKeeper,
authzKeeper,
evmKeeper,
)
if err != nil {
panic(fmt.Errorf("failed to instantiate ICS20 precompile: %w", err))
}
bankPrecompile, err := bankprecompile.NewPrecompile(bankKeeper, erc20Keeper)
if err != nil {
panic(fmt.Errorf("failed to instantiate bank precompile: %w", err))
}
govPrecompile, err := govprecompile.NewPrecompile(govKeeper, authzKeeper)
if err != nil {
panic(fmt.Errorf("failed to instantiate gov precompile: %w", err))
}
slashingPrecompile, err := slashingprecompile.NewPrecompile(slashingKeeper, authzKeeper)
if err != nil {
panic(fmt.Errorf("failed to instantiate slashing precompile: %w", err))
}
evidencePrecompile, err := evidenceprecompile.NewPrecompile(evidenceKeeper, authzKeeper)
if err != nil {
panic(fmt.Errorf("failed to instantiate evidence precompile: %w", err))
}
// Stateless precompiles
precompiles[bech32Precompile.Address()] = bech32Precompile
precompiles[p256Precompile.Address()] = p256Precompile
// Stateful precompiles
precompiles[stakingPrecompile.Address()] = stakingPrecompile
precompiles[distributionPrecompile.Address()] = distributionPrecompile
precompiles[ibcTransferPrecompile.Address()] = ibcTransferPrecompile
precompiles[bankPrecompile.Address()] = bankPrecompile
precompiles[govPrecompile.Address()] = govPrecompile
precompiles[slashingPrecompile.Address()] = slashingPrecompile
precompiles[evidencePrecompile.Address()] = evidencePrecompile
return precompiles
}