Comprehensive Technical Overview

NLX is a protocol designed to bring Bitcoin-backed perpetual contracts to the blockchain. Its mission is to enhance capital efficiency for Bitcoin holders while maintaining their exposure to BTC. NLX achieves this by:

  1. Enabling Bitcoin holders to earn yields on their BTC without losing directional exposure.
  2. Facilitating on-chain perpetual trading using Bitcoin-based assets as collateral.
  3. Providing simplified and scalable liquidity through Bitcoin-denominated liquidity pools.

These are achieved through a sophisticated system architecture comprising five core components:

  1. Vault
  2. Routers
  3. Price Feeds
  4. NLX Token
  5. NLP Tokens

Each of these components plays a crucial role in creating a seamless, secure, and efficient trading environment. Let’s delve into each component in detail.

Vault: The Core of NLX

The Vault contract is the cornerstone of the NLX protocol, managing deposits, withdrawals, swaps, and trading functions. It’s designed to handle complex operations while maintaining high security standards.

Key features and operations:

Deposits

Users can deposit Bitcoin-based tokens (e.g., WBTC, coreBTC) into the Vault to mint NLP-BTC tokens. For example, if the price of NLP-BTC is 1.50 BTC, a user can mint 1 NLP-BTC by depositing 1.50 WBTC tokens. This process increases the liquidity in the protocol and allows users to start earning yields on their Bitcoin holdings.

Withdrawals

NLP tokens can be burned to withdraw the underlying assets. Following the previous example, if the price of NLP-BTC remains at 1.50 BTC, a user can burn 1 NLP-BTC to redeem 1.50 WBTC tokens. This ensures that users can exit their positions and reclaim their assets when needed.

Swaps

The Vault facilitates exchanges between different Bitcoin-based tokens within the same NLP. For instance, if the price of WBTC is 1 BTC, a user can swap 1 WBTC for 1 coreBTC through the swap function of the Vault. This feature allows for flexibility in managing one’s portfolio.

Trading

The Vault supports both long and short positions using Bitcoin-based assets as collateral. Here’s how it works:

  • Longing: A user can open a long position by depositing Bitcoin-based tokens. For example, a user might deposit 1 WBTC (worth $50,000) into the Vault and open a position of 5 BTC (worth $250,000). This would be a 5x leveraged long position. If the price of BTC increases by 10%, the user would make a profit of 5 BTC * 10% = 0.5 BTC (or $25,000 at the original price).

  • Shorting: A user can open a short position using Bitcoin-based assets as collateral. A user might deposit 1 WBTC and open a short position of 5 BTC. This unique feature allows traders to maintain their Bitcoin exposure even when betting on price decreases.

  • Liquidations: To maintain system solvency, positions can be liquidated by keepers if losses reduce the collateral to the point where position size / remaining collateral exceeds the maximum allowed leverage. This process is automated to ensure the stability of the protocol.

Routers: Streamlining Transactions

The Router contracts in NLX provide essential convenience functions that simplify user interactions with the Vault. These include:

  1. Handling token transfers to the Vault
  2. Managing the wrapping and unwrapping of native tokens
  3. Implementing a sophisticated two-part transaction process for position changes

The PositionRouter contract is particularly crucial in mitigating front-running issues. It employs a two-step process for increasing or decreasing positions:

  1. A user sends a request to increase/decrease a position to the PositionRouter.
  2. A keeper fetches the current index price from an aggregate of exchanges.
  3. The keeper executes the position at the current index price.
  4. If the position cannot be executed within the allowed slippage, the request is cancelled, and funds are returned to the user.

This process significantly reduces the risk of front-running attacks, enhancing the fairness and security of the trading environment. Users can also execute their own positions if three minutes have passed since the initial request, ensuring the protocol remains functional even without active keepers.

Price Feeds: Ensuring Accurate and Fair Pricing

The PriceFeed contract is a critical component of NLX, designed to provide accurate and manipulation-resistant price data. It works as follows:

  1. Price Feed Keeper: Submits prices routinely for swaps.
  2. Position Keeper: Submits prices when executing a position.

The Vault uses the price from the keeper if it’s within a configured percentage of the corresponding Resilient Oracle price. If the price exceeds this threshold, a spread is created between the bounded price and the Resilient Oracle price. This threshold is based on the historical maximum deviation of the Resilient Oracle price from the median price of reference exchanges.

