LogoLogo
Join DiscordFollow on XBridge FundsLong $BERA
  • Doc Bros v1
    • Overview
    • Key Features
      • Speed & Liquidity is Key
      • Bropetual Markets
      • A Hub for Berachain DeFi
    • Proof-of-Liquidity
      • Reward Vault
    • Power of Points
    • Partners & Integrations
    • Campaigns
      • bro.trade Em Up
  • bullish bros
    • SuperBros NFT
  • Technicals
    • What is Proof-of-Liquidity?
    • One-Click Trading
    • Funding Rates
  • Liquidations & Insurance Fund
  • Vertex Edge Sequencer
  • Fees
  • PnL Settlements
  • Withdrawals
  • Pricing (Oracles)
  • links & resources
    • bro.trade Links
      • Website
      • Trade Bropetuals
      • Discord
      • X (Twitter)
      • Medium
      • Swap on OogaBooga
    • Berachain Links
      • Berachain.com
      • Official Bridge
      • BeraHub
      • Berascan
      • Bera Discord
      • Berachain X (Twitter)
      • Berachain Docs
    • FAQ
  • developer bros
    • API
      • Gateway
        • Executes
          • Place Order
          • Cancel Order
          • Cancel and Place
          • Cancel Product Order
          • Withdraw Colleteral
          • Transfer Quote
          • Liquidate Subaccount
          • Mint LP
          • Burn LP
          • Link Signer
        • Queries
          • All Products
          • Contracts
          • Fee Rates
          • Health Groups
          • Insurance
          • Linked Signer
          • Market Liquidity
          • Market Prices
          • Max Lp Mintable
          • Max Order Size
          • Max Withdrawable
          • Min Deposit Rates
          • Nonces
          • Order
          • Orders
          • Status
          • Subaccount Info
          • Symbols
        • Signing
          • Examples
          • Q A
      • Subscriptions
        • Authentication
        • Streams
        • Events
        • Rate Limits
      • Archive (indexer)
        • Candlesticks
        • Events
        • Funding Rate
        • Interest Funding Payments
        • Linked Signer Rate Limit
        • Liquidation Feed
        • Maker Statistics
        • Market Snapshots
        • Matches
        • Merkle Proofs
        • Oracle Price
        • Orders
        • Perp Prices
        • Product Snapshots
        • Rewards
        • Signatures
        • Subaccounts
        • Summary
        • HONEY Price
      • Trigger
        • Executes
          • Place Order
          • Cancel Orders
          • Cancel Product Orders
        • Queries
          • List Trigger Orders
      • V2
        • Apr
        • Assets
        • Contracts
        • Orderbook
        • Pairs
        • Tickers
        • Trades
      • Rate limits
      • Errors
      • Symbols
      • Depositing
      • Withdrawing (on-chain)
      • Integrate via Smart Contracts
      • Definitions / Formulas
    • On-Chain Contracts
Powered by GitBook
On this page
  1. developer bros
  2. API
  3. Gateway
  4. Signing

Examples

The following are full examples of EIP12 typed data for each of bro.trade’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')
import { arrayify } from 'ethers/lib/utils';

export function hexToBytes32(subaccount: string) {
const subaccountBytes = arrayify(subaccount);
const bytes32 = new Uint8Array(32);
for (let i = 0; i < Math.min(subaccountBytes.length, 32); i++) {
    bytes32[i] = subaccountBytes[i];
}
return bytes32;
}

