Skip to content

Trading ABI

Use this ABI for direct onchain trading against the LeverUp Diamond on Monad mainnet. It is a raw JSON ABI array, so it can be passed directly to viem, ethers, web3.js, or another EVM client.

ContractLeverUp Diamond
Address0xea1b8E4aB7f14F7dCA68c5B214303B13078FC5ec
Chain ID143 (Monad mainnet)
FormatJSON ABI array

Download

Download leverup-trading-abi.json

Stable URL:

text
https://developer-docs.leverup.xyz/abi/leverup-trading-abi.json

The file contains the user-facing direct-trading functions, current read functions, lifecycle events, and relevant custom errors. The same ABI is used with the Diamond address for every entry — facet names only describe how the contract is organised internally.

The bundle intentionally excludes:

  • admin functions and keeper-only settlement functions;
  • legacy V2 and V3 read methods when a V4 method is available;
  • _forOneclick functions, which are protocol relay entrypoints rather than public integration methods;
  • ERC-20 approval and the standalone LVMONMinter ABI.

See Authorizing an Agent for 1CT authorization calls and Minting LVMON for the separate minter contract.

Pin the ABI in production

The download URL always represents the current documented deployment. Vendor the JSON into your application and review the changelog before updating it; this keeps a docs release from changing your runtime unexpectedly.

Load the ABI

ts
import type { Abi } from 'viem'

const ABI_URL = 'https://developer-docs.leverup.xyz/abi/leverup-trading-abi.json'

const response = await fetch(ABI_URL)
if (!response.ok) throw new Error(`ABI download failed: HTTP ${response.status}`)

export const tradingAbi = await response.json() as Abi

Or download and vendor it during your build:

bash
curl -L https://developer-docs.leverup.xyz/abi/leverup-trading-abi.json \
  --output leverup-trading-abi.json
ts
import tradingAbi from './leverup-trading-abi.json'
import { getContract } from 'viem'
import { publicClient, walletClient, account, DIAMOND } from './config'

const trading = getContract({
  address: DIAMOND,
  abi: tradingAbi,
  client: { public: publicClient, wallet: walletClient },
})

const positions = await trading.read.getPositionsV4([account.address, pairBase])

Write functions

Open orders

FunctionPayableDescription
openMarketTradeV2(OpenDataInput, OracleUpdateData, uint96)yesRequest a market open. Returns the pending trade hash.
openLimitOrderV2(OpenDataInput, OracleUpdateData, uint96)yesPlace a limit order. Returns the order hash.

Both calls require an oracle update and may require native-token msg.value. The last argument is the optional broker extraFee, not the oracle fee. See Market Orders and Limit Orders for executable examples.

Change or cancel a limit order

FunctionDescription
updateOrderTp(bytes32,uint128)Change the order's take-profit price.
updateOrderSl(bytes32,uint128)Change or clear the order's stop-loss price.
updateOrderTpAndSl(bytes32,uint128,uint128)Change TP and SL atomically.
cancelLimitOrder(bytes32)Cancel one unfilled limit order.
batchCancelLimitOrders(bytes32[])Cancel several unfilled limit orders.

These calls are not payable. Prices use 1e18 precision; see Precision & Units.

Close a position

Function signatureDescription
closeTrade(bytes32)Fully close using the position's existing broker.
closeTrade(bytes32,uint24)Fully close and specify the close-fee broker.
closeTrade(bytes32,uint128,uint24)Partially close closeQty and specify the broker.
batchCloseTrade(bytes32[])Fully close several positions using their existing brokers.
batchCloseTrade(bytes32[],uint24)Fully close several positions with one broker ID.

The ABI includes all overloads. With ethers, use the full signature when the overload is ambiguous, for example contract['closeTrade(bytes32,uint128,uint24)'](...). See Closing & Partial Close for lifecycle details.

Manage a position

FunctionPayableDescription
addMargin(bytes32,address,uint96)yesAdd collateral to an open position.
removeMargin(bytes32,uint96,OracleUpdateData)yesRemove margin after an oracle-backed risk check.
updateTradeTp(bytes32,uint128)noChange the embedded full-position take profit.
updateTradeSl(bytes32,uint128)noChange or clear the embedded full-position stop loss.
updateTradeTpAndSl(bytes32,uint128,uint128)noChange embedded TP and SL atomically.

addMargin is payable only when adding native MON; removeMargin uses msg.value for the oracle update fee. See Managing a Position.

TP/SL decrease orders

FunctionDescription
createDecreaseOrder(bytes32,DecreaseOrderInput)Create one standalone TP or SL order.
batchCreateDecreaseOrders(bytes32,DecreaseOrderInput[])Create multiple orders atomically.
batchUpdateDecreaseOrders(DecreaseOrderUpdateInput[])Update multiple active orders.
cancelDecreaseOrder(bytes32)Cancel one order.
cancelAllDecreaseOrders(bytes32)Cancel every order attached to a position.

These calls are not payable. closeQty uses 1e10 precision. See TP/SL Orders for order constraints and tuple definitions.

Read functions

Reads use the same Diamond address and do not require a wallet.

AreaFunctionsDescription
PositionsgetPositionsV4, getPositionByHashV4, getPositionByKeyV4Return current position snapshots.
Position identitygetPositionHash, getPositionTraderCompute or resolve a merged position hash.
Pending opensgetPendingTradeReturn a pending market-open request.
Limit ordersgetLimitOrders, getLimitOrderByHashReturn active limit orders.
TP/SL ordersgetDecreaseOrders, getTraderDecreaseOrders, getDecreaseOrderReturn active standalone decrease orders.
Market stategetMarketInfoV2, getMarketInfosV2Return open interest and funding state.
Pair configurationgetPairByBaseV4, getPairConfig, getPairFeeConfig, getPairHoldingFeeRate, getPairSlippageConfigReturn trading limits, fees, holding rates, and slippage settings.
Locked assetstraderAssetsReturn protocol-locked totals by token and purpose.

Return tuple layouts and examples are documented in Reading Data.

Shared ABI types

The JSON file includes the complete tuple components. These are the main types you will encounter:

TypeUsed byNotes
OpenDataInputMarket and limit opensPair, direction, collateral, quantity, price bounds, TP/SL, and broker.
OracleUpdateDataOpens and margin removalPyth and Pyth Pro update byte arrays.
PositionV4Position readsCurrent merged-position state and accrued fee fields.
LimitOrderViewLimit-order readsActive order state plus its orderHash.
DecreaseOrderInputTP/SL order creationKind, trigger price, close quantity, and broker.
DecreaseOrderUpdateInputTP/SL order updatesOrder hash plus replacement values.
OpenTradeEventV2Settlement eventsFull position snapshot after an open, increase, or decrease.
CloseInfoSettlement eventsFill price, funding fee, close fee, PnL, and holding fee.

Solidity enums appear in JSON ABI as their integer types. In particular, DecreaseOrderKind is uint8: 0 is TP and 1 is SL.

Events and errors

The ABI contains request and settlement events, including MarketPendingTrade, OpenPosition, PositionIncreased, PendingTradeRefund, OpenLimitOrder, CloseTradeRequested, ClosePosition, PositionDecreased, and the decrease-order events. Use settlement events—not only the transaction receipt—to determine whether a two-phase open or close actually completed. See Events.

Relevant custom error entries are included so clients can decode revert data with the same ABI. Some protocol failures still use Solidity's standard Error(string) or Panic(uint256) formats; handle those as a fallback. See Error Reference.

Trading perpetuals involves risk. Nothing here is financial advice.