precompile

package
v2.0.0-evm.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

README

Sample Hardhat Project

This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a Hardhat Ignition module that deploys that contract.

Try running some of the following tasks:

npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
npx hardhat ignition deploy ./ignition/modules/Lock.js

Documentation

Overview

Package precompile implements custom precompiles for the Nibiru EVM.

Precompiles are special, built-in contract interfaces that exist at predefined addresses and run custom logic outside of what is possible in standard Solidity contracts. This package extends the default Ethereum precompiles with Nibiru-specific functionality.

Key components:

  • InitPrecompiles: Initializes and returns a map of precompiled contracts.
  • NibiruPrecompile: Interface for Nibiru-specific precompiles.
  • PrecompileFunToken: Implements the FunToken precompile for ERC20-to-bank transfers.

The package also provides utility functions for working with precompiles, such as "ABIMethodByID" and "OnRunStart" for common precompile execution setup.

Index

Constants

This section is empty.

Variables

View Source
var PrecompileAddr_FuntokenGateway = eth.MustNewHexAddrFromStr(
	"0x0000000000000000000000000000000000000800",
)

Precompile address for "FunToken.sol", the contract that enables transfers of ERC20 tokens to "nibi" addresses as bank coins using the ERC20's `FunToken` mapping.

Functions

func ABIMethodByID

func ABIMethodByID(abi *gethabi.ABI, sigdata []byte) (*gethabi.Method, error)

ABIMethodByID: Looks up an ABI method by the 4-byte id. Copy of "ABI.MethodById" from go-ethereum version > 1.10

func ArgsFunTokenBankSend

func ArgsFunTokenBankSend(
	erc20 gethcommon.Address,
	amount *big.Int,
	to sdk.AccAddress,
) []any

ArgsFunTokenBankSend: Constructor for an "args" array of arguments for the "IFunToken.bankSend" function.

func AssertArgCount

func AssertArgCount(args []interface{}, wantNumArgs int) error

func InitPrecompiles

func InitPrecompiles(
	k keepers.PublicKeepers,
) (precompiles map[gethcommon.Address]vm.PrecompiledContract)

InitPrecompiles initializes and returns a map of precompiled contracts for the EVM. It combines default Ethereum precompiles with custom Nibiru precompiles.

Parameters:

  • k: A keepers.PublicKeepers instance providing access to various blockchain state.

Returns:

  • A map of Ethereum addresses to PrecompiledContract implementations.

func OnRunStart

func OnRunStart(
	p NibiruPrecompile, evm *vm.EVM, input []byte,
) (ctx sdk.Context, method *gethabi.Method, args []interface{}, err error)

func PrecompileFunToken

func PrecompileFunToken(keepers keepers.PublicKeepers) vm.PrecompiledContract

Types

type FunTokenMethod

type FunTokenMethod string
const (
	FunTokenMethod_BankSend FunTokenMethod = "bankSend"
)

type NibiruPrecompile

type NibiruPrecompile interface {
	vm.PrecompiledContract
	ABI() *gethabi.ABI
}

NibiruPrecompile is the interface that all Nibiru-specific precompiles must implement.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL