Documentation ¶
Overview ¶
The zrx package provides types, functions, and interfaces for interacting with the 0x contract system.
Index ¶
- Constants
- Variables
- func ECSignatureToBytes(ecSignature *signer.ECSignature) []byte
- func EncodeERC20AssetData(address common.Address) []byte
- func GeneratePseudoRandomSalt() (*big.Int, error)
- type SignedTransaction
- type Transaction
- type ZeroExHelper
- func (zh *ZeroExHelper) CreateOrder(maker common.Address, taker common.Address, sender common.Address, ...) (*zeroex.Order, error)
- func (zh *ZeroExHelper) DevUtils() *wrappers.DevUtilsCaller
- func (zh *ZeroExHelper) ExecuteTransaction(opts *bind.TransactOpts, ztx *Transaction, sig []byte) (*types.Transaction, error)
- func (zh *ZeroExHelper) GetFillOrderCallData(order zeroex.Order, takerAssetAmount *big.Int, signature []byte) ([]byte, error)
- func (zh *ZeroExHelper) GetTransactionHash(tx *Transaction) (common.Hash, error)
- func (zh *ZeroExHelper) ValidateFill(ctx context.Context, order *zeroex.SignedOrder, takerAssetAmount *big.Int) error
Constants ¶
const AssetDataLength = int(36)
const AssetDataPrefixLength = int(4)
const ECSignatureLength = 66
ECSignatureLength is the length, in bytes, of a ECSignature
const TypeEIP712Domain = "EIP712Domain"
TypeEIP712Domain is the name of the EIP-712 domain type
const TypeZeroExTransaction = "ZeroExTransaction"
TypeZeroExTransaction is the name of the 0x transaction type
const ZeroExProtocolName = "0x Protocol"
ZeroExProtocolName is the EIP-712 domain name of the 0x protocol
const ZeroExProtocolVersion = "3.0.0"
ZeroExProtocolVersion is the EIP-712 domain version of the 0x protocol
const ZeroExTestChainID = 1337
ZeroExTestChainID is the chain ID of the 0x ganache snapshot network
Variables ¶
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
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
var NULL_ADDRESS = common.Address{}
NULL_ADDRESS is the Ethereum address with 20 null bytes
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 ¶
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 ¶
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.