Skip to content

Repository files navigation

Minswap Lending Market – Long/Short

Status: ✅ Project Complete — all milestones (1–6) delivered and approved.

The Minswap Lending Market brings leveraged long/short trading to Cardano by combining Minswap DEX V2 swaps with Liqwid lending. Users open and manage leveraged positions through a single, integrated interface, with the full multi-step lifecycle automated by a backend state machine.

Live Interface

👉 https://app.minswap.org/margin — open, monitor, and close leveraged long/short positions directly on Minswap.

Project Catalyst — Funded Proposal

This work was delivered under a Project Catalyst proposal across six milestones:

Milestone Deliverable Status
1–2 Proof-of-Concept: core SDK integration, Nitro Wallet, minimal UI ✅ Complete
3 UI integration for long positions ✅ Complete
4 UI integration for short positions ✅ Complete
5 Testing, hardening, and deployment ✅ Complete
6 User feedback collection and close-out ✅ Complete

The sections below document the Milestone 3 to 5 deliverables in detail and remain as a record of the work.

Close-out — Results & Reports

Quantitative Measures (last 30 days)

Metric Value
Users accessing the service 272
Active users 149
Number of actions (deposit/withdraw/open/close) 338
Volume over 13,000 ₳

Qualitative Measures & Reports


What changed since Milestone 1, 2

Milestone 1–2 delivered a Proof-of-Concept with hardcoded values, minimal UI, and the core SDK integration.

Milestones 3–6 deliver a production-grade, mainnet-deployed system with:

  • A full backend server (API, database, state machine) that orchestrates multi-step leveraged positions end-to-end on Cardano Mainnet.
  • A polished trading interface integrated into the Minswap page at /margin, replacing the POC.
  • Real-time data feeds for asset prices, lending rates, and position health.
  • Educational content and risk warnings for short position mechanics.
  • An user feedback evaluation period to collect user insights and plan future improvements.

"A tour" of what I accomplished in Milestone 3

Milestone Outputs

User-friendly interface for executing long position strategies.

  • Production Backend Infrastructure: Built a Fastify API server with PostgreSQL database, handling the full lifecycle of long positions — from opening to closing — through an automated state machine.
  • Integrated Trading UI: A single-page interface at /margin where users can open, monitor, and close long positions without ever leaving Minswap or visiting Liqwid directly.
  • Real-time Data Feeds: Live asset prices, lending APY rates, position health factor, liquidation price, and unrealized PnL — all visible in the interface.

Acceptance Criteria

Users can initiate and manage long positions through a single, intuitive interface.

  • Users open a long position by selecting the market (e.g., ADA-MIN), entering their collateral amount, and clicking "Open Long Position".
  • The backend state machine automatically orchestrates the full 4-step opening sequence:
    1. LONG_BUY — Swap ADA → MIN on Minswap DEX V2
    2. LONG_SUPPLY — Supply MIN to Liqwid as collateral
    3. LONG_BORROW — Borrow ADA against the supplied collateral
    4. LONG_BUY_MORE — Use borrowed ADA to buy additional MIN (leverage)
  • Users manage their open position from the same interface: view current P&L, health factor, interest accrued, and entry/liquidation prices.
  • Closing a position triggers the automated 4-step closing sequence:
    1. LONG_SELL — Sell MIN → ADA
    2. LONG_REPAY — Repay the loan to Liqwid
    3. LONG_WITHDRAW — Withdraw collateral from Liqwid
    4. LONG_SELL_ALL — Sell remaining MIN to capture profit
  • The interface also supports fractional repay flows (LONG_REPAY_FRACTION → LONG_WITHDRAW_FRACTION → LONG_SELL_FREED) for partial position management.

Latest data feeds provide accurate information on asset prices, lending rates, and position health.

The interface displays live data feeds including:

  • Asset Price: Current ADA/MIN price from the Minswap aggregator
  • Lending Rates: Supply APY and Borrow APY fetched from Liqwid V2 API
  • Position Health: Health factor from Liqwid's loansForUser API
  • Entry Price: Calculated from the user's actual swap execution data
  • Liquidation Price: Derived from the current price and health factor
  • Unrealized PnL: Current token value minus total invested (collateral + borrowed amount)
  • Accrued Interest: Outstanding borrow interest from Liqwid

All data is served through the backend API endpoint GET /position/get, which computes these metrics on each request using live on-chain and Liqwid data.


"A tour" of what I accomplished in Milestone 4

Milestone Outputs

User-friendly interface for executing short position strategies.

  • Short Position Trading: Users can open and close short positions from the same /margin interface, with full automation of the 3-step opening and 3-step closing sequences.
  • Risk & Educational Content: The interface includes warnings about short position mechanics, liquidation scenarios, and leverage risks.

Acceptance Criteria

