Example #1
0
def get_domain_hash():
    return Web3.solidityKeccak(
        ['bytes32', 'bytes32', 'bytes32', 'uint256', 'bytes32'], [
            utils.hash_string(EIP712_DOMAIN_STRING),
            utils.hash_string('P1Orders'),
            utils.hash_string('1.0'), consts.NETWORK_ID,
            utils.address_to_bytes32(consts.P1_ORDERS_ADDRESS)
        ]).hex()
Example #2
0
def get_order_hash(order):
    '''
    Returns the final signable EIP712 hash for an order.
    '''

    struct_hash = Web3.solidityKeccak([
        'bytes32', 'bytes32', 'uint256', 'uint256', 'uint256', 'uint256',
        'bytes32', 'bytes32', 'uint256'
    ], [
        utils.hash_string(EIP712_ORDER_STRUCT_STRING),
        get_order_flags(order['salt'], order['isBuy'], order['limitFee']),
        int(order['amount']),
        int(order['limitPrice'] * consts.BASE_DECIMAL),
        int(order['triggerPrice'] * consts.BASE_DECIMAL),
        int(abs(order['limitFee']) * consts.BASE_DECIMAL),
        utils.address_to_bytes32(order['maker']),
        utils.address_to_bytes32(order['taker']),
        int(order['expiration'])
    ]).hex()
    return utils.get_eip712_hash(get_domain_hash(), struct_hash)
Example #3
0
def get_domain_hash(pair):
    contract_name = ''
    contract_address = ''
    if pair == consts.PAIR_PBTC_USDC:
        contract_name = 'P1Orders'
        contract_address = consts.BTC_P1_ORDERS_ADDRESS
    elif pair == consts.PAIR_PLINK_USDC:
        contract_name = 'P1Orders'
        contract_address = consts.LINK_P1_ORDERS_ADDRESS
    elif pair == consts.PAIR_WETH_PUSD:
        contract_name = 'P1InverseOrders'
        contract_address = consts.ETH_P1_ORDERS_ADDRESS
    else:
        raise ValueError('Invalid perpetual pair')

    return Web3.solidityKeccak(
        ['bytes32', 'bytes32', 'bytes32', 'uint256', 'bytes32'], [
            utils.hash_string(EIP712_DOMAIN_STRING),
            utils.hash_string(contract_name),
            utils.hash_string('1.0'), consts.NETWORK_ID,
            utils.address_to_bytes32(contract_address)
        ]).hex()
Example #4
0
 def test_util_address_to_bytes32(self):
     expected_result = "0x" + ADDRESS_1_NO_PREFIX.zfill(64)
     assert utils.address_to_bytes32(ADDRESS_1_NO_PREFIX) == expected_result
     assert utils.address_to_bytes32(ADDRESS_1) == expected_result