Skip to content

Commit

Permalink
feat(evm): init evm precompiles on start
Browse files Browse the repository at this point in the history
  • Loading branch information
onikonychev committed Jul 1, 2024
1 parent 8a6a59a commit 155737a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

"github.com/NibiruChain/nibiru/app/ante"
"github.com/NibiruChain/nibiru/app/wasmext"
Expand Down Expand Up @@ -259,6 +260,9 @@ func NewNibiruApp(
app.capabilityKeeper.Seal()
}

ctx := sdk.NewContext(app.CommitMultiStore(), tmproto.Header{}, false, nil)
app.EvmKeeper.InitPrecompiles(ctx)

return app
}

Expand Down
22 changes: 22 additions & 0 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ package keeper
import (
"math/big"

"github.com/NibiruChain/collections"
"github.com/NibiruChain/nibiru/precompiles/erc20"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/ethereum/go-ethereum/core"
gethcore "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -81,6 +84,25 @@ func NewKeeper(
}
}

func (k *Keeper) InitPrecompiles(ctx sdk.Context) {
// Create precompile objects for fungible tokens
iter := k.FunTokens.Iterate(ctx, collections.Range[[]byte]{})
defer iter.Close()
for ; iter.Valid(); iter.Next() {
erc20Precompile, err := erc20.NewPrecompile(iter.Value(), k.bankKeeper.(bankkeeper.Keeper))
if err != nil {
panic(err)

Check warning on line 94 in x/evm/keeper/keeper.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/keeper.go#L92-L94

Added lines #L92 - L94 were not covered by tests
}
err = k.AddEVMExtensions(
ctx,
erc20Precompile,
)
if err != nil {
panic(err)

Check warning on line 101 in x/evm/keeper/keeper.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/keeper.go#L96-L101

Added lines #L96 - L101 were not covered by tests
}
}
}

// GetEvmGasBalance: Implements `evm.EVMKeeper` from
// "github.com/NibiruChain/nibiru/app/ante/evm": Load account's balance of gas
// tokens for EVM execution
Expand Down

0 comments on commit 155737a

Please sign in to comment.