UNPKG

@defindex/sdk

Version:

Official TypeScript SDK for DeFindex API

426 lines 19.2 kB
import { CreateDefindexVault, CreateDefindexVaultDepositDto, CreateVaultAutoInvestParams, CreateVaultAutoInvestResponse, CreateVaultDepositResponse, CreateVaultResponse, DepositToVaultParams, DistributeFeesParams, FactoryAddressResponse, LaunchTubeResponse, LockFeesParams, PauseStrategyParams, RebalanceParams, ReleaseFeesParams, RescueFromVaultParams, SendTransactionResponse, SetVaultRoleParams, SupportedNetworks, UnpauseStrategyParams, UpgradeWasmParams, VaultApyResponse, VaultBalanceResponse, VaultInfoResponse, VaultRoleResponse, VaultRoles, VaultTransactionResponse, WithdrawParams, WithdrawSharesParams } from './types'; /** * Configuration options for the DeFindex SDK */ export interface DefindexSDKConfig { apiKey?: string; /** Custom API base URL (defaults to 'https://api.defindex.io') */ baseUrl?: string; /** Request timeout in milliseconds (defaults to 30000) */ timeout?: number; /** Default network for all operations (can be overridden per method call) */ defaultNetwork?: SupportedNetworks; } /** * DeFindex SDK - TypeScript client for DeFindex API * * @example * ```typescript * // Basic initialization with default network * const sdk = new DefindexSDK({ * baseUrl: 'https://api.defindex.io', * defaultNetwork: SupportedNetworks.TESTNET * }); * * // With API key authentication * const sdk = new DefindexSDK({ * apiKey: 'sk_your_api_key_here', * baseUrl: 'https://api.defindex.io', * defaultNetwork: SupportedNetworks.MAINNET * }); * * // Now you can call methods without specifying network * const vaultInfo = await sdk.getVaultInfo('CVAULT...'); * * // Or override for a specific call * const testnetInfo = await sdk.getVaultInfo('CVAULT...', SupportedNetworks.TESTNET); * ``` */ export declare class DefindexSDK { private httpClient; private config; private defaultNetwork?; /** * Create a new DeFindex SDK instance * @param config - SDK configuration options */ constructor(config: DefindexSDKConfig); /** * Get the network to use for a request * @param network - Optional network override * @returns The network to use (provided network or default) * @throws Error if no network is provided and no default is set */ private getNetwork; /** * Get the current default network * @returns The default network or undefined if not set */ getDefaultNetwork(): SupportedNetworks | undefined; /** * Set the default network for all operations * @param network - The network to use as default */ setDefaultNetwork(network: SupportedNetworks): void; /** * Check API health status * @returns Health status information * @example * ```typescript * const health = await sdk.healthCheck(); * if (health.status.reachable) { * console.log('API is healthy'); * } * ``` */ healthCheck(): Promise<any>; /** * Get the factory contract address for a specific network * @param network - Stellar network (optional, uses default if not specified) * @returns Factory contract address * @example * ```typescript * const factory = await sdk.getFactoryAddress(); * console.log('Factory address:', factory.address); * ``` */ getFactoryAddress(network?: SupportedNetworks): Promise<FactoryAddressResponse>; /** * Create a new vault (requires Vault Manager role) * @param vaultConfig - Vault configuration including assets, fees, and roles * @param network - Stellar network (optional, uses default if not specified) * @returns Transaction XDR for vault creation * @example * ```typescript * const vaultConfig = { * roles: { "0": "GMANAGER...", "1": "CFEE..." }, * vault_fee_bps: 100, // 1% * assets: [{ address: "CASSET...", strategies: [...] }], * name_symbol: { name: "My Vault", symbol: "MVLT" }, * upgradable: true, * caller: "GCALLER..." * }; * const response = await sdk.createVault(vaultConfig); * ``` */ createVault(vaultConfig: CreateDefindexVault, network?: SupportedNetworks): Promise<CreateVaultResponse>; /** * Create a new vault with initial deposit in a single transaction * @param vaultConfig - Vault configuration with initial deposit amounts * @param network - Stellar network (optional, uses default if not specified) * @returns Transaction XDR for vault creation and deposit * @example * ```typescript * const vaultConfig = { * // ... vault config * deposit_amounts: [1000000, 2000000] // Initial deposit amounts * }; * const response = await sdk.createVaultWithDeposit(vaultConfig); * ``` */ createVaultWithDeposit(vaultConfig: CreateDefindexVaultDepositDto, network?: SupportedNetworks): Promise<CreateVaultDepositResponse>; /** * Create a new vault with auto-invest in a single atomic transaction * * This endpoint creates a batched transaction that: * 1. Creates the vault with initial deposit * 2. Invests funds in specified strategies (rebalance) * 3. Changes manager to the final address * * All operations are atomic - either all succeed or all fail. * * @param params - Auto-invest vault configuration with asset allocations and strategies * @param network - Stellar network (optional, uses default if not specified) * @returns Transaction XDR, predicted vault address, and warning about address prediction * @example * ```typescript * const params = { * caller: 'GCALLER...', * roles: { * emergencyManager: 'GEMERGENCY...', * rebalanceManager: 'GREBALANCE...', * feeReceiver: 'GFEE...', * manager: 'GMANAGER...' * }, * name: 'My Auto-Invest Vault', * symbol: 'MAIV', * vaultFee: 10, // 0.1% in basis points * upgradable: true, * assets: [{ * address: 'CASSET...', * symbol: 'XLM', * amount: 2000000000, // 200 XLM in stroops * strategies: [ * { address: 'CSTRAT1...', name: 'hodl_strategy', amount: 1000000000 }, * { address: 'CSTRAT2...', name: 'yield_strategy', amount: 1000000000 } * ] * }] * }; * const response = await sdk.createVaultAutoInvest(params); * console.log('Sign this XDR:', response.xdr); * console.log('Predicted vault address:', response.predictedVaultAddress); * ``` */ createVaultAutoInvest(params: CreateVaultAutoInvestParams, network?: SupportedNetworks): Promise<CreateVaultAutoInvestResponse>; /** * Get comprehensive vault information * @param vaultAddress - The vault contract address * @param network - Stellar network (optional, uses default if not specified) * @returns Vault metadata, assets, strategies, and TVL information * @example * ```typescript * const vaultInfo = await sdk.getVaultInfo('CVAULT...'); * console.log(`Vault: ${vaultInfo.name} (${vaultInfo.symbol})`); * console.log(`Total Assets: ${vaultInfo.totalAssets}`); * ``` */ getVaultInfo(vaultAddress: string, network?: SupportedNetworks): Promise<VaultInfoResponse>; /** * Get user's vault balance and shares * @param vaultAddress - The vault contract address * @param userAddress - User's wallet address * @param network - Stellar network (optional, uses default if not specified) * @returns User's vault shares and underlying asset values * @example * ```typescript * const balance = await sdk.getVaultBalance('CVAULT...', 'GUSER...'); * console.log(`Shares: ${balance.dfTokens}`); * console.log(`Underlying values: ${balance.underlyingBalance}`); * ``` */ getVaultBalance(vaultAddress: string, userAddress: string, network?: SupportedNetworks): Promise<VaultBalanceResponse>; /** * Get vault report with transaction details * @param vaultAddress - The vault contract address * @param network - Stellar network (optional, uses default if not specified) * @returns Vault report with transaction XDR and simulation response * @example * ```typescript * const report = await sdk.getReport('CVAULT...'); * console.log(`Report XDR: ${report.xdr}`); * ``` */ getReport(vaultAddress: string, network?: SupportedNetworks): Promise<VaultTransactionResponse>; /** * Deposit assets into a vault * @param vaultAddress - The vault contract address * @param depositData - Deposit parameters including amounts and caller address * @param network - Stellar network (optional, uses default if not specified) * @returns Transaction XDR for signing and simulation response */ depositToVault(vaultAddress: string, depositData: DepositToVaultParams, network?: SupportedNetworks): Promise<VaultTransactionResponse>; /** * Withdraw specific asset amounts from vault * @param vaultAddress - The vault contract address * @param withdrawData - Withdrawal parameters including amounts and caller * @param network - Stellar network (optional, uses default if not specified) * @returns Transaction XDR for signing and simulation response * @example * ```typescript * const withdrawData = { * amounts: [500000, 1000000], * caller: 'GUSER...', * slippageBps: 100 // 1% slippage tolerance * }; * const response = await sdk.withdrawFromVault('CVAULT...', withdrawData); * ``` */ withdrawFromVault(vaultAddress: string, withdrawData: WithdrawParams, network?: SupportedNetworks): Promise<VaultTransactionResponse>; /** * Withdraw vault shares for underlying assets * @param vaultAddress - The vault contract address * @param shareData - Share withdrawal parameters including share amount and caller * @param network - Stellar network (optional, uses default if not specified) * @returns Transaction XDR for signing and simulation response */ withdrawShares(vaultAddress: string, shareData: WithdrawSharesParams, network?: SupportedNetworks): Promise<VaultTransactionResponse>; /** * Get vault's Annual Percentage Yield (APY) * @param vaultAddress - The vault contract address * @param network - Stellar network (optional, uses default if not specified) * @returns APY information including percentage and calculation period * @example * ```typescript * const apy = await sdk.getVaultAPY('CVAULT...'); * console.log(`APY: ${apy.apyPercent}% (calculated over ${apy.period})`); * ``` */ getVaultAPY(vaultAddress: string, network?: SupportedNetworks): Promise<VaultApyResponse>; /** * Rebalance vault strategies (Rebalance Manager role required) * @param vaultAddress - The vault contract address * @param rebalanceData - Rebalance parameters including investment instructions * @param network - Stellar network (optional, uses default if not specified) * @returns Transaction XDR for Rebalance Manager signing * @example * ```typescript * const rebalanceData = { * caller: 'GREBALANCE_MANAGER...', * instructions: [ * { type: 'Unwind', strategy_address: 'CSTRATEGY1...', amount: 500000 }, * { type: 'Invest', strategy_address: 'CSTRATEGY2...', amount: 1000000 }, * { * type: 'SwapExactIn', * token_in: 'GTOKEN1...', * token_out: 'GTOKEN2...', * amount: 250000, * slippageToleranceBps: 100 * } * ] * }; * const response = await sdk.rebalanceVault('CVAULT...', rebalanceData); * ``` */ rebalanceVault(vaultAddress: string, rebalanceData: RebalanceParams, network?: SupportedNetworks): Promise<VaultTransactionResponse>; /** * Emergency rescue assets from strategy (Emergency Manager role required) * @param vaultAddress - The vault contract address * @param rescueData - Rescue parameters including strategy address and caller * @param network - Stellar network (optional, uses default if not specified) * @returns Transaction XDR for Emergency Manager signing and rescued assets info * @example * ```typescript * const rescueData = { * strategy_address: 'CSTRATEGY...', * caller: 'GEMERGENCY_MANAGER...' * }; * const response = await sdk.emergencyRescue('CVAULT...', rescueData); * ``` */ emergencyRescue(vaultAddress: string, rescueData: RescueFromVaultParams, network?: SupportedNetworks): Promise<VaultTransactionResponse>; /** * Pause a specific strategy (Strategy Manager role required) * @param vaultAddress - The vault contract address * @param strategyData - Strategy pause parameters * @param network - Stellar network (optional, uses default if not specified) * @returns Transaction XDR for Strategy Manager signing * @example * ```typescript * const strategyData = { * strategy_address: 'CSTRATEGY...', * caller: 'CSTRATEGY_MANAGER...' * }; * const response = await sdk.pauseStrategy('CVAULT...', strategyData); * ``` */ pauseStrategy(vaultAddress: string, strategyData: PauseStrategyParams, network?: SupportedNetworks): Promise<VaultTransactionResponse>; /** * Unpause a specific strategy (Strategy Manager role required) * @param vaultAddress - The vault contract address * @param strategyData - Strategy unpause parameters * @param network - Stellar network (optional, uses default if not specified) * @returns Transaction XDR for Strategy Manager signing * @example * ```typescript * const strategyData = { * strategy_address: 'CSTRATEGY...', * caller: 'GSTRATEGY_MANAGER...' * }; * const response = await sdk.unpauseStrategy('CVAULT...', strategyData); * ``` */ unpauseStrategy(vaultAddress: string, strategyData: UnpauseStrategyParams, network?: SupportedNetworks): Promise<VaultTransactionResponse>; /** * Get a specific vault role address * @param vaultAddress - The vault contract address * @param roleToGet - The role to retrieve (manager, emergency_manager, rebalance_manager, fee_receiver) * @param network - Stellar network (optional, uses default if not specified) * @returns Role information with address * @example * ```typescript * const role = await sdk.getVaultRole('CVAULT...', VaultRoles.MANAGER); * console.log(`Manager address: ${role.address}`); * ``` */ getVaultRole(vaultAddress: string, roleToGet: VaultRoles, network?: SupportedNetworks): Promise<VaultRoleResponse>; /** * Set a vault role to a new address (Manager role required) * @param vaultAddress - The vault contract address * @param roleToSet - The role to set * @param roleData - Role assignment parameters including new address and caller * @param network - Stellar network (optional, uses default if not specified) * @returns Transaction XDR for Manager signing * @example * ```typescript * const roleData = { * caller: 'GMANAGER...', * new_address: 'GNEW_MANAGER...' * }; * const response = await sdk.setVaultRole('CVAULT...', VaultRoles.MANAGER, roleData); * ``` */ setVaultRole(vaultAddress: string, roleToSet: VaultRoles, roleData: SetVaultRoleParams, network?: SupportedNetworks): Promise<VaultTransactionResponse>; /** * Lock vault fees and optionally update fee rate (Manager role required) * @param vaultAddress - The vault contract address * @param lockData - Lock fees parameters including optional new fee rate * @param network - Stellar network (optional, uses default if not specified) * @returns Transaction XDR for Manager signing * @example * ```typescript * const lockData = { * caller: 'GMANAGER...', * new_fee_bps: 150 // Optional: new fee rate in basis points (1.5%) * }; * const response = await sdk.lockVaultFees('CVAULT...', lockData); * ``` */ lockVaultFees(vaultAddress: string, lockData: LockFeesParams, network?: SupportedNetworks): Promise<VaultTransactionResponse>; /** * Release fees from a specific strategy (Manager role required) * @param vaultAddress - The vault contract address * @param releaseData - Release fees parameters including strategy address and amount * @param network - Stellar network (optional, uses default if not specified) * @returns Transaction XDR for Manager signing * @example * ```typescript * const releaseData = { * caller: 'GMANAGER...', * strategy_address: 'CSTRATEGY...', * amount: 100000 * }; * const response = await sdk.releaseVaultFees('CVAULT...', releaseData); * ``` */ releaseVaultFees(vaultAddress: string, releaseData: ReleaseFeesParams, network?: SupportedNetworks): Promise<VaultTransactionResponse>; /** * Distribute accumulated vault fees to fee receiver (Manager role required) * @param vaultAddress - The vault contract address * @param distributeData - Distribution parameters including caller * @param network - Stellar network (optional, uses default if not specified) * @returns Transaction XDR for Manager signing * @example * ```typescript * const distributeData = { * caller: 'GMANAGER...' * }; * const response = await sdk.distributeVaultFees('CVAULT...', distributeData); * ``` */ distributeVaultFees(vaultAddress: string, distributeData: DistributeFeesParams, network?: SupportedNetworks): Promise<VaultTransactionResponse>; /** * Upgrade vault WASM contract (Manager role required) * @param vaultAddress - The vault contract address * @param newWasmHash - Upgrade parameters including new WASM hash and caller * @param network - Stellar network (optional, uses default if not specified) * @returns Transaction XDR for Manager signing * @example * ```typescript * const upgradeData = { * caller: 'GMANAGER...', * new_wasm_hash: 'abcd1234...' // New WASM hash to upgrade to * }; * const response = await sdk.upgradeVaultWasm('CVAULT...', upgradeData); * ``` */ upgradeVaultWasm(vaultAddress: string, newWasmHash: UpgradeWasmParams, network?: SupportedNetworks): Promise<VaultTransactionResponse>; /** * Submit a signed transaction to the Stellar blockchain * @param xdr - Base64 encoded signed transaction XDR * @param network - Stellar network (optional, uses default if not specified) * @param launchtube - Whether to use LaunchTube service (defaults to false) * @returns Transaction response with hash and status */ sendTransaction(xdr: string, network?: SupportedNetworks, launchtube?: boolean): Promise<SendTransactionResponse | LaunchTubeResponse>; } //# sourceMappingURL=defindex-sdk.d.ts.map