DeFindex.Sdk 0.3.1

dotnet add package DeFindex.Sdk --version 0.3.1
                    
NuGet\Install-Package DeFindex.Sdk -Version 0.3.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DeFindex.Sdk" Version="0.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DeFindex.Sdk" Version="0.3.1" />
                    
Directory.Packages.props
<PackageReference Include="DeFindex.Sdk" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DeFindex.Sdk --version 0.3.1
                    
#r "nuget: DeFindex.Sdk, 0.3.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DeFindex.Sdk@0.3.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DeFindex.Sdk&version=0.3.1
                    
Install as a Cake Addin
#tool nuget:?package=DeFindex.Sdk&version=0.3.1
                    
Install as a Cake Tool

DeFindex .NET SDK Specification

Overview

This document outlines the required methods and data structures for the DeFindex .NET SDK. The SDK is designed to interact with the DeFindex vault system, allowing users to retrieve vault shares and managed funds while maintaining clear distinctions between vault shares and underlying assets.

Terminology

  • Shares: Represents ownership of a vault.
  • Funds: Represents the underlying assets managed by the vault (e.g., USDC, XLM).
  • Vault: The contract managing investments and distributions.

SDK Initialization

The Defindex class requires a contract address and a SorobanServer instance from the dotnet-sdk. Clients must instantiate the SorobanServer with their RPC URL and bearer tokens before passing it to Defindex for initialization.

SDK Usage

1. Create vault instance:

 var sorobanServer = new SorobanServer("https://soroban-testnet.stellar.org/")
 var vaultAddress = "CXX...XXX" //(Smart contract address)
 var vaultInstance = new DefindexSdk(vaultAddress, sorobanServer);

2. Use vault instance to create a transaction:

var account = await horizonServer.Accounts.Account(keypair.AccountId);
var adminAccount = new Account(account.AccountId, account.SequenceNumber);
var userWithShares =  "GXX...XX"; //Soroban G account
var transaction = await vaultInstance.CreateBalanceTransaction(adminAccount, userWithShares);

3. Setup the transaction data & submit:

var simulatedDepositTransaction = await sorobanServer.SimulateTransaction(transaction);
transaction.SetSorobanTransactionData(simulatedDepositTransaction.SorobanTransactionData);
transaction.SetSorobanAuthorization(simulatedDepositTransaction.SorobanAuthorization);
transaction.AddResourceFee(simulatedDepositTransaction.MinResourceFee.Value + 100000);
transaction.Sign(keypair);
var submittedTx = await sorobanServer.SendTransaction(transaction);

// Now you should await for the blockchain confirmation...

4. Parse transaction result:

Task.Delay(5000).Wait(); //We will use a timeout for demonstration
// After the blockchain confirmation we can get the transaction by the hash using sorobanServer.GetTransaction(txhash)
var checkedTx = await sorobanServer.GetTransaction(submittedTx.Hash);

var parsedtx = vaultInstance.ParseTransactionResponse(checkedTx);
// Now you can print the results using:
Console.WriteLine($"Parsed transaction: {JsonConvert.SerializeObject(parsedtx, Formatting.Indented)}");

SDK Methods

1. GetUserShares

Retrieves the number of vault shares a user owns.

Method Signature:

public async Task<VaultShares> GetUserShares(string accountId)

Returns:

  • VaultShares object containing:
    • AccountId: The user’s account ID.
    • Shares: The number of vault shares owned.

2. FetchTotalManagedFunds

Retrieves vault's total funds, idle funds, and invested funds per strategy for each underlying asset.

Method Signature:

public async Task<List<ManagedFundsResult>> FetchTotalManagedFunds()

Returns:

  • List<ManagedFundsResult> where:
  • Every (ManagedFundsResult) object contains:
    • Asset: The underliying asset contractID
    • TotalAmount: Total amount of this asset in the vault.
    • IdleAmount: Amount of this asset not currently invested.
    • InvestedAmount: Amount of this asset currently invested.
    • StrategyAllocations: A List mapping strategy contract IDs, Invested amounts and paused status.

Example of a returned structure:

[
  {
    "Asset": "CARDT45FED2I3FKESPMHDFV3ZMR6VH5ZHCFIOPH6TPSU35GPB6QBBCSU",
    "IdleAmount": 100000000,
    "InvestedAmount": 0,
    "TotalAmount": 100000000,
    "StrategyAllocations": [
      {
        "Amount": 0,
        "Paused": false,
        "StrategyAddress": "CAS6KDVEXMCB5BNXJYHWGWO2U6INQFC2SGFGIJLU27HLWIOF4XQE5ZMS"
      }
    ]
  },
  {
    "Asset": "CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC",
    "IdleAmount": 50000000,
    "InvestedAmount": 50000000,
    "TotalAmount": 100000000,
    "StrategyAllocations": [
      {
        "Amount": 50000000,
        "Paused": false,
        "StrategyAddress": "CAS6KDVEXMCB5BNXJYHWGWO2U6INQFC2SGFGIJLU27HLWIOF4XQE5ZMS"
      }
    ]
  }
]

3. GetVaultTotalShares

Retrieves the total number of vault shares issued.

Method Signature:

public async Task<ulong> GetVaultTotalShares()

Returns:

  • ulong: Total number of shares in circulation.

4. CreateDepositTransaction

Creates an unsigned transaction to deposit into a vault.

Method Signature:

public async Task<Transaction> CreateDepositTransaction(
    List<ulong> amountsDesired,
    List<ulong> amountsMin,
    string from,
    bool invest)

