npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@samuel_birhanu/stellar-defi-sdk

v1.0.0

Published

A comprehensive, easy-to-use TypeScript SDK for interacting with Decentralized Finance (DeFi) protocols on the Stellar network using Soroban smart contracts.

Downloads

13

Readme

Stellar DeFi SDK

A comprehensive, easy-to-use TypeScript SDK for interacting with Decentralized Finance (DeFi) protocols on the Stellar network using Soroban smart contracts.

🚀 Features

  • 🏦 Vaults: Simple interface for token deposits and interest-bearing vaults.
  • 💱 Swap Pools: Automated Market Maker (AMM) interactions for liquidity and asset swaps.
  • ⚖️ Governance: Propose, vote on, and execute protocol changes.
  • 🛠️ Built-in Utilities: Helpers for ScVal conversions and address management.

📦 Installation

Install the SDK via npm:

npm install @samuel_birhanu/stellar-defi-sdk

Ensure you have @stellar/stellar-sdk installed as well:

npm install @stellar/stellar-sdk

⚙️ Quick Start

Initialize the DefiClient to connect to either Stellar Testnet or Mainnet.

import { DefiClient } from '@samuel_birhanu/stellar-defi-sdk';

// Initialize for Testnet
const client = new DefiClient('testnet');

// Access the underlying RPC server
console.log(client.rpc.server);

🏗️ Core Modules

1. Vault Client

Manage deposits and withdrawals for any Soroban-based vault.

import { VaultClient, DefiClient } from '@samuel_birhanu/stellar-defi-sdk';

const client = new DefiClient('testnet');
const vault = new VaultClient(client, 'CONTRACT_ID_HERE');

// Deposit tokens
const depositTx = vault.deposit('USER_ADDRESS', 1000n);

// Withdraw tokens
const withdrawTx = vault.withdraw('USER_ADDRESS', 500n);

// Check balance
const balanceQuery = vault.balance('USER_ADDRESS');

2. Swap Pool Client

Interact with liquidity pools to trade assets and manage liquidity.

import { SwapPoolClient, DefiClient } from '@samuel_birhanu/stellar-defi-sdk';

const client = new DefiClient('testnet');
const pool = new SwapPoolClient(client, 'POOL_CONTRACT_ID');

// Add Liquidity
const addLiq = pool.addLiquidity('USER_ADDRESS', 1000n, 1000n);

// Swap Asset A for Asset B
const swap = pool.swapAforB('USER_ADDRESS', 100n);

// Calculate output amount manually using math utilities
import { getAmountOut } from '@samuel_birhanu/stellar-defi-sdk/contracts/swapPool/math';
const expectedOut = getAmountOut(100n, 10000n, 10000n);

3. Governance Client

Participate in decentralized governance protocols.

import { GovernanceClient, DefiClient } from '@samuel_birhanu/stellar-defi-sdk';

const client = new DefiClient('testnet');
const gov = new GovernanceClient(client, 'GOV_CONTRACT_ID');

// Create a proposal
const proposal = gov.propose('USER_ADDRESS', 'Increase network fees', 5000);

// Vote on a proposal (true = Support, false = Against)
const vote = gov.vote('USER_ADDRESS', 1, true);

// Execute an approved proposal
const execution = gov.execute(1);

🛠️ Utilities

The SDK provides powerful utilities to handle Stellar's native data formats.

import { toI128, toU32, toAddress } from '@samuel_birhanu/stellar-defi-sdk/utils';

const scValLargeInt = toI128(1000000n);
const scValUint32 = toU32(42);
const scValAddress = toAddress('GD...');

📁 Project Structure

| File | Description | |------|-------------| | src/client/defiClient.ts | Main entry point for the SDK. | | src/client/rpc.ts | Handles connectivity to Stellar RPC nodes. | | src/contracts/vault/ | Vault interaction logic and types. | | src/contracts/swapPool/ | AMM/Swap pool logic and math utilities. | | src/contracts/governance/ | DAO governance tools. | | src/utils/ | Low-level converters for ScVal and Addresses. | | src/config/networks.ts | Network-specific configurations (Testnet/Mainnet). |


📜 Development

To build the SDK from source:

npm run build

This will generate CommonJS and ESM bundles in the dist directory.


🛡️ License

ISC