Exemple #1
0
 def zx_order(self,
              maker_asset_contract,
              maker_asset_amount: Decimal,
              taker_asset_contract,
              taker_asset_amount: Decimal,
              taker_address: str = _default_address,
              sender_address: str = _default_address,
              fee_recipient_address: str = _default_address,
              salt=_default_salt,
              maker_fee=0,
              taker_fee=0,
              expiration_time=_default_zx_order_expiry,
              maker_fee_asset_data=_default_asset_data,
              taker_fee_asset_data=_default_asset_data):
     order = Order(
         makerAddress=self.account.address,
         takerAddress=taker_address,
         senderAddress=sender_address,
         feeRecipientAddress=fee_recipient_address,
         makerAssetData=encode_erc20(maker_asset_contract.address),
         takerAssetData=encode_erc20(taker_asset_contract.address),
         salt=salt,
         makerFee=maker_fee,
         takerFee=taker_fee,
         makerAssetAmount=Web3.toWei(maker_asset_amount, 'ether'),
         takerAssetAmount=Web3.toWei(taker_asset_amount, 'ether'),
         expirationTimeSeconds=expiration_time,
         makerFeeAssetData=maker_fee_asset_data,
         takerFeeAssetData=taker_fee_asset_data)
     order_hash = generate_order_hash_hex(order, self.zx_exchange.address,
                                          self._chain_id)
     # TODO: make compatible with 0x-order-utils
     # order_sig = sign_hash(TEST_PROVIDER, self.account.address, order_hash)
     order_sig = self._sign_order_hash(order_hash)
     return order, order_sig
def create_test_order(
    maker_address,
    maker_asset_amount,
    maker_asset_data,
    taker_asset_amount,
    taker_asset_data,
):
    """Create a test order."""
    order = Order(
        makerAddress=maker_address,
        takerAddress="powerchain0000000000000000000000000000000000000000",
        feeRecipientAddress=
        "powerchain0000000000000000000000000000000000000000",
        senderAddress="powerchain0000000000000000000000000000000000000000",
        makerAssetAmount=maker_asset_amount,
        takerAssetAmount=taker_asset_amount,
        makerFee=0,
        takerFee=0,
        expirationTimeSeconds=100000000000000,
        salt=random.randint(1, 1000000000),
        makerAssetData=maker_asset_data,
        takerAssetData=taker_asset_data,
        makerFeeAssetData=asset_data_utils.encode_erc20("powerchain" +
                                                        "00" * 20),
        takerFeeAssetData=asset_data_utils.encode_erc20("powerchain" +
                                                        "00" * 20),
    )
    return order
Exemple #3
0
def zrx_asset_data(zrx_address):  # pylint: disable=redefined-outer-name
    """Get 0x asset data for ZRX token."""
    return asset_data_utils.encode_erc20(zrx_address)
Exemple #4
0
def weth_asset_data():  # pylint: disable=redefined-outer-name
    """Get 0x asset data for Wrapped Ether (WETH) token."""
    return asset_data_utils.encode_erc20(
        NETWORK_TO_ADDRESSES[NetworkId.GANACHE].ether_token)
Exemple #5
0
def weth_asset_data():  # pylint: disable=redefined-outer-name
    """Get 0x asset data for Wrapped Ether (WETH) token."""
    return asset_data_utils.encode_erc20(
        chain_to_addresses(ChainId.GANACHE).ether_token)
Exemple #6
0
from collections import OrderedDict
from typing import List, Tuple
from zero_ex.contract_wrappers.exchange.types import Order, OrderInfo, OrderStatus
from zero_ex.sra_client import ApiClient, Configuration, DefaultApi
from zero_ex.order_utils import asset_data_utils
import networkx as nx
import random

from .order_graph import OrderGraph


TOKENS = {
    "USDC": "0x"
    + asset_data_utils.encode_erc20("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48").hex(),
    "WETH": "0x"
    + asset_data_utils.encode_erc20("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2").hex(),
    "ZRX": "0x"
    + asset_data_utils.encode_erc20("0xe41d2489571d322189246dafa5ebde1f4699f498").hex(),
    "SAI": "0x"
    + asset_data_utils.encode_erc20("0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359").hex(),
    "BAT": "0x"
    + asset_data_utils.encode_erc20("0x0d8775f648430679a709e98d2b0cb6250d2887ef").hex(),
}


class Pathfinder:
    def __init__(self,) -> None:
        self.orderGraph = OrderGraph([])

        # TODO: Get orders from other relayers
        radarConfig = Configuration()