Set up the Exponent SDK and walk through the main tranching lifecycle - loading a market, depositing into Senior or Junior, withdrawing, and reading market state.
Installation
yarn add @exponent-labs/exponent-sdk
Setup
import {
LOCAL_ENV,
TranchingMarket,
} from "@exponent-labs/exponent-sdk";
import { TrancheSide } from "@exponent-labs/exponent-sdk/client/tranching";
import {
Connection,
Keypair,
PublicKey,
Transaction,
sendAndConfirmTransaction,
} from "@solana/web3.js";
const connection = new Connection("https://api.mainnet-beta.solana.com");
const wallet = Keypair.fromSecretKey(/* your keypair */);
const marketAddress = new PublicKey("...");
// Loads onchain market state, return model storage, SY linkage, and tranche LP mints.
const market = await TranchingMarket.load(connection, marketAddress, LOCAL_ENV);
Amount inputs use raw token units. amountBase uses the base token’s smallest units, amountIn uses SY token units, and LP amounts use tranche LP token units. APY inputs use decimal rates, so 0.10 means 10%.
Choose a tranche
Use TrancheSide.Senior for protected exposure and TrancheSide.Junior for first-loss exposure with higher expected return.const trancheSide = TrancheSide.Senior;
Deposit base assets
Use ixWrapperDeposit to deposit the market’s base asset. The wrapper mints SY first, deposits SY into the selected tranche, and mints Senior or Junior LP shares.const { ixs, setupIxs } = await market.ixWrapperDeposit({
user: wallet.publicKey,
trancheSide: TrancheSide.Senior,
amountBase: 1_000_000_000n, // raw base-token units; for 9 decimals, this is 1 token
minLpOut: 0n, // raw Senior LP units; set above 0 for output protection
});
const tx = new Transaction().add(...setupIxs, ...ixs);
await sendAndConfirmTransaction(connection, tx, [wallet]);
Set minLpOut to protect against stale exchange-rate or NAV assumptions. The transaction reverts if LP output is below that value.
Deposit into Junior
Junior deposits use the same wrapper with TrancheSide.Junior.const { ixs, setupIxs } = await market.ixWrapperDeposit({
user: wallet.publicKey,
trancheSide: TrancheSide.Junior,
amountBase: 1_000_000_000n, // raw base-token units
minLpOut: 0n, // raw Junior LP units
});
const tx = new Transaction().add(...setupIxs, ...ixs);
await sendAndConfirmTransaction(connection, tx, [wallet]);
Withdraw to base assets
Use ixWrapperWithdraw to burn tranche LP shares, withdraw SY from the market, and redeem SY back to the base asset.const { ixs, setupIxs } = await market.ixWrapperWithdraw({
user: wallet.publicKey,
trancheSide: TrancheSide.Senior,
lpAmountIn: 500_000_000n, // raw Senior LP units to burn
minBaseOut: 0n, // raw base-token units; set above 0 for output protection
});
const tx = new Transaction().add(...setupIxs, ...ixs);
await sendAndConfirmTransaction(connection, tx, [wallet]);
Senior withdrawals are only allowed while the market is Active. During FixedTermRecovery, Senior withdrawals are paused.
Read market state
Use read helpers to inspect current NAV, LP prices, capacity, APY, and Senior protection before sending transactions.console.log("Market size:", market.getMarketSize());
console.log("Effective market size:", market.getEffectiveMarketSize());
console.log("Senior LP price:", market.getSrLpPriceNetAsset());
console.log("Junior LP price:", market.getJrLpPriceNetAsset());
console.log("Target coverage:", market.getTargetCoverageRatio());
const seniorApy = market.calculateSeniorApy(0.10); // 0.10 = 10% underlying APY
const juniorApy = market.calculateJuniorApy(0.10);
console.log("Senior APY:", seniorApy);
console.log("Junior APY:", juniorApy);
SY-only instructions
If you already hold SY, use ixDeposit and ixWithdraw instead of the wrappers. These methods skip base asset minting and redemption.
const ix = market.ixDeposit({
user: wallet.publicKey,
trancheSide: TrancheSide.Senior,
amountIn: 1_000_000_000n, // raw SY units
minLpOut: 0n, // raw Senior LP units
tokenSrc: userSyTokenAccount,
tokenLpDst: userSeniorLpTokenAccount,
});
Next Steps
Technical Concepts
Understand coverage, utilization, return curves, recovery periods, and LP pricing.
TypeScript Instructions
Explore high-level deposit and withdraw builders.
Read Functions
Query NAV, capacity, APY, and Senior protection without submitting transactions.
Account References
Inspect the market account, return model storage, risk config, and fee config.