const sender = hexToBytes32('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': 'bro.trade',
        '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'}
         ],
         'Cancellation': [
             { 'name': 'sender', 'type': 'bytes32' },
             { 'name': 'productIds', 'type': 'uint32[]'},
             { 'name': 'digests', 'type': 'bytes32[]'},
             { 'name': 'nonce', 'type': 'uint64'},
         ],
     },
     'primaryType': 'Cancellation',
     'domain': {
         'name': 'bro.trade',
         'version': '0.0.1',
         'chainId': 421613,  
         'verifyingContract': '0xbf16e41fb4ac9922545bfc1500f67064dc2dcc3b'
     },
     'message': {
         'sender': hex_to_bytes32('0x841fe4876763357975d60da128d8a54bb045d76a64656661756c740000000000'),
         'productIds': [4],
         'digests': [hex_to_bytes32('0x51ba8762bc5f77957a4e896dba34e17b553b872c618ffb83dba54878796f2821')],
         'nonce': 1,
     },
 }
{
    'types': {
        'EIP712Domain': [
            {'name': 'name', 'type': 'string'},
            {'name': 'version', 'type': 'string'},
            {'name': 'chainId', 'type': 'uint256'},
            {'name': 'verifyingContract', 'type': 'address'}
        ],
        'CancellationProducts': [
            {'name': 'sender', 'type': 'bytes32'},
            {'name': 'productIds', 'type': 'uint32[]'},
            {'name': 'nonce', 'type': 'uint64'},
        ],
    },
    'primaryType': 'CancellationProducts',
    'domain': {
        'name': 'bro.trade',
        'version': '0.0.1',
        'chainId': 421613,  
        'verifyingContract': '0xbf16e41fb4ac9922545bfc1500f67064dc2dcc3b'
    },
    'message': {
        'sender': hex_to_bytes32('0x841fe4876763357975d60da128d8a54bb045d76a64656661756c740000000000'),
        'productIds': [2, 4],
        'nonce': 1,
    },
}
{
    'types': {
        'EIP712Domain': [
            {'name': 'name', 'type': 'string'},
            {'name': 'version', 'type': 'string'},
            {'name': 'chainId', 'type': 'uint256'},
            {'name': 'verifyingContract', 'type': 'address'}
        ],
        'LinkSigner': [
            {'name': 'sender', 'type': 'bytes32'},
            {'name': 'signer', 'type': 'bytes32'},
            {'name': 'nonce', 'type': 'uint64'},
        ],
    },
    'primaryType': 'LinkSigner',
    'domain': {
        'name': 'bro.trade',
        'version': '0.0.1',
        'chainId': 421613,  
        'verifyingContract': '0xbf16e41fb4ac9922545bfc1500f67064dc2dcc3b'
    },
    'message': {
        'sender': hex_to_bytes32('0x841fe4876763357975d60da128d8a54bb045d76a64656661756c740000000000'),
        'signer': hex_to_bytes32('0x12a0b4888021576eb10a67616dd3dd3d9ce206b664656661756c740000000000'),
        'nonce': 1,
    },
}
{
    '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': 'bro.trade',
        'version': '0.0.1',
        'chainId': 421613,  
        'verifyingContract': '0xbf16e41fb4ac9922545bfc1500f67064dc2dcc3b'
    },
    'message': {
        'sender': hex_to_bytes32('0x841fe4876763357975d60da128d8a54bb045d76a64656661756c740000000000'),
        'productId': 2,
        'amount': 10000000000000000,
        'nonce': 1
    },
}
 {
     'types': {
         'EIP712Domain': [
             {'name': 'name', 'type': 'string'},
             {'name': 'version', 'type': 'string'},
             {'name': 'chainId', 'type': 'uint256'},
             {'name': 'verifyingContract', 'type': 'address'}
         ],
         'LiquidateSubaccount': [
             {'name': 'sender', 'type': 'bytes32'},
             {'name': 'liquidatee', 'type': 'bytes32'},
             {'name': 'productId', 'type': 'uint32'},
             {'name': 'isEncodedSpread', 'type': 'bool'},
             {'name': 'amount', 'type': 'int128'},
             {'name': 'nonce', 'type': 'uint64'},
         ],
     },
     'primaryType': 'LiquidateSubaccount',
     'domain': {
         'name': 'bro.trade',
         'version': '0.0.1',
         'chainId': 421613,  
         'verifyingContract': '0xbf16e41fb4ac9922545bfc1500f67064dc2dcc3b'
     },
     'message': {
         'sender': hex_to_bytes32('0x841fe4876763357975d60da128d8a54bb045d76a64656661756c740000000000'),
         'liquidatee': hex_to_bytes32('0x12a0b4888021576eb10a67616dd3dd3d9ce206b664656661756c740000000000'),
         'productId': 1,
         'isEncodedSpread': false,
         'amount': 10000000000000000,
         'nonce': 1,
     },
 }
{
    'types': {
        'EIP712Domain': [
            {'name': 'name', 'type': 'string'},
            {'name': 'version', 'type': 'string'},
            {'name': 'chainId', 'type': 'uint256'},
            {'name': 'verifyingContract', 'type': 'address'}
        ],
        'MintLp': [
            {'name': 'sender', 'type': 'bytes32' },
            {'name': 'productId', 'type': 'uint32'},
            {'name': 'amountBase', 'type': 'uint128'},
            {'name': 'quoteAmountLow', 'type': 'uint128'},
            {'name': 'quoteAmountHigh', 'type': 'uint128'},
            {'name': 'nonce', 'type': 'uint64' },
        ],
    },
    'primaryType': 'MintLp',
    'domain': {
        'name': 'bro.trade',
        'version': '0.0.1',
        'chainId': 421613,  
        'verifyingContract': '0xbf16e41fb4ac9922545bfc1500f67064dc2dcc3b'
    },
    'message': {
        'sender': hex_to_bytes32('0x841fe4876763357975d60da128d8a54bb045d76a64656661756c740000000000'),
        'productId': 1,
        'amountBase': 1000000000000000000,
        'quoteAmountLow': 20000000000000000000000,
        'quoteAmountHigh': 40000000000000000000000,
        'nonce': 1,
    },
}
{
 'types': {
     'EIP712Domain': [
         {'name': 'name', 'type': 'string'},
         {'name': 'version', 'type': 'string'},
         {'name': 'chainId', 'type': 'uint256'},
         {'name': 'verifyingContract', 'type': 'address'}
     ],
     'BurnLp': [
         {'name': 'sender', 'type': 'bytes32'},
         {'name': 'productId', 'type': 'uint32'},
         {'name': 'amount', 'type': 'uint128'},
         {'name': 'nonce', 'type': 'uint64'},
     ],
 },
 'primaryType': 'BurnLp',
 'domain': {
     'name': 'bro.trade',
     'version': '0.0.1',
     'chainId': 421613,  
     'verifyingContract': '0xbf16e41fb4ac9922545bfc1500f67064dc2dcc3b'
 },
 'message': {
     'sender': hex_to_bytes32('0x841fe4876763357975d60da128d8a54bb045d76a64656661756c740000000000'),
     'productId': 1,
     'amount': 1000000000000000000,
     'nonce': 1,
 },
}
{
'types': {
    'EIP712Domain': [
        {'name': 'name', 'type': 'string'},
        {'name': 'version', 'type': 'string'},
        {'name': 'chainId', 'type': 'uint256'},
        {'name': 'verifyingContract', 'type': 'address'}
    ],
    'ListTriggerOrders': [
        {'name': 'sender', 'type': 'bytes32' },
        {'name': 'recvTime', 'type': 'uint64' }
    ],
},
'primaryType': 'WithdrawCollateral',
'domain': {
    'name': 'bro.trade',
    'version': '0.0.1',
    'chainId': 421613,  
    'verifyingContract': '0xbf16e41fb4ac9922545bfc1500f67064dc2dcc3b'
},
'message': {
    'sender': hex_to_bytes32('0x841fe4876763357975d60da128d8a54bb045d76a64656661756c740000000000'),
    'recvTime': 1688939576000
},
}
PreviousSigningNextQ A

Last updated 3 months ago