zeroex

package
v1.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2019 License: Apache-2.0 Imports: 23 Imported by: 52

Documentation

Index

Constants

View Source
const (
	EKInvalid          = OrderEventKind("INVALID")
	EKOrderAdded       = OrderEventKind("ADDED")
	EKOrderFilled      = OrderEventKind("FILLED")
	EKOrderFullyFilled = OrderEventKind("FULLY_FILLED")
	EKOrderCancelled   = OrderEventKind("CANCELLED")
	EKOrderExpired     = OrderEventKind("EXPIRED")
	// An order becomes unfunded if the maker transfers the balance / changes their
	// allowance backing an order
	EKOrderBecameUnfunded = OrderEventKind("UNFUNDED")
	// Fillability for an order can increase if a previously processed fill event
	// gets reverted, or if a maker tops up their balance/allowance backing an order
	EKOrderFillabilityIncreased = OrderEventKind("FILLABILITY_INCREASED")
)

OrderEventKind values

View Source
const (
	ZeroExValidation = RejectedOrderKind("ZEROEX_VALIDATION")
	MeshError        = RejectedOrderKind("MESH_ERROR")
	CoordinatorError = RejectedOrderKind("COORDINATOR_ERROR")
)

RejectedOrderKind values

Variables

View Source
var (
	ROEthRPCRequestFailed = RejectedOrderStatus{
		Code:    "EthRPCRequestFailed",
		Message: "network request to Ethereum RPC endpoint failed",
	}
	ROCoordinatorRequestFailed = RejectedOrderStatus{
		Code:    "CoordinatorRequestFailed",
		Message: "network request to coordinator server endpoint failed",
	}
	ROCoordinatorSoftCancelled = RejectedOrderStatus{
		Code:    "CoordinatorSoftCancelled",
		Message: "order was soft-cancelled via the coordinator server",
	}
	ROCoordinatorEndpointNotFound = RejectedOrderStatus{
		Code:    "CoordinatorEndpointNotFound",
		Message: "corresponding coordinator endpoint not found in CoordinatorRegistry contract",
	}
	ROInvalidMakerAssetAmount = RejectedOrderStatus{
		Code:    "OrderHasInvalidMakerAssetAmount",
		Message: "order makerAssetAmount cannot be 0",
	}
	ROInvalidTakerAssetAmount = RejectedOrderStatus{
		Code:    "OrderHasInvalidTakerAssetAmount",
		Message: "order takerAssetAmount cannot be 0",
	}
	ROExpired = RejectedOrderStatus{
		Code:    "OrderExpired",
		Message: "order already expired",
	}
	ROFullyFilled = RejectedOrderStatus{
		Code:    "OrderFullyFilled",
		Message: "order already fully filled",
	}
	ROCancelled = RejectedOrderStatus{
		Code:    "OrderCancelled",
		Message: "order cancelled",
	}
	ROUnfunded = RejectedOrderStatus{
		Code:    "OrderUnfunded",
		Message: "maker has insufficient balance or allowance for this order to be filled",
	}
	ROInvalidMakerAssetData = RejectedOrderStatus{
		Code:    "OrderHasInvalidMakerAssetData",
		Message: "order makerAssetData must encode a supported assetData type",
	}
	ROInvalidTakerAssetData = RejectedOrderStatus{
		Code:    "OrderHasInvalidTakerAssetData",
		Message: "order takerAssetData must encode a supported assetData type",
	}
	ROInvalidSignature = RejectedOrderStatus{
		Code:    "OrderHasInvalidSignature",
		Message: "order signature must be valid",
	}
)

RejectedOrderStatus values

View Source
var GanacheOrderValidatorAddress = common.HexToAddress("0x32eecaf51dfea9618e9bc94e9fbfddb1bbdcba15")

GanacheOrderValidatorAddress is the ganache snapshot OrderValidator contract address

View Source
var MainnetOrderValidatorAddress = common.HexToAddress("0x9463e518dea6810309563c81d5266c1b1d149138")

MainnetOrderValidatorAddress is the mainnet OrderValidator contract address

Functions

This section is empty.

Types

type AcceptedOrderInfo

type AcceptedOrderInfo struct {
	OrderHash                common.Hash  `json:"orderHash"`
	SignedOrder              *SignedOrder `json:"signedOrder"`
	FillableTakerAssetAmount *big.Int     `json:"fillableTakerAssetAmount"`
}

AcceptedOrderInfo represents an fillable order and how much it could be filled for

type AssetDataDecoder

type AssetDataDecoder struct {
	// contains filtered or unexported fields
}

AssetDataDecoder decodes 0x order asset data

func NewAssetDataDecoder

func NewAssetDataDecoder() *AssetDataDecoder

