A TypeScript SDK for directly accessing Flux Protocol data from the Radix blockchain. This package provides a clean, type-safe interface for fetching protocol information without needing to rely on API endpoints.
npm install flux-protocol-sdkimport { FluxDataClient, collaterals } from "flux-protocol-sdk";
const client = new FluxDataClient();
// Get current prices
const prices = await client.getPrices();
console.log(`XRD: $${prices.xrdPrice}`);
// Get protocol statistics
const stats = await client.getProtocolStats();
console.log(`TVL: $${stats.totalValueLocked}`);Fetch data directly from the Radix Gateway and external sources - no API dependencies.
- Price data (XRD/LSULP with oracle messages)
- Protocol statistics (TVL, debt, collateralization)
- CDP operations and management
- Interest rate calculations
- Stability pool operations
- Transaction manifest generation
Full TypeScript support with comprehensive type definitions.
import { FluxDataClient } from "flux-protocol-sdk";
import { RadixNetwork } from "@radixdlt/babylon-gateway-api-sdk";
// For Stokenet (default)
const client = new FluxDataClient();
// For Mainnet
const mainnetClient = new FluxDataClient(RadixNetwork.Mainnet);// Get current prices with oracle message
const prices = await client.getPrices();
console.log(prices);
// Returns:
// {
// xrdPrice: 0.0456,
// lsulpPrice: 0.0410,
// oracleMessage: ["0x123...", "0x456..."] // or null if no message
// }// Get comprehensive protocol data
const stats = await client.getProtocolStats();
console.log(stats);
// Returns:
// {
// totalValueLocked: 1500000.50,
// totalDebt: 750000.25,
// totalDebtByCollateral: {
// xrd: 500000.15,
// lsulp: 250000.10
// },
// circulatingFusd: 750000.25,
// averageInterestRates: {
// xrd: 5.75,
// lsulp: 6.20
// },
// activeInterestRates: 35,
// collateralizationRatio: 200.00
// }// Get CDP information
const cdpData = await client.getCdpsInfo(["#1#", "#2#"]);
console.log(cdpData);
// Returns:
// {
// translatedCdpsData: [
// {
// id: '#1#',
// collateral: 'resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc',
// debt: 130.79868425583456,
// collateralAmount: 86262.2869049716,
// interestRate: 0.348,
// state: 'healthy'
// },
// {
// id: '#2#',
// collateral: 'resource_tdx_2_1tka404jaaw7kvtdq6ngj93eycnvscymfalctrehflvpjscfrqrlv5d',
// debt: 75.50,
// collateralAmount: 50000.00,
// interestRate: 0.352,
// state: 'healthy'
// }
// ]
// }
// Get historical CDP data with state version
const historicalData = await client.getCdpsInfo(["#1#"], 205725151);
// Returns same structure as above but with data from the specified state versionimport { collaterals } from "flux-protocol-sdk";
// Get interest rate information
const xrdRates = await client.getInterestInfos(
collaterals.xrd.collateralAddress
);
console.log(xrdRates);
// Returns:
// {
// interests: [
// [0.348, 500000.00], // [interest rate, debt amount]
// [0.352, 250000.00],
// [0.355, 100000.00]
// ],
// averageApr: 0.350,
// averageApy: 0.419,
// average7DayYield: 0.0067
// }
// Get collateral debt information
const collateralInfo = await client.getCollateralInfos([
collaterals.xrd.collateralAddress,
collaterals.lsulp.collateralAddress,
]);
console.log(collateralInfo);
// Returns:
// {
// xrd: {
// totalDebt: 500000.15,
// totalCollateral: 1000000.30
// },
// lsulp: {
// totalDebt: 250000.10,
// totalCollateral: 500000.20
// }
// }
// Get redemption risk interest data
const redemptionRisk = await client.getRedemptionRiskInterest(
collaterals.xrd.collateralAddress,
20, // percentage before
1000 // additional debt (optional)
);
console.log(redemptionRisk);
// Returns:
// {
// riskLevel: 'medium',
// amountInFront: 150000.00,
// percentageInFront: 0.15
// }// Get reservoir information
const reservoirData = await client.getReservoirDetails(
collaterals.xrd.collateralAddress,
12345678 // optional state version
);
console.log(reservoirData);
// Returns:
// {
// poolSize: 1000000.00,
// userDeposit: 50000.00,
// userShare: 0.05,
// totalEarnings: 2500.00,
// userEarnings: 125.00
// }
// Get APR information
const aprData = await client.getReservoirApr(collaterals.xrd.collateralAddress);
console.log(aprData);
// Returns:
// {
// apr: 5.75,
// apy: 5.92,
// dailyRate: 0.0157
// }// Generate borrow transaction
const borrowTx = await client.getBorrowManifest({
collateralAddress: collaterals.xrd.collateralAddress,
collateralAmount: 1000,
ltv: 80, // 80% loan-to-value
interestRate: 5, // 5% annual interest
accountAddress: "account_tdx_...",
redemptionOptOut: false, // optional
});
console.log(borrowTx);
// Returns:
// {
// manifest: "CALL_METHOD...",
// message: "Borrow fUSD against XRD collateral"
// }
// Generate close position transaction
const closeTx = await client.getCloseManifest({
nftId: "#1#",
accountAddress: "account_tdx_...",
});
console.log(closeTx);
// Returns:
// {
// manifest: "CALL_METHOD...",
// message: "Close CDP position"
// }
// Generate stability pool deposit
const depositTx = await client.getReservoirDepositManifest({
collateralAddress: collaterals.xrd.collateralAddress,
amount: 1000,
accountAddress: "account_tdx_...",
});
console.log(depositTx);
// Returns:
// {
// manifest: "CALL_METHOD...",
// message: "Deposit to stability pool"
// }
// Generate stability pool withdrawal
const withdrawTx = await client.getReservoirWithdrawManifest({
collateralAddress: collaterals.xrd.collateralAddress,
amount: 500,
accountAddress: "account_tdx_...",
});
console.log(withdrawTx);
// Returns:
// {
// manifest: "CALL_METHOD...",
// message: "Withdraw from stability pool"
// }// Access individual modules for specialized operations
const client = new FluxDataClient();
// Price module
const priceModule = client.prices;
const currentPrices = await priceModule.getPrices();
// Returns same structure as client.getPrices()
// CDP module with advanced filtering
const cdpModule = client.cdps;
const sortedCdps = await cdpModule.getCdpsSortedByInterest(
["#1#", "#2#"],
true
);
// Returns same structure as client.getCdpsInfo() but sorted by interest rate
// Interest rate module
const interestModule = client.interestRates;
const interestInfo = await interestModule.getInterestInfos(
collaterals.xrd.collateralAddress
);
// Returns same structure as client.getInterestInfos()
// Reservoir module
const reservoirModule = client.reservoir;
const reservoirDetails = await reservoirModule.getReservoirDetails(
collaterals.xrd.collateralAddress
);
// Returns same structure as client.getReservoirDetails()
// Transaction module
const transactionModule = client.transactions;
const borrowManifest = await transactionModule.getBorrowManifest({
collateralAddress: collaterals.xrd.collateralAddress,
collateralAmount: 1000,
ltv: 80,
accountAddress: "account_tdx_...",
interestRate: 5,
});
// Returns same structure as client.getBorrowManifest()import { FluxError } from "flux-protocol-sdk";
try {
const prices = await client.getPrices();
} catch (error) {
if (error instanceof FluxError) {
console.log("Flux Error:", error.message);
if (error.statusCode) {
console.log("Status Code:", error.statusCode);
}
}
}getPrices()- Get current XRD and LSULP pricesgetProtocolStats()- Get protocol statisticsgetCdpsInfo(nftIds, stateVersion?)- Get CDP informationgetInterestInfos(collateralAddress)- Get interest ratesgetCollateralInfos(addresses)- Get collateral debt datagetRedemptionRiskInterest(collateralAddress, percentageBefore, additionalDebt?)- Get redemption risk datagetReservoirApr(collateralAddress)- Get stability pool APRgetReservoirDetails(collateralAddress, stateVersion?)- Get pool details
getBorrowManifest(borrowData)- Generate borrow transactiongetCloseManifest(closeData)- Generate close transactiongetReservoirDepositManifest(depositData)- Generate deposit transactiongetReservoirWithdrawManifest(withdrawData)- Generate withdraw transaction
client.prices- Price moduleclient.protocolStats- Protocol statistics moduleclient.cdps- CDP operations moduleclient.interestRates- Interest rate moduleclient.reservoir- Stability pool moduleclient.transactions- Transaction generation moduleclient.gateway- Direct Radix Gateway access
MIT