zeroex

package
Version: v0.0.0-...-a40744b Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2021 License: Apache-2.0 Imports: 21 Imported by: 49

Documentation

Index

Constants

View Source
const (
	// ESInvalid is an event that is never emitted. It is here to discern between a declared but uninitialized OrderEventEndState
	ESInvalid = OrderEventEndState("INVALID")
	// ESOrderAdded means an order was successfully added to the Mesh node
	ESOrderAdded = OrderEventEndState("ADDED")
	// ESOrderFilled means an order was filled for a partial amount
	ESOrderFilled = OrderEventEndState("FILLED")
	// ESOrderFullyFilled means an order was fully filled such that it's remaining fillableTakerAssetAmount is 0
	ESOrderFullyFilled = OrderEventEndState("FULLY_FILLED")
	// ESOrderCancelled means an order was cancelled on-chain
	ESOrderCancelled = OrderEventEndState("CANCELLED")
	// ESOrderExpired means an order expired according to the latest block timestamp
	ESOrderExpired = OrderEventEndState("EXPIRED")
	// ESOrderUnexpired means an order is no longer expired. This can happen if a block re-org causes the latest
	// block timestamp to decline below the order's expirationTimestamp (rare and usually short-lived)
	ESOrderUnexpired = OrderEventEndState("UNEXPIRED")
	// ESOrderBecameUnfunded means an order has become unfunded. This happens if the maker transfers the balance /
	// changes their allowance backing an order
	ESOrderBecameUnfunded = OrderEventEndState("UNFUNDED")
	// ESOrderFillabilityIncreased means the fillability of an order has increased. 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
	ESOrderFillabilityIncreased = OrderEventEndState("FILLABILITY_INCREASED")
	// ESStoppedWatching means an order is potentially still valid but was removed for a different reason (e.g.
	// the database is full or the peer that sent the order was misbehaving). The order will no longer be watched
	// and no further events for this order will be emitted. In some cases, the order may be re-added in the
	// future.
	ESStoppedWatching = OrderEventEndState("STOPPED_WATCHING")
)

OrderEventEndState values

View Source
const CheckGasPriceDefaultID = "d728f5b7"

CheckGasDefaultID is the function selector for the `checkGas` function that does not accept a gasPrice.

View Source
const CheckGasPriceID = "da5b166a"

CheckGasID is the function selector for the `checkGas` function that accepts a gasPrice.

View Source
const ERC1155AssetDataID = "a7cb5fb7"

ERC1155AssetDataID is the assetDataId for ERC721 tokens

View Source
const ERC20AssetDataID = "f47261b0"

ERC20AssetDataID is the assetDataId for ERC20 tokens

View Source
const ERC20BridgeAssetDataID = "dc1600f3"

ERC20BridgeAssetDataID is the assetDataId for ERC20Bridge assets

View Source
const ERC721AssetDataID = "02571792"

ERC721AssetDataID is the assetDataId for ERC721 tokens

View Source
const MultiAssetDataID = "94cfcdd7"

MultiAssetDataID is the assetDataId for multiAsset tokens

View Source
const StaticCallAssetDataID = "c339d10a"

StaticCallAssetDataID is the assetDataId for staticcalls

Variables

This section is empty.

Functions

This section is empty.

Types

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 Bytes32

type Bytes32 [32]byte

Bytes32 represents the Solidity `bytes32` type. It is mostly copied from go-ethereum's Hash type. See <https://github.com/ethereum/go-ethereum/blob/053ed9cc847647a9b3ef707d0efe7104c4ab2a4c/common/types.go#L47>

func BigToBytes32

func BigToBytes32(i *big.Int) Bytes32

BigToBytes32 creates a Bytes32 from a big.Int.

func BytesToBytes32

func BytesToBytes32(b []byte) Bytes32

BytesToBytes32 converts []byte to Bytes32

func HashToBytes32

func HashToBytes32(h common.Hash) Bytes32

HashToBytes32 creates a Bytes32 from a Hash.

func HexToBytes32

func HexToBytes32(s string) Bytes32

HexToBytes32 creates a Bytes32 from a hex string.

func (Bytes32) Big

func (b Bytes32) Big() *big.Int

Raw converts a Bytes32 to a big.Int

func (Bytes32) Bytes

func (b Bytes32) Bytes() []byte

Bytes converts a Bytes32 to a []bytes.

func (Bytes32) Hex

func (b Bytes32) Hex() string

Hex converts a Bytes32 to a hex string.

func (Bytes32) Raw

func (b Bytes32) Raw() [32]byte

Raw converts a Bytes32 to a [32]bytes.

func (*Bytes32) SetBytes

func (b *Bytes32) SetBytes(bytes []byte)

SetBytes sets the Bytes32 to the value of bytes. If bytes is larger than 32, bytes will be cropped from the left.

func (Bytes32) String

func (b Bytes32) String() string

String prints the value in hex

type CheckGasPriceStaticCallData

type CheckGasPriceStaticCallData struct {
	MaxGasPrice *big.Int
}

type ContractEvent

type ContractEvent struct {
	BlockHash  common.Hash
	TxHash     common.Hash
	TxIndex    uint
	LogIndex   uint
	IsRemoved  bool
	Address    common.Address
	Kind       string
	Parameters interface{}
}

ContractEvent is an event emitted by a smart contract

func (ContractEvent) MarshalJSON

func (c ContractEvent) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom JSON marshaller for the ContractEvent type

type ERC1155AssetData

type ERC1155AssetData struct {
	Address      common.Address
	Ids          []*big.Int
	Values       []*big.Int
	CallbackData []byte
}

ERC1155AssetData represents an ERC1155 assetData

type ERC20AssetData

type ERC20AssetData struct {
	Address common.Address
}

ERC20AssetData represents an ERC20 assetData

type ERC20BridgeAssetData

type ERC20BridgeAssetData struct {
	TokenAddress  common.Address
	BridgeAddress common.Address
	BridgeData    []byte
}

ERC20BridgeAssetData represents an ERC20 Bridge 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 a MultiAssetData

type Order

type Order struct {
	ChainID               *big.Int       `json:"chainId"`
	ExchangeAddress       common.Address `json:"exchangeAddress"`
	MakerAddress          common.Address `json:"makerAddress"`
	MakerAssetData        []byte         `json:"makerAssetData"`
	MakerFeeAssetData     []byte         `json:"makerFeeAssetData"`
	MakerAssetAmount      *big.Int       `json:"makerAssetAmount"`
	MakerFee              *big.Int       `json:"makerFee"`
	TakerAddress          common.Address `json:"takerAddress"`
	TakerAssetData        []byte         `json:"takerAssetData"`
	TakerFeeAssetData     []byte         `json:"takerFeeAssetData"`
	TakerAssetAmount      *big.Int       `json:"takerAssetAmount"`
	TakerFee              *big.Int       `json:"takerFee"`
	SenderAddress         common.Address `json:"senderAddress"`
	FeeRecipientAddress   common.Address `json:"feeRecipientAddress"`
	ExpirationTimeSeconds *big.Int       `json:"expirationTimeSeconds"`
	Salt                  *big.Int       `json:"salt"`
	// contains filtered or unexported fields
}

Order represents an unsigned 0x order

func (*Order) ComputeOrderHash

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

ComputeOrderHash computes a 0x order hash

func (*Order) ResetHash

func (o *Order) ResetHash()

ResetHash resets the cached order hash. Usually only required for testing.

type OrderEvent

type OrderEvent struct {
	// Timestamp is an order event timestamp that can be used for bookkeeping purposes.
	// If the OrderEvent represents a Mesh-specific event (e.g., ADDED, STOPPED_WATCHING),
	// the timestamp is when the event was generated. If the event was generated after
	// re-validating an order at the latest block height (e.g., FILLED, UNFUNDED, CANCELED),
	// then it is set to the latest block timestamp at which the order was re-validated.
	Timestamp time.Time `json:"timestamp"`
	// OrderHash is the EIP712 hash of the 0x order
	OrderHash common.Hash `json:"orderHash"`
	// SignedOrder is the signed 0x order struct
	SignedOrder *SignedOrder `json:"signedOrder"`
	// SignedOrder is the signed 0x order struct
	SignedOrderV4 *SignedOrderV4 `json:"signedOrderV4"`
	// EndState is the end state of this order at the time this event was generated
	EndState OrderEventEndState `json:"endState"`
	// FillableTakerAssetAmount is the amount for which this order is still fillable
	FillableTakerAssetAmount *big.Int `json:"fillableTakerAssetAmount"`
	// ContractEvents contains all the contract events that triggered this orders re-evaluation.
	// They did not all necessarily cause the orders state change itself, only it's re-evaluation.
	// Since it's state _did_ change, at least one of them did cause the actual state change.
	ContractEvents []*ContractEvent `json:"contractEvents"`
}

OrderEvent is the order event emitted by the Mesh GraphQL API or the SubScribeToOrderEvents method in core.

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 OrderEventEndState

type OrderEventEndState string

OrderEventEndState enumerates all the possible order event types. An OrderEventEndState describes the end state of a 0x order after revalidation

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 OrderStatusV4

type OrderStatusV4 uint8

OrderStatusV4 represents the status of an order as returned from the 0x smart contracts as part of OrderInfo for v4 orders

type OrderV4

type OrderV4 struct {
	// Domain information
	// TODO: These are constant within a chain context (mainnet/testnet/etc)
	// probably best to keep them out of the order struct, but this is how V3
	// does it.
	ChainID           *big.Int       `json:"chainId"`
	VerifyingContract common.Address `json:"verifyingContract"`

	// Limit order values
	MakerToken          common.Address `json:"makerToken"`
	TakerToken          common.Address `json:"takerToken"`
	MakerAmount         *big.Int       `json:"makerAmount"`         // uint128
	TakerAmount         *big.Int       `json:"takerAmount"`         // uint128
	TakerTokenFeeAmount *big.Int       `json:"takerTokenFeeAmount"` // uint128
	Maker               common.Address `json:"makerAddress"`
	Taker               common.Address `json:"takerAddress"`
	Sender              common.Address `json:"sender"`
	FeeRecipient        common.Address `json:"feeRecipient"`
	Pool                Bytes32        `json:"pool"`   // bytes32
	Expiry              *big.Int       `json:"expiry"` // uint64
	Salt                *big.Int       `json:"salt"`   // uint256
	// contains filtered or unexported fields
}

OrderV4 represents an unsigned 0x v4 limit order V4 Protocol also has RFQ orders, these are See <https://0xprotocol.readthedocs.io/en/latest/basics/orders.html#limit-orders>

func (*OrderV4) ComputeOrderHash

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

ComputeOrderHash computes a 0x order hash

func (*OrderV4) EthereumAbiLimitOrder

func (s *OrderV4) EthereumAbiLimitOrder() wrappers.LibNativeOrderLimitOrder

EthereumAbiLimitOrder converts the order to the abigen equivalent

func (*OrderV4) ResetHash

func (o *OrderV4) ResetHash()

ResetHash resets the cached order hash. Usually only required for testing.

func (*OrderV4) TestSign

func (o *OrderV4) TestSign(t *testing.T) *SignedOrderV4

type SignatureFieldV4

type SignatureFieldV4 struct {
	SignatureType SignatureTypeV4 `json:"signatureType"`
	V             uint8           `json:"v"`
	R             Bytes32         `json:"r"`
	S             Bytes32         `json:"s"`
}

type SignatureType

type SignatureType uint8

SignatureType represents the type of 0x signature encountered

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

