goethutils

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: MIT Imports: 7 Imported by: 0

README

Some Eth Utilities I've Gathered / Made for go

By popfendi

I plan on adding to this / add tests as I go, but here are some utils that I've often reused in my projects. May aswall make a library from them.

Very simple, all of the functions are commented so just look through them to see what they do.

Documentation

Index

Constants

View Source
const (
	Wei   = 1
	GWei  = 1e9
	Ether = 1e18
)

Variables

This section is empty.

Functions

func AddZerosToEnd

func AddZerosToEnd(num *big.Int, i int) *big.Int

Adds i amount of decimals from num (returning num as *big.Int)

func EtherToWei

func EtherToWei(eth *big.Float) *big.Int

formats ether as wei

func GeneratePairAddress

func GeneratePairAddress(token0, token1, FactoryAddress common.Address, pairAddressSuffix string) common.Address

GeneratePairAddress generates a pair address for the given tokens (for UniswapV2 or clones, requires pairAddressSuffic and factory address of clone instance)

func GetBalancesMapSlot

func GetBalancesMapSlot(holder common.Address, position int) [32]byte
returns the storage key slot for a holder.

Position is the index slot (storage index of amount balances map). You can use github.com/vocdoni/storage-proofs-eth-go/token useful library to get the memory slot of the map its self

func ParseUnits

func ParseUnits(num *big.Int, decimals uint8) *big.Float

go implimentation of ethers parse units (returns big.Int as big.Float to whichever decimal precision you like)

func RemoveZerosFromEnd

func RemoveZerosFromEnd(num *big.Int, i int) *big.Int

Removes i amount of decimals from num (returning num as *big.Int)

func SolidityEncode

func SolidityEncode(types []string, values []interface{}) (data []byte, err error)

implimentation of solidity abi.Encode

func SortTokens

func SortTokens(tokenA, tokenB common.Address) (common.Address, common.Address)

func WeiToEther

func WeiToEther(wei *big.Int) *big.Float

formats wei as ether

Types

This section is empty.

Jump to

Keyboard shortcuts

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