Inputs:

  • amountsDesired: List of desired deposit amounts.
  • amountsMin: List of minimum acceptable deposit amounts.
  • from: Address (string) of the depositor.
  • invest: Whether the deposit invests immediately into strategies.

Returns:

  • Transaction: The unsigned deposit transaction.

5. CreateWithdrawTransaction

Creates an unsigned transaction to withdraw from a vault.

Method Signature:

public async Task<Transaction> CreateWithdrawTransaction(
    ulong withdrawShares,
    List<ulong> amountsMinOut,
    string from)

Inputs:

  • withdrawShares: Amount of vault shares to withdraw.
  • amountsMinOut: List of minimum acceptable withdrawal amounts per asset.
  • from: Address (string) of the withdrawer.

Returns:

  • Transaction: The unsigned withdrawal transaction.

6. ParseTransactionResponse

Parses the transaction response from the network.

Method Signature:

public async Task<List<TransactionResult>> ParseTransactionResponse(GetTransactionResponse response)

Inputs:

  • response: A previously validated transaction response from the network.

Returns:

  • List<TransactionResult>: List of transaction results.
    • IsSuccess: Boolean indicating if the transaction succeeded.
    • TransactionHash: The hash of the submitted transaction (if successful).
    • Amounts: An array of amounts deposited or withdrawn.
    • SharesChanged: The amount of shares minted or burned.

7. GetVaultAPY

Retrieves the current estimated APY for the vault.

Method Signature:

public async Task<decimal?> GetVaultAPY()

Returns:

  • decimal?: Estimated APY for the vault, or null if not available.

8. GetAssetAmountsPerShares

Converts a given number of vault shares to the corresponding underlying asset amounts.

Method Signature:

public async Task<List<BigInteger>> GetAssetAmountsPerShares(BigInteger vaultShares)

Inputs:

  • vaultShares: The number of vault shares to convert.

Returns:

  • List<BigInteger>: List of asset amounts corresponding to the given vault shares.

9. CreateWithdrawUnderlyingTx

Creates an unsigned transaction to withdraw a specific amount of underlying asset from the vault, with a basis points tolerance.

Method Signature:

public async Task<Transaction> CreateWithdrawUnderlyingTx(
    BigInteger withdrawAmount,
    int toleranceBPS,
    string from
)

Inputs:

  • withdrawAmount: The amount of underlying asset to withdraw.
  • toleranceBPS: The basis points tolerance for the withdrawal.
  • from: The account to withdraw from.

Returns:

  • Transaction: The unsigned withdrawal transaction for underlying assets.

Data Models

VaultShares

public sealed record VaultShares(
    string AccountId,
    ulong Shares
);

ManagedFundsResult

public sealed record ManagedFundsResult(
    string? Asset,
    BigInteger IdleAmount,
    BigInteger InvestedAmount,
    BigInteger TotalAmount,
    List<StrategyAllocation> StrategyAllocations
);

StrategyAllocation

public sealed record StrategyAllocation(
    BigInteger Amount,
    bool Paused,
    string? StrategyAddress
);

TransactionResult

public sealed record TransactionResult(
    bool IsSuccess,
    string? TransactionHash,
    List<BigInteger> Amounts,
    BigInteger SharesChanged
);

Summary

Method Purpose
GetUserShares(string accountId) Retrieves user’s vault shares
FetchTotalManagedFunds() Gets total vault funds, idle funds, invested funds, and per-strategy breakdown for each asset
GetVaultTotalShares() Fetches total vault shares issued
CreateDepositTransaction(List<ulong> amountsDesired, List<ulong> amountsMin, string from, bool invest) Creates an unsigned transaction to deposit into a vault
CreateWithdrawTransaction(ulong withdrawShares, List<ulong> amountsMinOut, string from) Creates an unsigned transaction to withdraw from a vault
ParseTransactionResponse(GetTransactionResponse response) Parses a transaction response from the network
GetVaultAPY() Retrieves the current estimated APY for the vault
GetAssetAmountsPerShares(BigInteger vaultShares) Converts vault shares to underlying asset amounts
CreateWithdrawUnderlyingTx(BigInteger withdrawAmount, int toleranceBPS, string from) Creates an unsigned transaction to withdraw underlying assets from a vault

Development & upgrade guide,

  1. Installing dependencies
dotnet restore
  1. Building the project
dotnet build
  1. Running tests
dotnet test

If you need to update dependencies, just edit the *.csproj files and run dotnet restore again.

Build and deployment

To build and deploy the project, you can use the following commands:

  1. Building the project

Update the version number in the *.csproj file and add some release notes and run.

dotnet build
  1. Publishing the project

Manually publish the build from bin/Debug/DeFindex.Sdk.${your_version}.nupkg to the DeFindex nuget page.

Run the test example

copy the .env.example to a .env file using

cp .env.example .env

Then run the testnet example using

dotnet run testnet

Made with ❤️ by PaltaLabs🥑

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.1 143 9/9/2025
0.3.0 94 9/5/2025
0.2.3 146 7/1/2025
0.2.2 166 5/29/2025
0.2.1 570 5/27/2025
0.2.0 169 5/23/2025
0.1.4 775 3/25/2025
0.1.3 485 3/25/2025
0.1.2 113 2/26/2025
0.1.1 234 2/20/2025
0.1.0 113 2/19/2025

• Updated stellar-dotnet-sdk to version 14.0.1