precompile

package
v2.0.0-rc.8 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: Apache-2.0 Imports: 25 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.
  • 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_FunToken = gethcommon.HexToAddress("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.

View Source
var PrecompileAddr_Oracle = gethcommon.HexToAddress("0x0000000000000000000000000000000000000801")

Precompile address for "Oracle.sol", the contract that enables queries for exchange rates

View Source
var PrecompileAddr_Wasm = gethcommon.HexToAddress("0x0000000000000000000000000000000000000802")

Precompile address for "Wasm.sol",

Functions

func DecomposeInput

func DecomposeInput(
	abi *gethabi.ABI, input []byte,
) (method *gethabi.Method, args []interface{}, err error)

func ErrArgTypeValidation

func ErrArgTypeValidation(solidityHint string, arg any) error

Error short-hand for type validation

func ErrInvalidArgs

func ErrInvalidArgs(err error) error

Error when parsing method arguments

func ErrMethodCalled

func ErrMethodCalled(method *gethabi.Method, wrapped error) 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 PrecompileFunToken

func PrecompileFunToken(keepers keepers.PublicKeepers) vm.PrecompiledContract

func PrecompileOracle

func PrecompileOracle(keepers keepers.PublicKeepers) vm.PrecompiledContract

func PrecompileWasm

func PrecompileWasm(keepers keepers.PublicKeepers) vm.PrecompiledContract

func RequiredGas

func RequiredGas(input []byte, abi *gethabi.ABI) uint64

Types

type OracleMethod

type OracleMethod string
const (
	OracleMethod_QueryExchangeRate OracleMethod = "queryExchangeRate"
)

type PrecompileMethod

type PrecompileMethod string
const (
	WasmMethod_execute      PrecompileMethod = "execute"
	WasmMethod_query        PrecompileMethod = "query"
	WasmMethod_instantiate  PrecompileMethod = "instantiate"
	WasmMethod_executeMulti PrecompileMethod = "executeMulti"
	WasmMethod_queryRaw     PrecompileMethod = "queryRaw"
)

Contract methods from Wasm.sol

const (
	FunTokenMethod_BankSend PrecompileMethod = "bankSend"
)

type Wasm

Wasm: A struct embedding keepers for read and write operations in Wasm, such as execute, query, and instantiate.

type WasmBankCoin

type WasmBankCoin struct {
	Denom  string   `json:"denom"`
	Amount *big.Int `json:"amount"`
}

WasmBankCoin is a naked struct for the "BankCoin" type from Wasm.sol. The ABI parser requires an unnamed strict, so this type is only used in tests.

Jump to

Keyboard shortcuts

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