zrx

package module
v0.0.0-...-2cf345d Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2020 License: MIT Imports: 23 Imported by: 0

README

go-zrx Build Status GoDoc

Go library with helpful tools for interacting with the 0x system

Documentation

Overview

The zrx package provides types, functions, and interfaces for interacting with the 0x contract system.

Index

Constants

View Source
const AssetDataLength = int(36)
View Source
const AssetDataPrefixLength = int(4)
View Source
const ECSignatureLength = 66

ECSignatureLength is the length, in bytes, of a ECSignature

View Source
const TypeEIP712Domain = "EIP712Domain"

TypeEIP712Domain is the name of the EIP-712 domain type

View Source
const TypeZeroExTransaction = "ZeroExTransaction"

TypeZeroExTransaction is the name of the 0x transaction type

View Source
const ZeroExProtocolName = "0x Protocol"

ZeroExProtocolName is the EIP-712 domain name of the 0x protocol

View Source
const ZeroExProtocolVersion = "3.0.0"

ZeroExProtocolVersion is the EIP-712 domain version of the 0x protocol

View Source
const ZeroExTestChainID = 1337

ZeroExTestChainID is the chain ID of the 0x ganache snapshot network

Variables

View Source
var EIP712Types = core.Types{
	"EIP712Domain": {
		{
			Name: "name",
			Type: "string",
		},
		{
			Name: "version",
			Type: "string",
		},
		{
			Name: "chainId",
			Type: "uint256",
		},
		{
			Name: "verifyingContract",
			Type: "address",
		},
	},
	"ZeroExTransaction": {
		{
			Name: "salt",
			Type: "uint256",
		},
		{
			Name: "expirationTimeSeconds",
			Type: "uint256",
		},
		{
			Name: "gasPrice",
			Type: "uint256",
		},
		{
			Name: "signerAddress",
			Type: "address",
		},
		{
			Name: "data",
			Type: "bytes",
		},
	},
}

 EIP712Types are the EIP-712 type definitions for the relevant 0x types and domain

View Source
var EXECUTE_FILL_TX_GAS_LIMIT = uint64(330000)

EXECUTE_FILL_TX_GAS_LIMIT is the maximum gas cost (with buffer) of executing a single fill transaction This value accounts for a scenario in which a 0x staking epoch has ended and must be settled

View Source
var NULL_ADDRESS = common.Address{}

NULL_ADDRESS is the Ethereum address with 20 null bytes

View Source
var PROTOCOL_FEE_MULTIPLIER = big.NewInt(150000)

PROTOCOL_FEE_MULTIPLIER is the value that a fill transaction's gas price must be multipled by, and paid in ETH https://github.com/0xProject/0x-protocol-specification/blob/master/v3/v3-specification.md#protocol-fees

Functions

func ECSignatureToBytes

func ECSignatureToBytes(ecSignature *signer.ECSignature) []byte

ECSignatureToBytes converts a 0x ECSignature to it's bytes representation Ideally this would be a method on *signer.ECSignature

func EncodeERC20AssetData

func EncodeERC20AssetData(address common.Address) []byte

EncodeERC20AssetData returns the encoded asset data for the token address Details: https://github.com/0xProject/0x-protocol-specification/blob/master/v3/v3-specification.md#assetdata

func GeneratePseudoRandomSalt

func GeneratePseudoRandomSalt() (*big.Int, error)

GeneratePseudoRandomSalt generates a pseudo-random integer bound by (2^256 - 1)

Types

type SignedTransaction

type SignedTransaction struct {
	Transaction

	Signature []byte
}

SignedTransaction represents a signed 0x transaction

func SignTransaction

func SignTransaction(signer signer.Signer, tx *Transaction, chainID int) (*SignedTransaction, error)

SignTransaction signs the 0x transaction with the supplied Signer

func (*SignedTransaction) MarshalJSON

func (stx *SignedTransaction) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*SignedTransaction) UnmarshalJSON

func (stx *SignedTransaction) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

type Transaction

type Transaction struct {
	Salt                  *big.Int
	ExpirationTimeSeconds *big.Int
	GasPrice              *big.Int
	SignerAddress         common.Address
	Data                  []byte
	// contains filtered or unexported fields
}

Transaction represents 0x transaction (see ZEIP-18)

func (*Transaction) ComputeHashForChainID

func (tx *Transaction) ComputeHashForChainID(chainID int) (common.Hash, error)

ComputeHashForChainID calculates the 0x transaction hash for the provided chain ID. See https://github.com/0xProject/0x-protocol-specification/blob/master/v3/v3-specification.md#hashing-a-transaction

func (*Transaction) Map

func (tx *Transaction) Map() map[string]interface{}

Map returns the transaction as an un-typed map (useful when hashing)

func (*Transaction) MarshalJSON

func (tx *Transaction) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Transaction) ResetHash

func (tx *Transaction) ResetHash()

ResetHash returns the cached transaction hash to nil

func (*Transaction) UnmarshalJSON

func (tx *Transaction) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

type ZeroExHelper

type ZeroExHelper struct {
	ChainID           *big.Int
	ContractAddresses ethereum.ContractAddresses

	Client         *ethclient.Client
	Contracts      *contracts
	OrderValidator *ordervalidator.OrderValidator
}

func NewZeroExHelper

func NewZeroExHelper(client *ethclient.Client, maxContentLength int) (*ZeroExHelper, error)

func (*ZeroExHelper) CreateOrder

func (zh *ZeroExHelper) CreateOrder(
	maker common.Address,
	taker common.Address,
	sender common.Address,
	feeRecipient common.Address,
	makerAsset common.Address,
	takerAsset common.Address,
	makerAmount *big.Int,
	takerAmount *big.Int,
	makerFee *big.Int,
	takerFee *big.Int,
	makerFeeAsset common.Address,
	takerFeeAsset common.Address,
	expirationTimeSeconds *big.Int,
) (*zeroex.Order, error)

CreateOrder creates an unsigned order with the specified values, and generates pseudo-random salt

func (*ZeroExHelper) DevUtils

func (zh *ZeroExHelper) DevUtils() *wrappers.DevUtilsCaller

DevUtils returns an initialized 0x DevUtils contract caller

func (*ZeroExHelper) ExecuteTransaction

func (zh *ZeroExHelper) ExecuteTransaction(opts *bind.TransactOpts, ztx *Transaction, sig []byte) (*types.Transaction, error)

ExecuteTransaction prepares ZEIP-18 transaction ztx with signature sig and executes it against the Exchange contract

func (*ZeroExHelper) GetFillOrderCallData

func (zh *ZeroExHelper) GetFillOrderCallData(order zeroex.Order, takerAssetAmount *big.Int, signature []byte) ([]byte, error)

GetFillOrderCallData generates the underlying 0x exchange call data for the fill (to be singed by the taker)

func (*ZeroExHelper) GetTransactionHash

func (zh *ZeroExHelper) GetTransactionHash(tx *Transaction) (common.Hash, error)

GetTransactionHash gets the 0x transaction hash for the current chain ID

func (*ZeroExHelper) ValidateFill

func (zh *ZeroExHelper) ValidateFill(ctx context.Context, order *zeroex.SignedOrder, takerAssetAmount *big.Int) error

ValidateFill is a convenience wrapper for ordervalidator.BatchValidate with a single order In addition, it also verifies the taker balance/allowance if the taker address is present.

Jump to

Keyboard shortcuts

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