embeds

package
v2.0.0-rc.12 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

README

Nibiru Contract Embeds

Hacking

npm install
npx hardhat compile

Precompile Solidity Documentation

Example of a well-documented contract: [Uniswap/v4-core/.../IHooks.sol]

  • @notice: Used to explain to end users what the function does. Should be written in plain English and focus on the function's purpose.
    Best practice: Include for all public and external functions.
  • @param: Describes a function parameter. Should explain what the parameter is used for.
    Best practice: Include for all function parameters, especially in interfaces.
  • @dev: Provides additional details for developers. Used for implementation details, notes, or warnings for developers.
    Best practice: Use when there's important information that doesn't fit in @notice but is crucial for developers.
  • @return: Describes what a function returns.
    Best practice: Use for all functions that return values, explaining each return value.

Example from IHooks.sol:

/@notice The hook called before liquidity is removed
/// @param sender The initial msg.sender for the remove liquidity call
/// @param key The key for the pool
/// @param params The parameters for removing liquidity
/// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook
/// @return bytes4 The function selector for the hook
function beforeRemoveLiquidity(
    address sender,
    PoolKey calldata key,
    IPoolManager.ModifyLiquidityParams calldata params,
    bytes calldata hookData
) external returns (bytes4);

@inheritdoc:

Used to inherit documentation from a parent contract or interface. Best practice: Use when you want to reuse documentation from a base contract.

@title:

Provides a title for the contract or interface. Best practice: Include at the top of each contract or interface file.

@author:

States the author of the contract. Best practice: Optional, but can be useful in larger projects.

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 (
	// Contract_ERC20Minter: The default ERC20 contract deployed during the
	// creation of a `FunToken` mapping from a bank coin.
	SmartContract_ERC20Minter = CompiledEvmContract{
		Name:      "ERC20Minter.sol",
		EmbedJSON: erc20MinterContractJSON,
	}

	// 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 = CompiledEvmContract{
		Name:      "Oracle.sol",
		EmbedJSON: oracleContractJSON,
	}
	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_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 bankSend.
	// 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 bankSend.
	// 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,
	}
)

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()

Jump to

Keyboard shortcuts

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