NewAssetDataDecoder instantiates a new asset data decoder

func (*AssetDataDecoder) Decode

func (a *AssetDataDecoder) Decode(assetData []byte, decodedAssetData interface{}) error

Decode decodes an encoded asset data into it's sub-components

func (*AssetDataDecoder) GetName

func (a *AssetDataDecoder) GetName(assetData []byte) (string, error)

GetName returns the name of the assetData type

type ERC20AssetData

type ERC20AssetData struct {
	Address common.Address
}

ERC20AssetData represents an ERC20 assetData

type ERC721AssetData

type ERC721AssetData struct {
	Address common.Address
	TokenId *big.Int
}

ERC721AssetData represents an ERC721 assetData

type MultiAssetData

type MultiAssetData struct {
	Amounts         []*big.Int
	NestedAssetData [][]byte
}

MultiAssetData represents an MultiAssetData

type Order

type Order struct {
	MakerAddress          common.Address `json:"makerAddress"`
	MakerAssetData        []byte         `json:"makerAssetData"`
	MakerAssetAmount      *big.Int       `json:"makerAssetAmount"`
	MakerFee              *big.Int       `json:"makerFee"`
	TakerAddress          common.Address `json:"takerAddress"`
	TakerAssetData        []byte         `json:"takerAssetData"`
	TakerAssetAmount      *big.Int       `json:"takerAssetAmount"`
	TakerFee              *big.Int       `json:"takerFee"`
	SenderAddress         common.Address `json:"senderAddress"`
	ExchangeAddress       common.Address `json:"exchangeAddress"`
	FeeRecipientAddress   common.Address `json:"feeRecipientAddress"`
	ExpirationTimeSeconds *big.Int       `json:"expirationTimeSeconds"`
	Salt                  *big.Int       `json:"salt"`
}

Order represents an unsigned 0x order

func (*Order) ComputeOrderHash

func (o *Order) ComputeOrderHash() (common.Hash, error)

ComputeOrderHash computes a 0x order hash

type OrderEvent

type OrderEvent struct {
	OrderHash                common.Hash    `json:"orderHash"`
	SignedOrder              *SignedOrder   `json:"signedOrder"`
	Kind                     OrderEventKind `json:"kind"`
	FillableTakerAssetAmount *big.Int       `json:"fillableTakerAssetAmount"`
	// The hashes of the Ethereum transactions that caused the order status to change.
	// Could be because of multiple transactions, not just a single transaction.
	TxHashes []common.Hash `json:"txHashes"`
}

OrderEvent is the order event emitted by Mesh nodes on the "orders" topic when calling JSON-RPC method `mesh_subscribe`

func (OrderEvent) MarshalJSON

func (o OrderEvent) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom JSON marshaller for the OrderEvent type

func (*OrderEvent) UnmarshalJSON

func (o *OrderEvent) UnmarshalJSON(data []byte) error

UnmarshalJSON implements a custom JSON unmarshaller for the OrderEvent type

type OrderEventKind

type OrderEventKind string

OrderEventKind enumerates all the possible order event types

func ConvertRejectOrderCodeToOrderEventKind

func ConvertRejectOrderCodeToOrderEventKind(rejectedOrderStatus RejectedOrderStatus) (OrderEventKind, bool)

ConvertRejectOrderCodeToOrderEventKind converts an RejectOrderCode to an OrderEventKind type

type OrderInfo

type OrderInfo struct {
	OrderHash                common.Hash
	SignedOrder              *SignedOrder
	FillableTakerAssetAmount *big.Int
	OrderStatus              OrderStatus
	// The hash of the Ethereum transaction that caused the order status to change
	TxHash common.Hash
}

OrderInfo represents the order information emitted from Mesh

type OrderStatus

type OrderStatus uint8

OrderStatus represents the status of an order as returned from the 0x smart contracts as part of OrderInfo

const (
	OSInvalid OrderStatus = iota
	OSInvalidMakerAssetAmount
	OSInvalidTakerAssetAmount
	OSFillable
	OSExpired
	OSFullyFilled
	OSCancelled
	OSSignatureInvalid
	OSInvalidMakerAssetData
	OSInvalidTakerAssetData
)

OrderStatus values

type OrderValidator

type OrderValidator struct {
	// contains filtered or unexported fields
}

OrderValidator validates 0x orders

func NewOrderValidator

func NewOrderValidator(ethClient *ethclient.Client, networkID int, maxRequestContentLength int) (*OrderValidator, error)

NewOrderValidator instantiates a new order validator

func (*OrderValidator) BatchOffchainValidation

func (o *OrderValidator) BatchOffchainValidation(signedOrders []*SignedOrder) ([]*SignedOrder, []*RejectedOrderInfo)

