defindex-sdk
v0.1.2
Published
TypeScript SDK for interacting with DeFindex Vaults on the Stellar Soroban network
Downloads
151
Maintainers
Readme
DeFindex SDK
A TypeScript SDK for interacting with DeFindex Vaults on the Stellar Soroban network. DeFindex is a protocol for creating and managing multi-asset investment vaults with customizable strategies.
Overview
DeFindex Vaults serve as the core of the DeFindex platform, responsible for:
- Managing multiple assets
- Executing investment strategies
- Ensuring proper asset rebalancing
- Minting/burning dfTokens (vault shares)
Installation
npm install defindex-sdk
# or
yarn add defindex-sdk
Quick Start
import { Vault, SorobanNetwork } from 'defindex-sdk';
// Initialize a vault instance
const vault = new Vault({
network: SorobanNetwork.TESTNET,
contractId: 'YOUR_VAULT_CONTRACT_ID'
});
// Deposit assets
const txHash = await vault.deposit(
accountAddress,
100, // amount
true, // signAndSend
sorobanContext,
secretKey
);
Features
- Asset Management: Deposit and withdraw multiple assets
- Balance Tracking: Monitor your vault share balance
- Transaction Handling: Built-in support for Soroban transactions
- Type Safety: Full TypeScript support
API Reference
Vault
The main class for interacting with DeFindex vaults.
Constructor
new Vault({
network: SorobanNetwork,
contractId: string
})
Methods
deposit(account: string, amount: number, signAndSend: boolean, sorobanContext: SorobanContextType, secretKey?: string): Promise<string>
Deposits assets into the vault and receives dfTokens in return.
Parameters:
account
: The depositor's addressamount
: Amount to depositsignAndSend
: Whether to sign and submit the transactionsorobanContext
: Soroban context objectsecretKey
: Optional secret key for signing
Returns: Transaction hash
withdraw(account: string, amount: number, signAndSend: boolean, sorobanContext: SorobanContextType, secretKey?: string): Promise<string>
Withdraws assets from the vault by burning dfTokens.
Parameters:
account
: The withdrawer's addressamount
: Amount of dfTokens to burnsignAndSend
: Whether to sign and submit the transactionsorobanContext
: Soroban context objectsecretKey
: Optional secret key for signing
Returns: Transaction hash
balance(account: string, sorobanContext: SorobanContextType): Promise<number>
Checks the dfToken balance of an account.
Parameters:
account
: The account addresssorobanContext
: Soroban context object
Returns: Balance amount
Example Usage
import { Vault, SorobanNetwork } from 'defindex-sdk';
async function main() {
// Initialize vault
const vault = new Vault({
network: SorobanNetwork.TESTNET,
contractId: 'YOUR_CONTRACT_ID'
});
// Create Soroban context
const sorobanContext = await createSorobanContext();
// Check initial balance
const balance = await vault.balance(accountAddress, sorobanContext);
console.log('Balance:', balance);
// Deposit assets
const txHash = await vault.deposit(
accountAddress,
100,
true,
sorobanContext,
secretKey
);
console.log('Deposit TX:', txHash);
}
For a complete example, see vault-example.ts.
Support
- Discord: Join our community