Skip to content

Onchain Integration

Call the LeverUp Diamond directly from your own account. You control the key, you pay gas, and nothing sits between your code and the contracts.

If you want the protocol to relay and pay for your transactions instead, see Gasless Trading. The trade parameters are the same either way — this section is worth reading first regardless of which path you take.

Trading calls use one address

Diamond0xea1b8E4aB7f14F7dCA68c5B214303B13078FC5ec
Chain ID143 (Monad mainnet)

Point every trading call at that address and supply only the ABI fragment for the function you need. There is no separate address for limit orders, reads, or one-click trading. Standalone helper contracts are called out explicitly; for example, minting LVMON uses the separate LVMONMinter.

For a single machine-readable ABI covering direct trading writes, current reads, lifecycle events, and custom errors, see Trading ABI.

What you can do

OperationFunctionOracle dataPage
Mint LVMON from MON or WMONLVMONMinter.mintnoMinting LVMON
Open at marketopenMarketTradeV2yesMarket Orders
Open a limit orderopenLimitOrderV2yesLimit Orders
Cancel a limit ordercancelLimitOrder, batchCancelLimitOrdersnoLimit Orders
Change a limit order's TP/SLupdateOrderTpAndSlnoLimit Orders
Close fullycloseTrade, batchCloseTradenoClosing
Close partiallycloseTrade(hash, closeQty, broker)noClosing
Add marginaddMarginnoManaging a Position
Remove marginremoveMarginyesManaging a Position
Change a position's TP/SLupdateTradeTpAndSlnoManaging a Position
Create TP/SL ordersbatchCreateDecreaseOrdersnoTP/SL Orders
Update / cancel TP/SL ordersbatchUpdateDecreaseOrders, cancelDecreaseOrdernoTP/SL Orders
Read positions, orders, marketsgetPositionsV4, getLimitOrders, …n/aReading Data

"Oracle data: yes" means the call takes an OracleUpdateData argument and requires a native-token fee as msg.value. See Oracle updates.

Two-phase execution

Opens and closes are requests, not immediate state changes:

your tx                        keeper tx
   │                               │
   ├─ openMarketTradeV2 ──────────►│
   │  collateral locked            │  oracle price delivered
   │  MarketPendingTrade emitted   ├─► position opens
   │                               │  OpenPosition / PositionIncreased emitted

A successful receipt on your own transaction confirms the request was accepted. Confirm the outcome by watching events or polling getPositionsV4.

Requests can also be refunded — if the filled price falls outside your acceptable price, the market is closed, or a limit fails. A refund emits PendingTradeRefund with a reason code; see the Error Reference.

Before your first write

  1. Approve the Diamond for the collateral token you intend to use. Approve the Diamond address itself.
  2. Look up the pair with GET /v1/pairs — do not hardcode pairBase.
  3. Pair tokenIn with the right lvToken — see Collateral and lvToken.
  4. Get the units rightqty at 1e10, prices at 1e18. See Precision & Units.
  5. If you route trades for others, decide what to pass in broker before you start — it appears on opens, closes and TP/SL orders, and 0 is not a neutral value. See Brokers & Referrals.

Shared snippets

All examples on the following pages assume the config.ts from the Quickstart, plus this oracle helper:

ts
import { API } from './config'

export async function fetchOracleUpdate(
  pairBase: `0x${string}`,
  collateral: `0x${string}`,
) {
  const res = await fetch(`${API}/v1/oracle/price/updates/by-position`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      pairBase,
      collateral,
      blockChain: 'MONAD',
      options: { includeEncodingData: true, includeFee: true, includePrice: true },
    }),
  })
  if (!res.ok) throw new Error(`oracle: HTTP ${res.status}`)

  const data = await res.json()

  return {
    updateData: {
      pythPriceUpdateData: data.pythPriceUpdateData ?? [],
      pythProPriceUpdateData: data.pythProPriceUpdateData ?? [],
    },
    value: BigInt(data.updateFee ?? '0') + BigInt(data.verifition_fee ?? '0'),
  }
}

Native MON collateral

When tokenIn is native MON (0x0), request oracle data using the WMON address as collateral, and set the transaction value to amountIn + oracleValue instead of just oracleValue.

Trading perpetuals involves risk. Nothing here is financial advice.