For example, if the maximum deviation is 2.5% and the Resilient Oracle price for BTC is $50,000:

  • If the keeper price is $51,500, the pricing on the Vault would be $50,000 to $51,500.
  • When opening a long position, the higher price ($51,500) is used.
  • When closing a long position, the lower price ($50,000) is used.
  • For short positions, the lower price is used when opening, and the higher price when closing.

Additional safeguards include:

  • Price expiry: Keeper prices expire after five minutes, reverting to Resilient Oracle prices if no update is received.
  • Liquidation constraints: Liquidations can only occur if the Resilient Oracle price reaches the liquidation price for a position.
  • Watcher nodes: These verify that keeper-submitted prices haven’t been tampered with, enforcing spreads if discrepancies are detected.

NLX Token: Governance, Staking and Rewards

The $NLX token serves as the governance token of the protocol. Key features include:

  1. Participation in protocol governance decisions
  2. Staking for rewards
  3. Protocol incentives

NLP Tokens: Bitcoin-Centric Liquidity Provision

NLP (NLX Liquidity Provider) tokens represent shares in asset-specific liquidity pools. Unlike general-purpose liquidity pools, NLX’s NLPs are designed to minimize impermanent loss for liquidity providers while maintaining exposure to Bitcoin. Key characteristics include:

  1. Asset-specific pools: Each NLP is tied to a particular asset class (e.g., NLP-BTC for Bitcoin-based assets).
  2. Price determination: The value of NLP tokens is based on the worth of all tokens within the pool, factoring in the profits and losses of all currently opened positions.
  3. Yield generation: NLP holders earn from trading fees, funding fees, and liquidations.

Key Differentiators and Advanced Features

  1. Bitcoin-Centric Design: NLX is specifically tailored for the Bitcoin ecosystem, allowing for increased capital efficiency while maintaining collateral and earnings in BTC.

  2. Flexible Collateral: Traders can use long-tailed Bitcoin-based assets as collateral for both long and short positions. This reduces the need for stablecoins in the pools and allows traders to maintain their Bitcoin exposure even when shorting.

  3. Advanced Risk Management:

    • Dynamic liquidation thresholds based on position size and market volatility
    • Partial liquidations to allow traders to maintain portions of their positions
    • Liquidation guards to prevent cascading liquidations during extreme market events
  4. Innovative Borrow Rate Mechanism: NLX implements a borrow rate system that helps balance long and short positions while providing additional yield opportunities for NLP holders.

Access Control and Upgradeability

NLX implements a robust access control system to ensure the security and stability of the protocol:

  1. Controller Account: Managed by contributors, it can adjust parameters such as:

    • Swap and margin trading fees (up to a maximum of 5%)
    • Token weights for the NLP pool
    • Maximum allowed leverage
    • Maximum total capacity for long and short positions
  2. Timelock Contract: Controls more significant changes with a 24-hour delay, including:

    • Listing of new tokens
    • Updating the price feed
    • Modifying core contract functionalities
  3. Multi-sig Safety: A multi-signature wallet comprising advisors and community members can override the Timelock admin in case of detected malicious transactions.

While the core logic of NLX contracts cannot be altered, peripheral functions like fee calculations and pricing mechanisms can be updated through a carefully controlled process.

Advanced Attack Mitigations

  1. Front-Running Protection:

    • Two-step transaction process for position changes
    • Frequent price feed updates (within 0.12% price movements)
    • Base swap fee of 0.25% to discourage small-margin front-running attempts
  2. Flash Loan Attack Prevention:

    • Use of oracle prices for key operations, making them independent of pool composition
    • Dynamic fees for swaps based on pool composition, preventing positive slippage exploitation
  3. Oracle Manipulation Resistance:

    • Multiple price sources (keeper, Resilient Oracle, reference exchanges)
    • Spread enforcement and cumulative delta checks

By combining these advanced features and security measures, NLX aims to provide a robust, efficient, and secure platform for Bitcoin-backed perpetual trading, pushing the boundaries of what’s possible in decentralized finance while maintaining a strong focus on the Bitcoin ecosystem.