SignatureType values

type SignatureTypeV4

type SignatureTypeV4 uint8

SignatureTypeV4 represents the type of 0x signature encountered

const (
	IllegalSignatureV4 SignatureTypeV4 = iota
	InvalidSignatureV4
	EIP712SignatureV4
	EthSignSignatureV4
)

SignatureType values

func SignatureTypeV4FromString

func SignatureTypeV4FromString(s string) (SignatureTypeV4, error)

func (SignatureTypeV4) String

func (s SignatureTypeV4) String() string

type SignedOrder

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

SignedOrder represents a signed 0x order

func SignOrder

func SignOrder(signer signer.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) MarshalJSON

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

MarshalJSON implements a custom JSON marshaller for the SignedOrder type

func (*SignedOrder) Trim

Trim converts the order to a LibOrderOrder, which is the format expected by our smart contracts. It removes the ChainID and ExchangeAddress fields.

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 {
	ChainID               int64  `json:"chainId"`
	ExchangeAddress       string `json:"exchangeAddress"`
	MakerAddress          string `json:"makerAddress"`
	MakerAssetData        string `json:"makerAssetData"`
	MakerFeeAssetData     string `json:"makerFeeAssetData"`
	MakerAssetAmount      string `json:"makerAssetAmount"`
	MakerFee              string `json:"makerFee"`
	TakerAddress          string `json:"takerAddress"`
	TakerAssetData        string `json:"takerAssetData"`
	TakerFeeAssetData     string `json:"takerFeeAssetData"`
	TakerAssetAmount      string `json:"takerAssetAmount"`
	TakerFee              string `json:"takerFee"`
	SenderAddress         string `json:"senderAddress"`
	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 SignedOrderJSONV4

type SignedOrderJSONV4 struct {
	ChainID             int64  `json:"chainId"`
	VerifyingContract   string `json:"verifyingContract"`
	MakerToken          string `json:"makerToken"`
	TakerToken          string `json:"takerToken"`
	MakerAmount         string `json:"makerAmount"`
	TakerAmount         string `json:"takerAmount"`
	TakerTokenFeeAmount string `json:"takerTokenFeeAmount"`
	Maker               string `json:"maker"`
	Taker               string `json:"taker"`
	Sender              string `json:"sender"`
	FeeRecipient        string `json:"feeRecipient"`
	Pool                string `json:"pool"`
	Expiry              string `json:"expiry"`
	Salt                string `json:"salt"`
	SignatureType       string `json:"signatureType"`
	SignatureR          string `json:"signatureR"`
	SignatureV          string `json:"signatureV"`
	SignatureS          string `json:"signatureS"`
}

SignedOrderJSONV4 is an unmodified JSON representation of a SignedOrder

type SignedOrderV4

type SignedOrderV4 struct {
	OrderV4   `json:"order"`
	Signature SignatureFieldV4 `json:"signature"`
}

SignedOrderV4 represents a signed 0x order See <https://0xprotocol.readthedocs.io/en/latest/basics/orders.html#how-to-sign>

func SignOrderV4

func SignOrderV4(signer signer.Signer, order *OrderV4) (*SignedOrderV4, error)

SignOrderV4 signs the 0x order with the supplied Signer

func (*SignedOrderV4) EthereumAbiSignature

func (s *SignedOrderV4) EthereumAbiSignature() wrappers.LibSignatureSignature

EthereumAbiSignature converts the signature to the abigen equivalent

func (*SignedOrderV4) MarshalJSON

func (s *SignedOrderV4) MarshalJSON() ([]byte, error)

func (*SignedOrderV4) UnmarshalJSON

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

UnmarshalJSON implements a custom JSON unmarshaller for the SignedOrderV4 type.

type StaticCallAssetData

type StaticCallAssetData struct {
	StaticCallTargetAddress common.Address
	StaticCallData          []byte
	ExpectedReturnHashData  [32]byte
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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