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

Integrate via Smart Contracts

PreviousWithdrawing (on-chain)NextDefinitions / Formulas

Last updated 2 months ago

Smart contracts can use the LinkSigner transaction type (see ) to perform the following:

  1. Deposit into bro.trade.

  2. LinkSigner an externally owned account ().

  3. Have the externally owned account trade using the smart contract's assets on bro.trade.

Setup: Depositing into bro.trade + Linking an EOA

  1. Deposits are always on-chain, as such, users can simply have their smart contract call on our Endpoint contract (see for addresses).

  2. The contract needs to have 1 HONEY available to pay for slow-mode fee and approve the endpoint contract, assemble the bytes for a slow mode linked signer transaction, and submit it via .

You can find the requisite parsing logic in the contract.

Example

struct LinkSigner {
    bytes32 sender;
    bytes32 signer;
    uint64 nonce;
}

function linkVertexSigner(
        address vertexEndpoint,
        address externalAccount,
        address honeyAddress
    ) external {
    // 1. a slow mode fee of 1 HONEY needs to be avaliable and approved
    ERC20 honeyToken =  ERC20(honeyAddress);
    
    // NOTE: should double check the HONEY decimals in the corresponding chain.
    // e.g: it's 1e6 on arbitrum, whereas it's 1e18 on blast, etc.
    uint256 SLOW_MODE_FEE = 1e6;
    honeyToken.transferFrom(msg.sender, address(this), SLOW_MODE_FEE);
    honeyToken.approve(vertexEndpoint, SLOW_MODE_FEE);
    
    // 2. assamble the link signer slow mode transaction
    bytes12 defaultSubaccountName = bytes12(abi.encodePacked("default"));
    bytes32 contractSubaccount = bytes32(
        abi.encodePacked(uint160(address(this)), defaultSubaccountName)
    );
    bytes32 externalSubaccount = bytes32(
        uint256(uint160(externalAccount)) << 96
    );
    LinkSigner memory linkSigner = LinkSigner(
        contractSubaccount,
        externalSubaccount,
        IEndpoint(vertexEndpoint).getNonce(externalAccount)
    );
    bytes memory txs = abi.encodePacked(
        uint8(19),
        abi.encode(linkSigner)
    );
    
    // 3. submit slow mode transaction
    IEndpoint(vertexEndpoint).submitSlowModeTransaction(txs);
}

Once the transaction is confirmed, it may take a few seconds for it to make its way into the bro.trade offchain sequencer. Afterwards, you can sign transactions that have sender contractSubaccount using externalSubaccount, and they will be accepted by the sequencer and the blockchain.

Link Signer
EOA
depositCollateral
Contracts
submitSlowModeTransaction
Endpoint