New demos for Python packages (#1734)
End-to-end demos of constructing and signing an order and submitting it to a Relayer. Docs are generated from the code, and include usage examples that are verified through automated testing.
This commit is contained in:
committed by
F. Eugene Aumson
parent
28c4ca73ab
commit
3099ba71eb
@@ -6,7 +6,55 @@ For local testing one may construct such a provider pointing at an instance of
|
||||
contracts deployed on it. For convenience, a docker container is provided for
|
||||
just this purpose. To start it:
|
||||
`docker run -d -p 8545:8545 0xorg/ganache-cli:2.2.2`:code:.
|
||||
"""
|
||||
|
||||
Creating a 0x Order
|
||||
--------------------
|
||||
|
||||
Here is a short demonstration on how to create a 0x order.
|
||||
|
||||
>>> import pprint
|
||||
>>> from zero_ex.contract_addresses import (
|
||||
... NETWORK_TO_ADDRESSES, NetworkId)
|
||||
>>> from zero_ex.order_utils import asset_data_utils, Order
|
||||
>>> NULL_ADDRESS = "0x0000000000000000000000000000000000000000"
|
||||
>>> my_address = "0x5409ed021d9299bf6814279a6a1411a7e866a631"
|
||||
>>> exchange_address = NETWORK_TO_ADDRESSES[NetworkId.MAINNET].exchange
|
||||
>>> weth_address = NETWORK_TO_ADDRESSES[NetworkId.MAINNET].ether_token
|
||||
>>> zrx_address = NETWORK_TO_ADDRESSES[NetworkId.MAINNET].zrx_token
|
||||
>>> maker_asset_data = (
|
||||
... asset_data_utils.encode_erc20_asset_data(weth_address))
|
||||
>>> taker_asset_data = (
|
||||
... asset_data_utils.encode_erc20_asset_data(zrx_address))
|
||||
>>> example_order: Order = {
|
||||
... "makerAddress": my_address,
|
||||
... "takerAddress": NULL_ADDRESS,
|
||||
... "exchangeAddress": exchange_address,
|
||||
... "senderAddress": NULL_ADDRESS,
|
||||
... "feeRecipientAddress": NULL_ADDRESS,
|
||||
... "makerAssetData": maker_asset_data,
|
||||
... "takerAssetData": taker_asset_data,
|
||||
... "salt": 123456789,
|
||||
... "makerFee": 0,
|
||||
... "takerFee": 0,
|
||||
... "makerAssetAmount": 1 * 10 ** 18, # Converting token amount to base unit with 18 decimals
|
||||
... "takerAssetAmount": 500 * 10 ** 18, # Converting token amount to base unit with 18 decimals
|
||||
... "expirationTimeSeconds": 1553553429,
|
||||
... }
|
||||
>>> pprint.pprint(example_order)
|
||||
{'exchangeAddress': '0x4f833a24e1f95d70f028921e27040ca56e09ab0b',
|
||||
'expirationTimeSeconds': 1553553429,
|
||||
'feeRecipientAddress': '0x0000000000000000000000000000000000000000',
|
||||
'makerAddress': '0x5409ed021d9299bf6814279a6a1411a7e866a631',
|
||||
'makerAssetAmount': 1000000000000000000,
|
||||
'makerAssetData': '0xf47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
||||
'makerFee': 0,
|
||||
'salt': 123456789,
|
||||
'senderAddress': '0x0000000000000000000000000000000000000000',
|
||||
'takerAddress': '0x0000000000000000000000000000000000000000',
|
||||
'takerAssetAmount': 500000000000000000000,
|
||||
'takerAssetData': '0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498',
|
||||
'takerFee': 0}
|
||||
""" # noqa E501
|
||||
|
||||
from copy import copy
|
||||
from enum import auto, Enum
|
||||
|
Reference in New Issue
Block a user