Users can initiate and manage short positions through a single, intuitive interface.

  • Users open a short position by selecting the market, entering their ADA collateral, and clicking "Open Short Position".
  • The backend state machine automatically orchestrates the 3-step opening sequence:
    1. SHORT_SUPPLY — Supply ADA to Liqwid as collateral
    2. SHORT_BORROW — Borrow MIN against the ADA collateral
    3. SHORT_SELL — Sell borrowed MIN → ADA on Minswap DEX V2
  • Closing a short position triggers the automated 3-step closing sequence:
    1. SHORT_BUY — Buy back MIN with ADA
    2. SHORT_REPAY — Repay the borrowed MIN to Liqwid
    3. SHORT_WITHDRAW — Withdraw ADA collateral from Liqwid
  • Users can monitor their short position with the same real-time metrics: entry price, current price, unrealized PnL, health factor, interest, and liquidation price.

Educational resources explaining short position mechanics and risks are integrated into the interface.

  • The interface displays clear warnings explaining:
    • How short positions work (borrow token → sell → buy back cheaper → profit)
    • Liquidation risk: when the token price rises, the position may be liquidated
    • Leverage mechanics and the relationship between collateral and borrowed amount
    • Interest accrual on borrowed assets
  • Risk indicators are color-coded (green for healthy, red for at-risk positions)
  • Position health factor is prominently displayed to help users understand their liquidation proximity

"A tour" of what I accomplished in Milestone 5

Milestone Outputs

Mainnet deployment of the Minswap Lending Market.

  • Mainnet Launch: The unified Long/Short trading interface went live at https://app.minswap.org/margin, making leveraged trading accessible to all Minswap users.
  • Production-Hardened Integration: The backend server, database, and state machine were fully hardened, integrated, and deployed to coordinate mainnet transactions between Minswap DEX V2 and Liqwid V2.

Acceptance Criteria

Users can initiate and manage long/short positions through a single, intuitive interface.

  • Users can open, monitor, and close both leveraged long and short positions directly on Cardano mainnet.
  • Seamless execution of multi-step strategies on mainnet via the automated state machine.

Latest data feeds provide accurate information on asset prices, lending rates, and position health.

  • Verified live mainnet feeds for asset prices (from the Minswap aggregator), lending APYs (from Liqwid V2), and position health factors.

Seamless off-chain integration successfully enables asset supply, borrowing, and purchasing for long/short positions.

  • All state machine transitions (supplying collateral, borrowing, swapping, and repaying) operate successfully under real mainnet conditions.

Backend Infrastructure

The backend is the core new component built for Milestones 3–5. It replaces the POC's client-side logic with a server-side system, hardened and deployed for mainnet production.

API Endpoints

Endpoint Method Description
/health GET Health check
/metadata GET Returns enabled market configs with current Liqwid APY data
/position/get GET Fetch user's open position with live trading metrics
/position/create POST Create a new LONG or SHORT position
/position/build-tx POST Build the next transaction in the position lifecycle
/position/close POST Initiate closing sequence for an open position
/liqwid/submit POST Submit a Liqwid lending transaction to the chain

All POST endpoints require CIP-8 signature authentication — the user signs a message with their wallet to prove ownership, ensuring non-custodial security.

Database Schema

Three tables in PostgreSQL:

  • position — Tracks each position's market, side (LONG/SHORT), status (PENDING → OPEN → CLOSING → CLOSED), collateral amount, and borrow amount.
  • order — Tracks each step in the position lifecycle with its order type, built transaction, on-chain confirmation, and input/output amounts.
  • market_config — Stores market parameters: asset pairs, Liqwid market IDs, qToken mappings, leverage multipliers, and minimum collateral.

State Machine

The state machine orchestrates multi-step leveraged positions automatically:

LONG Opening:  LONG_BUY → LONG_SUPPLY → LONG_BORROW → LONG_BUY_MORE
LONG Closing:  LONG_SELL → LONG_REPAY → LONG_WITHDRAW → LONG_SELL_ALL
SHORT Opening: SHORT_SUPPLY → SHORT_BORROW → SHORT_SELL
SHORT Closing: SHORT_BUY → SHORT_REPAY → SHORT_WITHDRAW

Each order step:

  1. Builds an unsigned transaction (DEX swap or Liqwid lending operation)
  2. Returns it to the frontend for signing
  3. Waits for on-chain confirmation via Cardanoscan
  4. Extracts output amounts and transitions to the next order

Position Metrics (Real-time)

The GET /position/get endpoint returns live trading metrics computed from multiple data sources:

Metric Source Description
entry_price Order history (DB) Weighted average price from BUY/SELL orders
health Liqwid V2 loansForUser Current health factor of the lending position
interest Liqwid V2 loansForUser Accrued borrow interest in lovelace
unrealized_pnl Minswap Aggregator + DB Current value minus cost basis
liq_price Derived from health + price Estimated price at which liquidation occurs

Technical Details

Nitro Wallet

Same non-custodial Nitro Wallet from Milestone 1–2:

  • Private key persists on the user's device only
  • Auto-sign within user-granted scope for seamless multi-step flows
  • No data sent to backend — fully non-custodial

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages