embeds

package
v2.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: BSD-2-Clause Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

@nibiruchain/solidity

Nibiru EVM solidity contracts and ABIs for Nibiru-specific precompiles and core protocol functionality.

Install

bun add @nibiruchain/solidity
# OR npm install

Solidity code is in "@nibiruchain/solidity/contracts/*", and ABI JSON files are in "@nibiruchain/solidity/abi/*".

ABI Files

Since contract ABIs are exported in JSON format, these ABIs can be used with any Ethereum-compatible JS library, such as:

  • Viem
  • Ethers.js
  • Web3.js
  • Hardhat or Foundry
// Example import
import wasmAbi from "@nibiruchain/solidity/abi/IWasm.json"

Usage with Typechain for Ethers v6

Often when building an application using Ethers.js, we want type-safe contract interactions. The typechain and @typechain/ethers-v6 packages are a useful tool to generate TypeScript code an ethers.Contract directly from smart contract ABIs.

To generate ethers TypeScript bindings for the ABIs exported from the @nibiruchain/solidity package, first install the required dependencies:

npm install -D @nibiruchain/solidity @typechain/ethers-v6@0.5 typechain@8

Then, you can generate like so.

out_dir="typechain-out"
npm run typechain \
  --target=ethers-v6 \
  --out-dir="$out_dir" \
  "$(pwd)/node_modules/@nibiruchain/solidity/abi/*.json" 

This ensures contract interactions are type-checked at compile-time, helping reduce the likelihood of runtime errors.

Usage in Solidity

This package exports interfaces, types, and constants for each Nibiru-specific precompiled contract. To use these precompiles in Solidity, use the exported constant that represents an instance of the precompile.

Similarly, the fungible token precompile defines:

IFunToken constant FUNTOKEN_PRECOMPILE = IFunToken(FUNTOKEN_PRECOMPILE_ADDRESS);

So, you import this in your contract

import '@nibiruchain/solidity/contracts/IFunToken.sol';

// Methods:
// FUNTOKEN_PRECOMPILE.sendToBank
// FUNTOKEN_PRECOMPILE.sendToEvm
// FUNTOKEN_PRECOMPILE.balance
// FUNTOKEN_PRECOMPILE.bankBalance
// FUNTOKEN_PRECOMPILE.bankMsgSend
// FUNTOKEN_PRECOMPILE.whoAmI

Hacking

Hacking - Nibiru EVM Solidity Embeds

Documentation

Overview

Package "embeds" adds access to files (smart contracts) embedded in the Go runtime. Go source files that import "embed" can use the //go:embed directive to initialize a variable of type string, \[]byte, or \[FS] with the contents of files read from the package directory or subdirectories at compile time.

Index

Constants

This section is empty.

Variables

