JSPM

  • Created
  • Published
  • Downloads 330
  • Score
    100M100P100Q79123F
  • License MIT

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@reflectmoney/stable.ts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Reflect Money SDK

    A TypeScript SDK for interacting with the Reflect programs on Solana. This SDK provides high-level abstractions for minting, redeeming, and managing stablecoins, administrative operations, and protocol integrations.

    Installation

    npm install @reflectmoney/stable.ts
    # or
    yarn add @reflectmoney/stable.ts

    Overview

    The Reflect SDK enables developers to interact with the protocol via three main Reflect stablecoins:

    1. USDC+ (Index 0): Stablecoin backed by USDC deployed in various money markets
    2. JLP Hedged (Index 1): Stablecoin backed by the JLP token, neutralized with perpetual hedging strategies
    3. LST Delta-Neutral (Index 2): Stablecoin backed by LSTs hedged by perpetual futures positions

    Architecture

    The SDK is organized into several key components:

    Core Classes

    Stablecoin (Abstract Base Class)

    The foundation for all stablecoin implementations. Provides abstract functions and a common interface for:

    • Minting
    • Redemption
    • Administrative operations

    Key Methods:

    • mint() - Create mint instructions
    • redeem() - Create redemption instructions
    • rebalance() - Create rebalance instructions (admin-only or permissionless, depending on the strategy)

    ReflectKeeper

    Administrative client for protocol-level operations (admin-only).

    PdaClient

    Utility class for deriving PDAs:

    • Configuration program accounts
    • Stablecoin controllers
    • Permission accounts
    • External protocol integrations (Drift, Jupiter, Tokenized Bond)

    ReflectTokenizedBond

    Client for the tokenized bonds program used for wrapping base stablecoins into yield-bearing receipts. Allows for:

    • Vault creation and management
    • Receipt token generation
    • Deposit and withdrawal operations

    Stablecoin Implementations

    UsdcPlusStablecoin

    USDC+ is a stablecoin backed by USDC deployed in money markets. Implementation details:

    • Status: Live
    • Strategy ID: 0
    • Collateral: USDC
    • Integrated with the tokenized bonds program at the protocol level
    • Users only receive the yield-bearing stablecoin
    • Does not require rebalancing

    UsdjStablecoin

    Stablecoin backed by JLP neutralized with perpetual hedging:

    • Status: Coming soon
    • Strategy ID: 1
    • Collateral: JLP (Jupiter LP tokens)
    • Requires manual wrapping via the Tokenized Bonds program
    • Requires rebalancing, currently permissioned

    LstStablecoin

    Liquid staking token delta-neutral strategy:

    • Status: Live
    • Strategy ID: 2
    • Collateral: Various LSTs (mSOL, jitoSOL, etc.) - use load() functionality to fetch the currently supported list of collateral assets
    • Requires manual wrapping via the Tokenized Bonds program
    • Requires rebalancing, currently permissioned

    Usage

    Follow the snippets below to mint and redeem Reflect stablecoins. All Stablecoin subclasses expose methods following the same schema, so the code below works interchangeably with minor changes - simply change between the three:

    const stablecoin = new UsdcPlusStablecoin(connection);
    const stablecoin = new UsdjStablecoin(connection);
    const stablecoin = new LstStablecoin(connection);

    Minting Stablecoins

    import { UsdcPlusStablecoin } from '@reflectmoney/stable.ts';
    import { PublicKey, Keypair, Connection, TransactionMessage, VersionedTransaction } from '@solana/web3.js';
    import BN from 'bn.js';
    
    // Use an actual user's public key, read from wallet adapter or local environment.
    const user = Keypair.generate();
    const stablecoin = new UsdcPlusStablecoin(connection);
    
    // Load controller data for the most up-to-date stablecoin setup.
    await stablecoin.load(connection);
    
    // Mint stablecoins against USDC collateral
    const instructions = await stablecoin.mint(
        user.publicKey,
        new BN(1000 * 1_000_000), // Deposit collateral of 1,000 USDC (6 decimals)
        new BN(999 * 1_000_000),  // Minimum received USDC+ (0.1% slippage protection)
    );
    
    const { blockhash } = await connection.getLatestBlockhash();
    
    const {
        value: lookupTable
    } = await connection.getAddressLookupTable(
        stablecoin.lookupTable
    );
    
    const message = new TransactionMessage({
        instructions,
        payerKey: user.publicKey,
        recentBlockhash: blockhash
    }).compileToV0Message([lookupTable]);
    
    const transaction = new VersionedTransaction(message);
    
    // Transaction signature and confirmation logic, adjust for your needs.
    transaction.sign([user]);
    await connection.sendRawTransaction(transaction.serialize());

    Redeeming Stablecoins

    import { UsdcPlusStablecoin } from '@reflectmoney/stable.ts';
    import { PublicKey, Keypair, Connection, TransactionMessage, VersionedTransaction } from '@solana/web3.js';
    import BN from 'bn.js';
    
    // Use an actual user's public key, read from wallet adapter or local environment.
    const user = Keypair.generate();
    const stablecoin = new UsdcPlusStablecoin(connection);
    
    // Load controller data for the most up-to-date stablecoin setup.
    await stablecoin.load(connection);
    
    // Redeem USDC+ into USDC
    const instructions = await stablecoin.redeem(
        user.publicKey,
        new BN(999 * 1_000_000), // Burn 999 of USDC+
        new BN(1_000 * 1_000_000),  // Minimum received USDC (USDC+ is yield bearing, so you'll receive more USDC over time)
    );
    
    const { blockhash } = await connection.getLatestBlockhash();
    
    const {
        value: lookupTable
    } = await connection.getAddressLookupTable(
        stablecoin.lookupTable
    );
    
    const message = new TransactionMessage({
        instructions,
        payerKey: user.publicKey,
        recentBlockhash: blockhash
    }).compileToV0Message([lookupTable]);
    
    const transaction = new VersionedTransaction(message);
    
    // Transaction signature and confirmation logic, adjust for your needs.
    transaction.sign([user]);
    await connection.sendRawTransaction(transaction.serialize());

    Integration with External Protocols

    The SDK is built with integration for:

    • Drift Protocol: For perpetual futures and spot trading
    • Jupiter Protocol: For LP token operations and swaps
    • Pyth Network: For price oracle data
    • Tokenized Bonds: For yield generation

    License

    This SDK is licensed under the MIT License.

    Support

    For support and questions: