ethereum

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

README

Safe Ethereum Contracts Deployment

1 Deploy Safe Singleton Factory

  • Run git clone https://github.com/MixinNetwork/safe-singleton-factory
  • Run yarn install
  • Set RPC in the .env file for the network.
  • Set MNEMONIC in the .env file
  • Run yarn estimate-compile
  • Run yarn submit

The deployment information will be saved in safe-singleton-factory/artifacts/<chain_id>/deployment.json.

To deploy safe contracts in the next step, it's better to push changes of artifacts folder to your own fork.

2 Deploy Safe Contracts

  • Run git clone https://github.com/MixinNetwork/safe-contracts.git
  • Run git checkout feature/mixin-safe-guard (contracts version: v1.4.1)
  • Run yarn install (Do this every time before deploying contracts if @gnosis.pm/safe-singleton-factory in package.json is your own fork)
  • Set MNEMONIC in the .env file
  • Set CUSTOM_DETERMINISTIC_DEPLOYMENT = true in the .env file
  • Run rm -r deployments if needed
For custom network like mvm
  • Set NODE_URL in the .env file for the network.
  • Run yarn deploy-all custom
For infura based network
  • Set INFURA_KEY in .env
  • Run yarn deploy-all <network>

For some networks or custom network, you might need to add network rpc host in the submitSources function of node_modules/hardhat-deploy/dist/src/etherscan.js in contract verification step.

// add mvm rpc host
case '73927':
    host = 'https://scan.mvm.dev';
    break;

Documentation

Index

Constants

View Source
const (
	ChainEthereum = 2
	ChainMVM      = 4
	ChainPolygon  = 6

	ValuePrecision = 18
	ValueDust      = 100000000000000

	TimeLockMinimum = time.Hour * 1
	TimeLockMaximum = time.Hour * 24 * 365

	TypeETHTx       = 1
	TypeERC20Tx     = 2
	TypeMultiSendTx = 3

	EthereumEmptyAddress                        = "0x0000000000000000000000000000000000000000"
	EthereumSafeProxyFactoryAddress             = "0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"
	EthereumSafeL2Address                       = "0x29fcB43b46531BcA003ddC8FCB67FFE91900C762"
	EthereumCompatibilityFallbackHandlerAddress = "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99"
	EthereumMultiSendAddress                    = "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526"
	EthereumSafeGuardAddress                    = "0x5cFE246E7F5d2473e34D0F2B33552076a682d68C"
)

Variables

This section is empty.

Functions

func BuildChainAssetId

func BuildChainAssetId(base, asset string) string

func BuildGnosisSafe

func BuildGnosisSafe(ctx context.Context, rpc, holder, signer, observer, rid string, lock time.Duration, chain byte) (*GnosisSafe, *SafeTransaction, error)

func CheckFinalization

func CheckFinalization(num uint64, chain byte) bool

func CheckSafeAccountDeployed

func CheckSafeAccountDeployed(rpc, address string) (bool, bool, error)

func CheckTransactionPartiallySignedBy

func CheckTransactionPartiallySignedBy(raw, public string) bool

func DeploySafeAccount

func DeploySafeAccount(ctx context.Context, rpc, key string, chainId int64, owners []string, threshold int64) error

func GenerateAssetId

func GenerateAssetId(chain byte, assetKey string) string

func GetEvmChainID

func GetEvmChainID(chain int64) int64

func GetMixinChainID

func GetMixinChainID(chain int64) string

func GetNonce

func GetNonce(rpc, address string) (int64, error)

func GetNonceAtBlock

func GetNonceAtBlock(rpc, address string, blockNumber *big.Int) (*big.Int, error)

func GetOrDeploySafeAccount

func GetOrDeploySafeAccount(ctx context.Context, rpc, key string, chainId int64, owners []string, threshold int64, timelock, observerIndex int64, tx *SafeTransaction) (*common.Address, error)

func GetOwners

func GetOwners(rpc, address string) ([]common.Address, error)

func GetSafeAccountAddress

func GetSafeAccountAddress(owners []string, threshold int64) common.Address

func GetSafeLastTxTime

func GetSafeLastTxTime(rpc, address string) (time.Time, error)

func GetSortedSafeOwners

func GetSortedSafeOwners(holder, signer, observer string) ([]string, []string)

func GetTokenBalanceAtBlock

func GetTokenBalanceAtBlock(rpc, tokenAddress, address string, blockNumber *big.Int) (*big.Int, error)

func HashMessageForSignature

func HashMessageForSignature(msg string) []byte

func NormalizeAddress

func NormalizeAddress(addr string) string

func ParseAmount

func ParseAmount(amount string, decimals int32) *big.Int

func ParseEthereumCompressedPublicKey

func ParseEthereumCompressedPublicKey(public string) (*common.Address, error)

func PrivToAddress

func PrivToAddress(priv string) (*common.Address, error)

func ProcessSignature

func ProcessSignature(signature []byte) []byte

func RPCGetAddressBalanceAtBlock

func RPCGetAddressBalanceAtBlock(rpc, blockHeight, address string) (*big.Int, error)

func RPCGetBlockHash

func RPCGetBlockHash(rpc string, height int64) (string, error)

func RPCGetBlockHeight

func RPCGetBlockHeight(rpc string) (int64, error)

func RPCGetGasPrice

func RPCGetGasPrice(rpc string) (*big.Int, error)

func UnitAmount

func UnitAmount(amount *big.Int, decimals int32) string

func VerifyAssetKey

func VerifyAssetKey(assetKey string) error

func VerifyDeposit

func VerifyDeposit(ctx context.Context, chain byte, rpc, hash, chainId, assetAddress, destination string, index int64, amount *big.Int) (*Transfer, *RPCTransaction, error)

func VerifyHashSignature

func VerifyHashSignature(public string, hash, sig []byte) error

func VerifyHolderKey

func VerifyHolderKey(public string) error

func VerifyMessageSignature

func VerifyMessageSignature(public string, msg, sig []byte) error

Types

type Asset

type Asset struct {
	Address  string
	Id       string
	Symbol   string
	Name     string
	Decimals uint32
	Chain    byte
}

func FetchAsset

func FetchAsset(chain byte, rpc, address string) (*Asset, error)

type GnosisSafe

type GnosisSafe struct {
	Sequence uint32
	Address  string
	TxHash   string
}

func UnmarshalGnosisSafe

func UnmarshalGnosisSafe(extra []byte) (*GnosisSafe, error)

func (*GnosisSafe) Marshal

func (gs *GnosisSafe) Marshal() []byte

type Output

type Output struct {
	TokenAddress string
	Destination  string
	Amount       *big.Int
}

type RPCBlock

type RPCBlock struct {
	Hash      string   `json:"hash"`
	Number    string   `json:"number"`
	Tx        []string `json:"transactions"`
	Timestamp string   `json:"timestamp"`

	Height uint64
	Time   time.Time
}

func RPCGetBlock

func RPCGetBlock(rpc, hash string) (*RPCBlock, error)

type RPCBlockCallTrace

type RPCBlockCallTrace struct {
	Result *RPCTransactionCallTrace `json:"result"`
}

func RPCDebugTraceBlockByNumber

func RPCDebugTraceBlockByNumber(rpc string, height int64) ([]*RPCBlockCallTrace, error)

type RPCBlockWithTransactions

type RPCBlockWithTransactions struct {
	Hash   string            `json:"hash"`
	Number string            `json:"number"`
	Tx     []*RPCTransaction `json:"transactions"`

	Height uint64
}

func RPCGetBlockWithTransactions

func RPCGetBlockWithTransactions(rpc string, height int64) (*RPCBlockWithTransactions, error)

type RPCTransaction

