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:
- Pools — Multi-asset liquidity pools that hold USDC, SOL, and other tokens
- Markets — Trading pairs (e.g. SOL-USDC) with configurable risk exposure and fees
- Positions — Long (buy) or short (sell) positions opened by traders
- Oracles — Pyth Network price feeds providing real-time mark prices
- Keepers — Off-chain bots that execute limit orders and liquidations
Islamic Contract Mapping
Every step in SalamCraft maps to an established Islamic finance contract:
| Component | Islamic Contract | Description |
|---|---|---|
| User margin | Rahn (Pledge) | USDC collateral locked for the position duration |
| Pool financing | Qard (Benevolent Loan) | Interest-free loan — pool lends quote (buy) or base (sell) |
| Trade execution | Wakalah (Agency) | Pool executes the buy/sell at Pyth oracle price |
| Daily fee | Ujrah (Service Fee) | Flat fee on notional for daily risk management |
| Closing fee | Ujrah (Service Fee) | One-time fee at position close |
Position Lifecycle
Opening a Position
- Trader deposits margin (USDC) as Rahn (collateral pledge)
- Protocol calculates notional value = margin × risk multiplier
- 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
- The trade is executed internally via Wakalah at the Pyth oracle price
- Position is recorded on-chain with entry price, margin, and liquidation price
Closing a Position
- Current price is fetched from Pyth oracle
- PnL is calculated based on entry price vs. current price
- Settlement follows the waterfall: Qard repayment → Ujrah fees → profit cap → remaining to user
- For profitable trades: trader receives margin + profit (capped at max profit)
- For losing trades: losses are deducted from margin
- 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 Type | Description |
|---|---|
| Opening Ujrah | Service fee charged when opening a position (basis points on notional) |
| Closing Ujrah | Service fee charged when closing a position |
| Daily Ujrah | Accrues daily based on pool utilization — compensates LPs for capital lockup |
| Liquidation Fee | Paid 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.