Craftec Docs
SalamCraftPerpetual Trading

How It Works

Architecture and mechanics of SalamCraft perpetual trading

Architecture

SalamCraft is a Shariah-compliant DeFi protocol built with Anchor on Solana. The perpetual trading components are:

  1. Pools — Multi-asset liquidity pools that hold USDC, SOL, and other tokens
  2. Markets — Trading pairs (e.g. SOL-USDC) with configurable risk exposure and fees
  3. Positions — Long (buy) or short (sell) positions opened by traders
  4. Oracles — Pyth Network price feeds providing real-time mark prices
  5. Keepers — Off-chain bots that execute limit orders and liquidations

Islamic Contract Mapping

Every step in SalamCraft maps to an established Islamic finance contract:

ComponentIslamic ContractDescription
User marginRahn (Pledge)USDC collateral locked for the position duration
Pool financingQard (Benevolent Loan)Interest-free loan — pool lends quote (buy) or base (sell)
Trade executionWakalah (Agency)Pool executes the buy/sell at Pyth oracle price
Daily feeUjrah (Service Fee)Flat fee on notional for daily risk management
Closing feeUjrah (Service Fee)One-time fee at position close

Position Lifecycle

Opening a Position

  1. Trader deposits margin (USDC) as Rahn (collateral pledge)
  2. Protocol calculates notional value = margin × risk multiplier
  3. Pool provides a Qard (interest-free loan):
    • Buy (long): Pool lends USDC (quote), trader buys the base asset
    • Sell (short): Pool lends base tokens (e.g. SOL), trader sells for USDC
  4. The trade is executed internally via Wakalah at the Pyth oracle price
  5. Position is recorded on-chain with entry price, margin, and liquidation price

Closing a Position

  1. Current price is fetched from Pyth oracle
  2. PnL is calculated based on entry price vs. current price
  3. Settlement follows the waterfall: Qard repayment → Ujrah fees → profit cap → remaining to user
  4. For profitable trades: trader receives margin + profit (capped at max profit)
  5. For losing trades: losses are deducted from margin
  6. Pool receives back its Qard plus applicable Ujrah fees

Liquidation

When a position's margin drops below the maintenance threshold, it becomes eligible for liquidation. Liquidators earn a fee for closing unhealthy positions, protecting the pool from bad debt.

Fee Structure

Fee TypeDescription
Opening UjrahService fee charged when opening a position (basis points on notional)
Closing UjrahService fee charged when closing a position
Daily UjrahAccrues daily based on pool utilization — compensates LPs for capital lockup
Liquidation FeePaid to the liquidator from the position's remaining margin

All fees are structured as Ujrah (service fees) — not interest. They flow to the liquidity pool, rewarding LPs for providing capital.

Max Profit Cap

Each position has a maximum profit cap to protect the pool from catastrophic losses. The cap is defined per-market and limits how much a single trade can extract from the pool.

On this page