type RPCTransaction struct {
	BlockHash        string `json:"blockHash"`
	BlockNumber      string `json:"blockNumber"`
	ChainID          string `json:"chainId"`
	From             string `json:"from"`
	Gas              string `json:"gas"`
	GasPrice         string `json:"gasPrice"`
	Hash             string `json:"hash"`
	Input            string `json:"input"`
	Nonce            string `json:"Nonce"`
	To               string `json:"to"`
	TransactionIndex string `json:"transactionIndex"`
	Type             string `json:"type"`
	Value            string `json:"value"`

	BlockHeight uint64
}

func RPCGetTransactionByHash

func RPCGetTransactionByHash(rpc, hash string) (*RPCTransaction, error)

type RPCTransactionCallTrace

type RPCTransactionCallTrace struct {
	Calls   []*RPCTransactionCallTrace `json:"calls"`
	Error   string                     `json:"error"`
	From    string                     `json:"from"`
	Gas     string                     `json:"gas"`
	GasUsed string                     `json:"gasUsed"`
	Input   string                     `json:"input"`
	Output  string                     `json:"output"`
	To      string                     `json:"to"`
	Type    string                     `json:"type"`
	Value   string                     `json:"value"`
}

func RPCDebugTraceTransactionByHash

func RPCDebugTraceTransactionByHash(rpc, hash string) (*RPCTransactionCallTrace, error)

type SafeTransaction

type SafeTransaction struct {
	TxHash         string
	ChainID        int64
	SafeAddress    string
	Destination    common.Address
	Value          *big.Int
	Data           []byte
	Operation      uint8
	SafeTxGas      *big.Int
	BaseGas        *big.Int
	GasPrice       *big.Int
	GasToken       common.Address
	RefundReceiver common.Address
	Nonce          *big.Int
	Message        []byte
	Signatures     [][]byte
}

func CreateEnableGuardTransaction

func CreateEnableGuardTransaction(ctx context.Context, chainID int64, id, safeAddress, observerAddress string, timelock *big.Int) (*SafeTransaction, error)

func CreateMultiSendTransaction

func CreateMultiSendTransaction(ctx context.Context, chainID int64, id, safeAddress string, outputs []*Output, nonce *big.Int) (*SafeTransaction, error)

func CreateTransaction

func CreateTransaction(ctx context.Context, typ int, chainID int64, id, safeAddress, destination, tokenAddress, amount string, nonce *big.Int) (*SafeTransaction, error)

func CreateTransactionFromOutputs

func CreateTransactionFromOutputs(ctx context.Context, typ int, chainId int64, id, safeAddress string, outputs []*Output, nonce *big.Int) (*SafeTransaction, error)

func UnmarshalSafeTransaction

func UnmarshalSafeTransaction(b []byte) (*SafeTransaction, error)

func (*SafeTransaction) ExecTransaction

func (tx *SafeTransaction) ExecTransaction(ctx context.Context, rpc, key string) (string, error)

func (*SafeTransaction) ExtractOutputs

func (tx *SafeTransaction) ExtractOutputs() []*Output

func (*SafeTransaction) GetTransactionHash

func (tx *SafeTransaction) GetTransactionHash() []byte

func (*SafeTransaction) Hash

func (tx *SafeTransaction) Hash(id string) string

func (*SafeTransaction) Marshal

func (tx *SafeTransaction) Marshal() []byte

func (*SafeTransaction) ValidTransaction

func (tx *SafeTransaction) ValidTransaction(rpc string) (bool, error)

type Transfer

type Transfer struct {
	Hash         string
	Index        int64
	TokenAddress string
	AssetId      string
	Sender       string
	Receiver     string
	Value        *big.Int
}

func GetERC20TransferLogFromBlock

func GetERC20TransferLogFromBlock(ctx context.Context, rpc string, chain, height int64) ([]*Transfer, error)

func LoopBlockTraces

func LoopBlockTraces(chain byte, chainId string, traces []*RPCBlockCallTrace, blockTxs []*RPCTransaction) []*Transfer

TODO cross-chain deposits might be lost, which are sended from emtpy address and not included in the block traces in polygon

func LoopCalls

func LoopCalls(chain byte, chainId, hash string, trace *RPCTransactionCallTrace, index int64) ([]*Transfer, int64)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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