Documentation Index
Fetch the complete documentation index at: https://docs.radixagent.com/llms.txt
Use this file to discover all available pages before exploring further.
DeFi
Class for managing DeFi operations including staking, Ociswap liquidity pools, swaps, and advanced features like flash loans and hooked pools.
Constructor
new DeFi(
transactionBuilder: RadixTransactionBuilder,
gatewayClient: RadixGatewayClient,
networkId: number
)
Staking Operations
stakeXRD()
Stake XRD with validators.
async stakeXRD(
options: StakeXRDOptions,
wallet: RadixWallet,
currentEpoch: number
): Promise<string>
Parameters:
interface StakeXRDOptions {
ownerAddress: string;
validatorAddress: string;
amount: number | string;
}
Example:
const txHash = await defi.stakeXRD({
ownerAddress: "account_tdx_2_1...",
validatorAddress: "validator_tdx_2_1s...",
amount: "1000"
}, wallet, currentEpoch);
unstakeXRD()
Unstake XRD from validators.
async unstakeXRD(
options: UnstakeXRDOptions,
wallet: RadixWallet,
currentEpoch: number
): Promise<string>
claimXRD()
Claim unstaked XRD from validators using stake claim NFTs.
async claimXRD(
options: ClaimXRDOptions,
wallet: RadixWallet,
currentEpoch: number
): Promise<string>
Ociswap Pool Operations
createTwoResourcePool()
Create a new two-resource pool using Ociswap Pool V2 with advanced features.
async createTwoResourcePool(
options: CreatePoolOptions,
wallet: RadixWallet,
currentEpoch: number
): Promise<{ txHash: string; poolAddress?: string }>
Parameters:
interface CreatePoolOptions {
ownerAddress: string;
resourceAddress1: string;
resourceAddress2: string;
amount1: number | string;
amount2: number | string;
feeTier?: 1 | 5 | 30 | 100; // 0.01%, 0.05%, 0.3%, 1%
assetRatio?: [number, number]; // e.g., [20, 80] for imbalanced pools
hookAddress?: string; // For hooked pools
poolName?: string;
poolSymbol?: string;
}
Example:
// Standard balanced pool
const result = await defi.createTwoResourcePool({
ownerAddress: "account_tdx_2_1...",
resourceAddress1: "resource_tdx_2_1t...",
resourceAddress2: "resource_tdx_2_1n...",
amount1: "10000",
amount2: "20000",
feeTier: 30, // 0.3% fee
poolName: "XRD-TOKEN Pool",
poolSymbol: "XRD-TKN"
}, wallet, currentEpoch);
// Imbalanced pool (80/20)
const imbalancedPool = await defi.createTwoResourcePool({
ownerAddress: "account_tdx_2_1...",
resourceAddress1: "resource_tdx_2_1t...",
resourceAddress2: "resource_tdx_2_1n...",
amount1: "8000",
amount2: "2000",
feeTier: 30,
assetRatio: [80, 20]
}, wallet, currentEpoch);
// Hooked pool with custom logic
const hookedPool = await defi.createTwoResourcePool({
ownerAddress: "account_tdx_2_1...",
resourceAddress1: "resource_tdx_2_1t...",
resourceAddress2: "resource_tdx_2_1n...",
amount1: "10000",
amount2: "20000",
feeTier: 30,
hookAddress: "component_tdx_2_1hook..."
}, wallet, currentEpoch);
Ociswap Availability: Pool creation is only available on Radix Mainnet. For Stokenet testing, deploy your own pool blueprint.
addLiquidity()
Add liquidity to Ociswap pools with automatic ratio calculation.
async addLiquidity(
options: AddLiquidityOptions,
wallet: RadixWallet,
currentEpoch: number
): Promise<string>
Parameters:
interface AddLiquidityOptions {
ownerAddress: string;
poolAddress: string;
amounts: [number | string, number | string];
minAmounts?: [number | string, number | string]; // Slippage protection
}
Example:
const txHash = await defi.addLiquidity({
ownerAddress: "account_tdx_2_1...",
poolAddress: "component_tdx_2_1c...",
amounts: ["1000", "2000"],
minAmounts: ["990", "1980"] // Allow 1% slippage
}, wallet, currentEpoch);
removeLiquidity()
Remove liquidity from Ociswap pools by burning LP tokens.
async removeLiquidity(
options: RemoveLiquidityOptions,
wallet: RadixWallet,
currentEpoch: number
): Promise<string>
Parameters:
interface RemoveLiquidityOptions {
ownerAddress: string;
poolAddress: string;
amountLP: number | string;
minAmounts?: [number | string, number | string]; // Slippage protection
}
Example:
const txHash = await defi.removeLiquidity({
ownerAddress: "account_tdx_2_1...",
poolAddress: "component_tdx_2_1c...",
amountLP: "100",
minAmounts: ["980", "1960"] // Minimum expected outputs
}, wallet, currentEpoch);
swapTokens()
Swap tokens through Ociswap pools with slippage protection.
async swapTokens(
options: SwapTokensOptions,
wallet: RadixWallet,
currentEpoch: number
): Promise<string>
Parameters:
interface SwapTokensOptions {
ownerAddress: string;
poolAddress: string;
fromResourceAddress: string;
toResourceAddress: string;
amountIn: number | string;
minAmountOut?: number | string; // Slippage protection
}
Example:
const txHash = await defi.swapTokens({
ownerAddress: "account_tdx_2_1...",
poolAddress: "component_tdx_2_1c...",
fromResourceAddress: "resource_tdx_2_1t...",
toResourceAddress: "resource_tdx_2_1n...",
amountIn: "100",
minAmountOut: "95" // Max 5% slippage
}, wallet, currentEpoch);
Advanced DeFi Features
executeFlashLoan()
Execute flash loans from Ociswap Pool V2.
async executeFlashLoan(
options: FlashLoanOptions,
wallet: RadixWallet,
currentEpoch: number
): Promise<string>
Parameters:
interface FlashLoanOptions {
ownerAddress: string;
poolAddress: string;
resourceAddress: string;
amount: number | string;
callbackComponentAddress: string;
callbackData?: string;
}
Example:
const txHash = await defi.executeFlashLoan({
ownerAddress: "account_tdx_2_1...",
poolAddress: "component_tdx_2_1c...",
resourceAddress: "resource_tdx_2_1t...",
amount: "10000",
callbackComponentAddress: "component_tdx_2_1callback...",
callbackData: "0x1234..." // Optional callback data
}, wallet, currentEpoch);
getPoolInfo()
Get enhanced information about Ociswap Pool V2 pools.
async getPoolInfo(poolAddress: string): Promise<PoolInfo>
Returns:
interface PoolInfo {
poolAddress: string;
resource1: string;
resource2: string;
reserves: [string, string];
totalSupply: string;
feeTier: number;
assetRatio?: [number, number];
hookAddress?: string;
poolType: "standard" | "precision" | "hooked";
autoCompounding: boolean;
flashLoansEnabled: boolean;
}
Example:
const poolInfo = await defi.getPoolInfo("component_tdx_2_1c...");
console.log("Pool type:", poolInfo.poolType);
console.log("Reserves:", poolInfo.reserves);
console.log("Fee tier:", poolInfo.feeTier / 100, "%");
console.log("Flash loans enabled:", poolInfo.flashLoansEnabled);
findPools()
Find available pools for a resource pair.
async findPools(
resource1: string,
resource2: string
): Promise<string[]>
Example:
const pools = await defi.findPools(
"resource_tdx_2_1t...",
"resource_tdx_2_1n..."
);
console.log("Available pools:", pools);
Ociswap Pool V2 Features:
- Multiple fee tiers: 0.01%, 0.05%, 0.3%, 1%
- Imbalanced pools: Custom asset ratios (e.g., 80/20)
- Hooked pools: Custom logic via hook components
- Flash loans: Borrow and repay in single transaction
- Auto-compounding: Automatic fee reinvestment
- NFT LP positions: Enhanced position tracking
Network Limitations: Ociswap is currently only available on Radix Mainnet. For Stokenet testing, deploy your own pool blueprint or use SimplePool.