Complete API reference for DeFi operations including Ociswap Pool V2
new DeFi( transactionBuilder: RadixTransactionBuilder, gatewayClient: RadixGatewayClient, networkId: number )
async stakeXRD( options: StakeXRDOptions, wallet: RadixWallet, currentEpoch: number ): Promise<string>
interface StakeXRDOptions { ownerAddress: string; validatorAddress: string; amount: number | string; }
const txHash = await defi.stakeXRD({ ownerAddress: "account_tdx_2_1...", validatorAddress: "validator_tdx_2_1s...", amount: "1000" }, wallet, currentEpoch);
async unstakeXRD( options: UnstakeXRDOptions, wallet: RadixWallet, currentEpoch: number ): Promise<string>
async claimXRD( options: ClaimXRDOptions, wallet: RadixWallet, currentEpoch: number ): Promise<string>
async createTwoResourcePool( options: CreatePoolOptions, wallet: RadixWallet, currentEpoch: number ): Promise<{ txHash: string; poolAddress?: string }>
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; }
// 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);
async addLiquidity( options: AddLiquidityOptions, wallet: RadixWallet, currentEpoch: number ): Promise<string>
interface AddLiquidityOptions { ownerAddress: string; poolAddress: string; amounts: [number | string, number | string]; minAmounts?: [number | string, number | string]; // Slippage protection }
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);
async removeLiquidity( options: RemoveLiquidityOptions, wallet: RadixWallet, currentEpoch: number ): Promise<string>
interface RemoveLiquidityOptions { ownerAddress: string; poolAddress: string; amountLP: number | string; minAmounts?: [number | string, number | string]; // Slippage protection }
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);
async swapTokens( options: SwapTokensOptions, wallet: RadixWallet, currentEpoch: number ): Promise<string>
interface SwapTokensOptions { ownerAddress: string; poolAddress: string; fromResourceAddress: string; toResourceAddress: string; amountIn: number | string; minAmountOut?: number | string; // Slippage protection }
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);
async executeFlashLoan( options: FlashLoanOptions, wallet: RadixWallet, currentEpoch: number ): Promise<string>
interface FlashLoanOptions { ownerAddress: string; poolAddress: string; resourceAddress: string; amount: number | string; callbackComponentAddress: string; callbackData?: string; }
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);
async getPoolInfo(poolAddress: string): Promise<PoolInfo>
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; }
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);
async findPools( resource1: string, resource2: string ): Promise<string[]>
const pools = await defi.findPools( "resource_tdx_2_1t...", "resource_tdx_2_1n..." ); console.log("Available pools:", pools);