Skip to main content

Universal Trading Account (UTA)

The UTA module provides a unified margin account for trading perpetuals and spot markets.

Overview

Instead of managing separate collateral for each position, UTA provides:

  • Single margin account for all positions
  • Cross-margining across positions
  • Up to 10x leverage on perpetuals
  • Unified P&L calculation
┌─────────────────────────────────────────────────────────────┐
│ Universal Trading Account │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Collateral Pool │ │
│ │ wBTC: 1.5 wETH: 10 USDC: 5000 │ │
│ └─────────────────────────────────────────────────────┘ │
│ │ │
│ ┌────────────────┼────────────────┐ │
│ ▼ ▼ ▼ │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ BTC-PERP │ │ ETH-PERP │ │ SOL-PERP │ │
│ │ Long 0.5 │ │ Short 2 │ │ Long 100 │ │
│ │ +$500 PnL │ │ -$200 PnL │ │ +$50 PnL │ │
│ └────────────┘ └────────────┘ └────────────┘ │
│ │
│ Total Collateral: $25,000 Total Margin Used: $15,000 │
│ Health Factor: 1.67 Available: $10,000 │
└─────────────────────────────────────────────────────────────┘

Opening Positions

Long Position

rp1d tx uta open-position \
--market BTC-PERP \
--direction long \
--size 0.5 \
--leverage 5 \
--from my-wallet

Short Position

rp1d tx uta open-position \
--market ETH-PERP \
--direction short \
--size 2 \
--leverage 3 \
--from my-wallet

Managing Collateral

Deposit Collateral

rp1d tx uta deposit \
--amount 1000000uusdc \
--from my-wallet

Withdraw Collateral

rp1d tx uta withdraw \
--amount 500000uusdc \
--from my-wallet

TypeScript SDK

import { UTAModule } from '@rp1/sdk';

const uta = new UTAModule(client);

// Deposit collateral
await uta.deposit(wallet, '1000000', 'uusdc');

// Open long position
const position = await uta.openPosition(wallet, {
market: 'BTC-PERP',
direction: 'long',
size: '0.5',
leverage: 5,
});

// Check account
const account = await uta.getAccount(wallet.address);
console.log(`Health Factor: ${account.healthFactor}`);
console.log(`Total Collateral: ${account.totalCollateral}`);
console.log(`Unrealized PnL: ${account.unrealizedPnl}`);

// Close position
await uta.closePosition(wallet, position.id);

Margin Calculation

Initial Margin

Initial Margin = Position Size × Entry Price / Leverage

Maintenance Margin

Maintenance Margin = Position Size × Entry Price × Maintenance Rate
MarketMaintenance Rate
BTC-PERP0.5%
ETH-PERP0.75%
SOL-PERP1%

Health Factor

Health Factor = Total Collateral Value / Total Maintenance Margin
  • Health Factor > 1: Safe
  • Health Factor < 1: Liquidation risk
  • Health Factor < 0.5: Liquidation triggered

Liquidation

When Health Factor falls below liquidation threshold:

  1. Position partially or fully closed
  2. Liquidation fee charged (0.5%)
  3. Remaining collateral returned to user
# Anyone can liquidate undercollateralized accounts
rp1d tx uta liquidate \
--account rp1underwater... \
--market BTC-PERP \
--from liquidator-wallet

Liquidators receive:

  • 50% of liquidation fee
  • Gas costs covered

Funding Rate

Perpetual positions pay/receive funding every 8 hours:

Funding Rate = (Mark Price - Index Price) / Index Price × Funding Factor
  • Long pays Short when Mark > Index
  • Short pays Long when Mark < Index
# Check current funding rate
rp1d query uta funding-rate BTC-PERP

Query Commands

Account Info

rp1d query uta account $(rp1d keys show my-wallet -a)

Position Details

rp1d query uta position \
--owner $(rp1d keys show my-wallet -a) \
--market BTC-PERP

All Open Positions

rp1d query uta positions $(rp1d keys show my-wallet -a)

Message Types

MsgOpenPosition

message MsgOpenPosition {
string owner = 1;
string market = 2;
string direction = 3; // "long" or "short"
string size = 4;
uint32 leverage = 5;
}

MsgClosePosition

message MsgClosePosition {
string owner = 1;
string market = 2;
}

Parameters

ParameterDefaultDescription
max_leverage10Maximum leverage allowed
liquidation_threshold0.5Health factor for liquidation
liquidation_fee0.0050.5% liquidation fee
funding_interval8hFunding payment interval

Events

EventTypePositionOpened = "uta_position_opened"
EventTypePositionClosed = "uta_position_closed"
EventTypeLiquidation = "uta_liquidation"
EventTypeFundingPayment = "uta_funding_payment"

Risk Management

  1. Set stop-loss: Use limit orders to cap losses
  2. Monitor health factor: Keep above 1.5 for safety margin
  3. Diversify: Don't concentrate in single position
  4. Watch funding: High funding rates can erode profits

Next Steps