View Source
var (
	// SmartContract_ErisEvm is the canonical proxy implementation for liquid staking and governance.
	SmartContract_ErisEvm = CompiledEvmContract{Name: "ErisEvm.sol", EmbedJSON: erisEvmJSON}
	// SmartContract_ERC20Minter is the original ERC20 minter for Bank-origin FunTokens.
	SmartContract_ERC20Minter = CompiledEvmContract{
		Name:      "ERC20Minter.sol",
		EmbedJSON: erc20MinterContractJSON,
	}

	// Enhanced ERC20 contract with metadata update capabilities
	SmartContract_ERC20MinterWithMetadataUpdates = CompiledEvmContract{
		Name:      "ERC20MinterWithMetadataUpdates.sol",
		EmbedJSON: erc20MinterWithMetadataUpdatesContractJSON,
	}

	// SmartContract_Funtoken: Precompile contract interface for
	// "IFunToken.sol". This precompile enables transfers of ERC20 tokens
	// to non-EVM accounts. Only the ABI is used.
	SmartContract_FunToken = CompiledEvmContract{
		Name:      "IFunToken.sol",
		EmbedJSON: funtokenPrecompileJSON,
	}

	// SmartContract_Funtoken: Precompile contract interface for
	// "Wasm.sol". This precompile enables contract invocations in the Wasm VM
	// from EVM accounts. Only the ABI is used.
	SmartContract_Wasm = CompiledEvmContract{
		Name:      "Wasm.sol",
		EmbedJSON: wasmPrecompileJSON,
	}
	// SmartContract_Oracle: Precompile contract interface for "IOracle.sol".
	// Only the ABI is used.
	SmartContract_Oracle = CompiledEvmContract{
		Name:      "IOracle.sol",
		EmbedJSON: oraclePrecompileJSON,
	}
	// SmartContract_Funtoken: Wrapped NIBI contract ERC20.
	SmartContract_WNIBI = CompiledEvmContract{
		Name:      "WNIBI.sol",
		EmbedJSON: wnibiContractJSON,
	}

	SmartContract_TestERC20 = CompiledEvmContract{
		Name:      "TestERC20.sol",
		EmbedJSON: testErc20Json,
	}
	// SmartContract_TestERC20MaliciousName is a test contract
	// which simulates malicious ERC20 behavior by adding gas intensive operation
	// for function name() intended to attack funtoken creation
	SmartContract_TestERC20MaliciousName = CompiledEvmContract{
		Name:      "TestERC20MaliciousName.sol",
		EmbedJSON: testErc20MaliciousNameJson,
	}
	// SmartContract_TestERC20MaliciousTransfer is a test contract
	// which simulates malicious ERC20 behavior by adding gas intensive operation
	// for function transfer() intended to attack funtoken conversion from erc20 to bank coin
	SmartContract_TestERC20MaliciousTransfer = CompiledEvmContract{
		Name:      "TestERC20MaliciousTransfer.sol",
		EmbedJSON: testErc20MaliciousTransferJson,
	}
	// SmartContract_TestERC20MaliciousCallback is a test contract that attempts
	// mutable precompile calls from inside ERC20.transfer, used to validate
	// VM-sender guard enforcement for module-originated callback windows.
	SmartContract_TestERC20MaliciousCallback = CompiledEvmContract{
		Name:      "TestERC20MaliciousCallback.sol",
		EmbedJSON: testErc20MaliciousCallbackJson,
	}
	// SmartContract_TestFunTokenPrecompileLocalGas is a test contract
	// which allows precompile execution with custom local gas set (calling precompile within contract)
	SmartContract_TestFunTokenPrecompileLocalGas = CompiledEvmContract{
		Name:      "TestFunTokenPrecompileLocalGas.sol",
		EmbedJSON: testFunTokenPrecompileLocalGasJson,
	}
	// SmartContract_TestNativeSendThenPrecompileSendJson is a test contract that
	// performs two sends in a single call: a native nibi send and a precompile
	// sendToBank. It tests a race condition where the state DB commit may
	// overwrite the state after the precompile execution, potentially causing a
	// loss of funds.
	SmartContract_TestNativeSendThenPrecompileSendJson = CompiledEvmContract{
		Name:      "TestNativeSendThenPrecompileSend.sol",
		EmbedJSON: testNativeSendThenPrecompileSendJson,
	}
	// SmartContract_TestERC20TransferThenPrecompileSend is a test contract that
	// performs two sends in a single call: an erc20 token transfer and a
	// precompile sendToBank. It tests a race condition where the state DB commit
	// may overwrite the state after the precompile execution, potentially
	// causing an infinite token mint.
	SmartContract_TestERC20TransferThenPrecompileSend = CompiledEvmContract{
		Name:      "TestERC20TransferThenPrecompileSend.sol",
		EmbedJSON: testERC20TransferThenPrecompileSendJson,
	}
	// SmartContract_TestPrecompileSelfCallRevert is a test contract
	// that creates another instance of itself, calls the precompile method and then force reverts.
	// It tests a race condition where the state DB commit
	// may save the wrong state before the precompile execution, not revert it entirely,
	// potentially causing an infinite mint of funds.
	SmartContract_TestPrecompileSelfCallRevert = CompiledEvmContract{
		Name:      "TestPrecompileSelfCallRevert.sol",
		EmbedJSON: testPrecompileSelfCallRevertJson,
	}
	// SmartContract_TestInfiniteRecursionERC20 is a test contract
	// which simulates malicious ERC20 behavior by adding infinite recursion in transfer() and balanceOf() functions
	SmartContract_TestInfiniteRecursionERC20 = CompiledEvmContract{
		Name:      "TestInfiniteRecursionERC20.sol",
		EmbedJSON: testInfiniteRecursionERC20Json,
	}
	// SmartContract_TestERC20TransferWithFee is a test contract
	// which simulates malicious ERC20 behavior by adding fee to the transfer() function
	SmartContract_TestERC20TransferWithFee = CompiledEvmContract{
		Name:      "TestERC20TransferWithFee.sol",
		EmbedJSON: testERC20TransferWithFee,
	}
	// SmartContract_TestRandom is a test contract which tests random function
	SmartContract_TestRandom = CompiledEvmContract{
		Name:      "TestRandom.sol",
		EmbedJSON: testRandom,
	}
	// SmartContract_TestBytes32Metadata is a test contract which tests contract that have bytes32 as metadata
	SmartContract_TestBytes32Metadata = CompiledEvmContract{
		Name:      "MKR.sol",
		EmbedJSON: testMetadataBytes32,
	}
	// SmartContract_TestPrecompileSendToBankThenERC20Transfer is a test contract that sends to bank then calls ERC20 transfer
	SmartContract_TestPrecompileSendToBankThenERC20Transfer = CompiledEvmContract{
		Name:      "TestPrecompileSendToBankThenERC20Transfer.sol",
		EmbedJSON: testPrecompileSendToBankThenERC20Transfer,
	}
	// SmartContract_TestDirtyStateAttack4 is a test contract that composes manual send and funtoken sendToBank with a reversion
	SmartContract_TestDirtyStateAttack4 = CompiledEvmContract{
		Name:      "TestDirtyStateAttack4.sol",
		EmbedJSON: testDirtyStateAttack4,
	}
	// SmartContract_TestDirtyStateAttack5 is a test contract that calls a wasm contract with 5 NIBI
	SmartContract_TestDirtyStateAttack5 = CompiledEvmContract{
		Name:      "TestDirtyStateAttack5.sol",
		EmbedJSON: testDirtyStateAttack5,
	}
	// SmartContract_TestOracleAsLZNativeFeeHandler exercises the oracle precompile
	// through a native-fee quote interface.
	SmartContract_TestOracleAsLZNativeFeeHandler = CompiledEvmContract{
		Name:      "TestOracleAsLZNativeFeeHandler.sol",
		EmbedJSON: testOracleAsLZNativeFeeHandler,
	}
	SmartContract_TestDelegatePrecompile = CompiledEvmContract{
		Name:      "TestDelegatePrecompile.sol",
		EmbedJSON: testDelegatePrecompile,
	}
	SmartContract_TestCallbackCaller = CompiledEvmContract{
		Name:      "TestCallbackCaller.sol",
		EmbedJSON: testCallbackCaller,
	}
	SmartContract_TestDelegateProxy = CompiledEvmContract{
		Name:      "TestDelegateProxy.sol",
		EmbedJSON: testDelegateProxy,
	}
)

Functions

This section is empty.

Types

type CompiledEvmContract

type CompiledEvmContract struct {
	Name      string
	EmbedJSON []byte

	// filled in post-load
	ABI      *gethabi.ABI `json:"abi"`
	Bytecode []byte       `json:"bytecode"`
}

func (*CompiledEvmContract) MustLoad

func (sc *CompiledEvmContract) MustLoad()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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