Examples

Vertex executes EIP712 typed data examples

The following are full examples of EIP12 typed data for each of Vertex's executes. Each execute includes a sender field which is a solidity bytes32 . There are two components to this field:

  • an address that is a bytes20

  • a subaccount identifier that is a bytes12

For example, if your address was 0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43, and you wanted to use the default subaccount identifier (i.e: an empty identifier "") you can set sender to 0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43000000000000000000000000 , which sets all bytes of the subaccount identifier to 0.

Note: a bytes32 representation of the sender must used when signing the request.

See below a sample util to convert a hex to a bytes32:

def hex_to_bytes32(hex_string):
    if hex_string.startswith("0x"):
        hex_string = hex_string[2:]
    data_bytes = bytes.fromhex(hex_string)
    padded_data = data_bytes + b"\x00" * (32 - len(data_bytes))
    return padded_data

sender = hex_to_bytes32('0x841fe4876763357975d60da128d8a54bb045d76a64656661756c740000000000')

EIP712 Typed data examples

{
    'types': {
        'EIP712Domain': [
            {'name': 'name', 'type': 'string'},
            {'name': 'version', 'type': 'string'},
            {'name': 'chainId', 'type': 'uint256'},
            {'name': 'verifyingContract', 'type': 'address'}
        ],
        'Order': [
            {'name': 'sender', 'type': 'bytes32'},
            {'name': 'priceX18', 'type': 'int128'},
            {'name': 'amount', 'type': 'int128'},
            {'name': 'expiration', 'type': 'uint64'},
            {'name': 'nonce', 'type': 'uint64'},
        ],
    },
    'primaryType': 'Order',
    'domain': {
        'name': 'Vertex',
        'version': '0.0.1',
        'chainId': 421613,  
        'verifyingContract': '0xf03f457a30e598d5020164a339727ef40f2b8fbc'
    },
    'message': {
        'sender': hex_to_bytes32('0x841fe4876763357975d60da128d8a54bb045d76a64656661756c740000000000'),
        'priceX18': 28898000000000000000000,
        'amount': -10000000000000000,
        'expiration': 4611687701117784255,
        'nonce': 1764428860167815857,
    },
}
{
    'types': {
        'EIP712Domain': [
            {'name': 'name', 'type': 'string'},
            {'name': 'version', 'type': 'string'},
            {'name': 'chainId', 'type': 'uint256'},
            {'name': 'verifyingContract', 'type': 'address'}
        ],
        'WithdrawCollateral': [
            {'name': 'sender', 'type': 'bytes32'},
            {'name': 'productId', 'type': 'uint32'},
            {'name': 'amount', 'type': 'uint128'},
            {'name': 'nonce', 'type': 'uint64'},
        ],
    },
    'primaryType': 'WithdrawCollateral',
    'domain': {
        'name': 'Vertex',
        'version': '0.0.1',
        'chainId': 421613,  
        'verifyingContract': '0xbf16e41fb4ac9922545bfc1500f67064dc2dcc3b'
    },
    'message': {
        'sender': hex_to_bytes32('0x841fe4876763357975d60da128d8a54bb045d76a64656661756c740000000000'),
        'productId': 2,
        'amount': 10000000000000000,
        'nonce': 1
    },
}

Last updated