BatchOffchainValidation performs all off-chain validation checks on a batch of 0x orders. These checks include: - `MakerAssetAmount` and `TakerAssetAmount` cannot be 0 - `AssetData` fields contain properly encoded, and currently supported assetData (ERC20 & ERC721 for now) - `Signature` contains a properly encoded 0x signature - Validate that order isn't expired Returns an orderHashToInfo mapping with all invalid orders added to it, and an array of the valid signedOrders

func (*OrderValidator) BatchValidate

func (o *OrderValidator) BatchValidate(rawSignedOrders []*SignedOrder) *ValidationResults

BatchValidate retrieves all the information needed to validate the supplied orders. It splits the orders into chunks of `chunkSize`, and makes no more then `concurrencyLimit` requests concurrently. If a request fails, re-attempt it up to four times before giving up. If it some requests fail, this method still returns whatever order information it was able to retrieve.

type RejectedOrderInfo

type RejectedOrderInfo struct {
	OrderHash   common.Hash         `json:"orderHash"`
	SignedOrder *SignedOrder        `json:"signedOrder"`
	Kind        RejectedOrderKind   `json:"kind"`
	Status      RejectedOrderStatus `json:"status"`
}

RejectedOrderInfo encapsulates all the needed information to understand _why_ a 0x order was rejected (i.e. did not pass) order validation. Since there are many potential reasons, some Mesh-specific, others 0x-specific and others due to external factors (i.e., network disruptions, etc...), we categorize them into `Kind`s and uniquely identify the reasons for machines with a `Code`

type RejectedOrderKind

type RejectedOrderKind string

RejectedOrderKind enumerates all kinds of reasons an order could be rejected by Mesh

type RejectedOrderStatus

type RejectedOrderStatus struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

RejectedOrderStatus enumerates all the unique reasons for an orders rejection

type SignatureType

type SignatureType uint8

SignatureType represents the type of 0x signature encountered

const (
	IllegalSignature SignatureType = iota
	InvalidSignature
	EIP712Signature
	EthSignSignature
	WalletSignature
	ValidatorSignature
	PreSignedSignature
	NSignatureTypesSignature
)

SignatureType values

type SignedOrder

type SignedOrder struct {
	Order
	Signature []byte `json:"signature"`
}

SignedOrder represents a signed 0x order

func SignOrder

func SignOrder(signer ethereum.Signer, order *Order) (*SignedOrder, error)

SignOrder signs the 0x order with the supplied Signer

func SignTestOrder

func SignTestOrder(order *Order) (*SignedOrder, error)

SignTestOrder signs the 0x order with the local test signer

func (*SignedOrder) ConvertToOrderWithoutExchangeAddress

func (s *SignedOrder) ConvertToOrderWithoutExchangeAddress() wrappers.OrderWithoutExchangeAddress

ConvertToOrderWithoutExchangeAddress re-formats a SignedOrder into the format expected by the 0x smart contracts.

func (SignedOrder) MarshalJSON

func (s SignedOrder) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom JSON marshaller for the SignedOrder type

func (*SignedOrder) UnmarshalJSON

func (s *SignedOrder) UnmarshalJSON(data []byte) error

UnmarshalJSON implements a custom JSON unmarshaller for the SignedOrder type

type SignedOrderJSON

type SignedOrderJSON struct {
	MakerAddress          string `json:"makerAddress"`
	MakerAssetData        string `json:"makerAssetData"`
	MakerAssetAmount      string `json:"makerAssetAmount"`
	MakerFee              string `json:"makerFee"`
	TakerAddress          string `json:"takerAddress"`
	TakerAssetData        string `json:"takerAssetData"`
	TakerAssetAmount      string `json:"takerAssetAmount"`
	TakerFee              string `json:"takerFee"`
	SenderAddress         string `json:"senderAddress"`
	ExchangeAddress       string `json:"exchangeAddress"`
	FeeRecipientAddress   string `json:"feeRecipientAddress"`
	ExpirationTimeSeconds string `json:"expirationTimeSeconds"`
	Salt                  string `json:"salt"`
	Signature             string `json:"signature"`
}

SignedOrderJSON is an unmodified JSON representation of a SignedOrder

type ValidationResults

type ValidationResults struct {
	Accepted []*AcceptedOrderInfo `json:"accepted"`
	Rejected []*RejectedOrderInfo `json:"rejected"`
}

ValidationResults defines the validation results returned from BatchValidate Within this context, an order is `Accepted` if it passes all the 0x schema tests and is fillable for a non-zero amount. An order is `Rejected` if it does not satisfy these conditions OR if we were unable to complete the validation process for whatever reason

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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