-
Notifications
You must be signed in to change notification settings - Fork 41
/
evm_utils.go
73 lines (59 loc) · 2.52 KB
/
evm_utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package app
import (
"fmt"
"github.com/evmos/evmos/v16/precompiles/bech32"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"golang.org/x/exp/maps"
// staking and distribution precompiles
distprecompile "github.com/aura-nw/aura/precompiles/distribution"
stakingprecompile "github.com/aura-nw/aura/precompiles/staking"
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"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
channelkeeper "github.com/cosmos/ibc-go/v7/modules/core/04-channel/keeper"
ics20precompile "github.com/evmos/evmos/v16/precompiles/ics20"
"github.com/evmos/evmos/v16/precompiles/p256"
erc20Keeper "github.com/evmos/evmos/v16/x/erc20/keeper"
transferkeeper "github.com/evmos/evmos/v16/x/ibc/transfer/keeper"
)
func Precompiles(
chainID string,
stakingKeeper stakingkeeper.Keeper,
distributionKeeper distributionkeeper.Keeper,
bankKeeper bankkeeper.Keeper,
erc20Keeper erc20Keeper.Keeper,
authzKeeper authzkeeper.Keeper,
transferKeeper transferkeeper.Keeper,
channelKeeper channelkeeper.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(6000)
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)
if err != nil {
panic(fmt.Errorf("failed to instantiate distribution precompile: %w", err))
}
ibcTransferPrecompile, err := ics20precompile.NewPrecompile(transferKeeper, channelKeeper, authzKeeper)
if err != nil {
panic(fmt.Errorf("failed to instantiate ICS20 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
return precompiles
}