Gas Operations

Gas vs Gas-Free Operations

Overview

The Opinion CLOB SDK implements a hybrid execution model: off-chain order matching via CLOB infrastructure eliminates gas costs for order operations, while direct smart contract invocations require BNB native token for transaction fees.

Gas-Free Operations

Off-Chain Order Book

The Central Limit Order Book functions as an off-chain matching engine. Orders are authenticated via EIP712 cryptographic signatures and submitted to the Opinion API. On-chain settlement is executed asynchronously by backend infrastructure, abstracting gas costs from end users.

Supported Gas-Free Operations

Market Data Queries

  • get_markets() - Market metadata retrieval

  • get_market() - Individual market details

  • get_categorical_market() - Categorical market information

  • get_orderbook() - Real-time order book snapshots

  • get_latest_price() - Current market prices

  • get_price_history() - Historical price data (OHLCV candles)

  • get_quote_tokens() - Supported collateral currencies

  • get_fee_rates() - Fee schedule information

Order Management

  • place_order() - Order submission (market and limit)

  • cancel_order() - Single order cancellation

  • cancel_all_orders() - Batch order cancellation

  • get_my_orders() - Active order retrieval

  • get_order_by_id() - Order status queries

Position Tracking

  • get_my_balances() - Token balance queries

  • get_my_positions() - Position inventory

  • get_my_trades() - Trade history

Technical Implementation

EIP712 Signature Protocol

Orders employ typed structured data signatures conforming to EIP712 specification. Signatures provide cryptographic proof of authorization without blockchain state modification.

Signature Generation Flow:

  1. Order parameters encoded per EIP712 TypedData standard

  2. Digest computed: keccak256("\x19\x01" β€– domainSeparator β€– structHash)

  3. ECDSA signature generated via secp256k1 curve

  4. Signature transmitted with order to API endpoint

  5. Backend performs ecrecover validation (signer authenticity)

  6. Matched orders batch-settled on-chain (gas paid by infrastructure)

Pseudocode:

Gas-Required Operations

On-Chain Smart Contract Invocations

Direct blockchain transactions invoke smart contract methods and require gas payment in BNB native tokens. These operations modify on-chain state and are irreversible post-confirmation.

Operations Requiring Gas

Token Approval (One-Time Setup)

  • enable_trading() - Grant ERC20/ERC1155 allowances to exchange contracts

Position Operations

  • split() - Invoke ConditionalTokens.splitPosition() (USDT β†’ outcome tokens)

  • merge() - Invoke ConditionalTokens.mergePositions() (outcome tokens β†’ USDT)

  • redeem() - Invoke ConditionalTokens.redeemPositions() (claim winning payouts)

State Query (RPC Call, No Gas)

  • check_enable_trading() - Read contract allowance state via eth_call

Gas Cost Analysis

BNB Chain Network Parameters

Parameter
Value
Notes

Block Time

~1.5s

Average block production interval

Gas Price

0.05 Gwei

Minimum gas price (EIP-1559 base fee)

Finality Threshold

10 blocks

Recommended confirmation depth (~15s)

Operation Gas Consumption Estimates

Operation
Gas Units
Cost @ 0.05 Gwei
USD Cost @ $600/BNB

enable_trading() (2 approvals)

~100,000

0.000005 BNB

$0.003

split()

~150,000

0.0000075 BNB

$0.0045

merge()

~120,000

0.000006 BNB

$0.0036

redeem()

~180,000

0.000009 BNB

$0.0054

Cost Formula:

Variability Factors:

  • Network congestion (gas price auction)

  • Contract state complexity (storage operations)

  • Transaction data size (calldata cost)

  • BNB market price volatility

Implementation Examples

Enable Trading (Required Once)

Required Approvals:

  • USDT Contract β†’ Exchange contract (for collateral deposits)

  • ConditionalTokens Contract β†’ Exchange contract (for outcome token trading)

Split Position

Use Cases:

  • Creating outcome tokens for selling

  • Market making strategies

  • Arbitrage opportunities

Merge Position

Requirements:

  • Must hold equal amounts of both outcome tokens

  • Amount specified in Wei (18 decimals)

Redeem Winnings

Redemption Logic:

  • Markets resolved to YES: 1 YES token β†’ 1 USDT

  • Markets resolved to NO: 1 NO token β†’ 1 USDT

  • Losing outcome tokens become worthless

Gas Balance Requirements

Maintain sufficient BNB balance to execute gas-required operations without transaction failures.

Allocation Guidelines:

Use Case
Minimum BNB
Rationale

Initial setup

0.001 BNB (~$0.60)

Single enable_trading() call

High-frequency

0.1 BNB (~$60.00)

Hundreds of transactions, failover capacity

Balance Monitoring

Position Management Planning

Structure trading strategies to minimize split/merge operations.

Example Strategy:

  1. Execute single split to create large token inventory

  2. Trade via gas-free CLOB orders

  3. Merge/redeem only when exiting position or market resolves

Next Steps

  • Precision - Token decimal systems

Last updated