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

@defibrain/sdk

v0.1.6

Published

DefiBrain SDK - Unified DeFi Router API Client

Downloads

24

Readme

DefiBrain SDK

Official TypeScript/JavaScript SDK for the DefiBrain API - A unified DeFi router that integrates multiple protocols (Pendle, Curve, 1inch, Aave V3, Morpho Blue, Uniswap) into a single intelligent API.

Installation

npm install @defibrain/sdk

🚀 Quick Start

import { DefiBrainClient } from '@defibrain/sdk';

// Initialize client
const client = new DefiBrainClient({
  apiKey: 'your-api-key',
  apiUrl: 'https://apibrain.oxg.fi/v1', // Optional, defaults to production
  chainId: 1, // Optional, defaults to Ethereum mainnet
});

// Optimize yield automatically (now also builds a ready-to-sign transaction by default)
const result = await client.optimizeYield({
  asset: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
  amount: '1000000', // 1 USDC
  strategy: 'max_yield',
});

console.log(`Best protocol: ${result.protocol}`);
console.log(`Estimated APR: ${result.estimatedAPR}%`);

// Option A: execute using the transaction returned by optimizeYield (recommended)
if (result.transaction) {
  const tx = await signer.sendTransaction(result.transaction);
  await tx.wait();
}

// Option B: manual executeAction flow (fallback / advanced)
// const tx = await client.executeAction({
//   protocol: result.protocol,
//   action: result.action,
//   params: result.params,
// });

Advanced Usage

Wallet Integration

import { WalletHelper } from '@defibrain/sdk';

const wallet = new WalletHelper();

// Connect wallet
const walletInfo = await wallet.connect();
console.log(`Connected: ${walletInfo.address}`);

// Get balance
const balance = await wallet.getBalance();
console.log(`Balance: ${balance} wei`);

// Get token balance
const usdcBalance = await wallet.getTokenBalance('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48');
console.log(`USDC: ${usdcBalance}`);

Transaction Helper

import { DefiBrainClient, TransactionHelper } from '@defibrain/sdk';

const client = new DefiBrainClient({ apiKey: 'your-key' });
const wallet = new WalletHelper();
await wallet.connect();

const txHelper = new TransactionHelper(wallet.getProvider()!, wallet.getChainId());

// Optimize yield
const result = await client.optimizeYield({
  asset: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
  amount: '1000000',
});

// Sign and send transaction
if (result.transaction) {
  const txHash = await txHelper.signAndSend(result.transaction);
  console.log(`Transaction sent: ${txHash}`);
  
  // Wait for confirmation
  const receipt = await txHelper.waitForConfirmation(txHash);
  console.log(`Confirmed in block: ${receipt.blockNumber}`);
  
  // Or do it all in one call
  // const receipt = await txHelper.signSendAndWait(result.transaction);
}

Pendle Helper

import { DefiBrainClient, PendleHelper, TransactionHelper, WalletHelper } from '@defibrain/sdk';

const client = new DefiBrainClient({ apiKey: 'your-key' });
const wallet = new WalletHelper();
await wallet.connect();

const txHelper = new TransactionHelper(wallet.getProvider()!, wallet.getChainId());
const pendleHelper = new PendleHelper(client, txHelper);

// Optimize yield with Pendle
const result = await pendleHelper.optimizeYieldWithPendle(
  '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
  '1000000', // 1 USDC
  'max_yield'
);

// Swap PT to YT
const swapResult = await pendleHelper.swapPTtoYT(
  '0x...', // PT address
  '1000000',
  false // Don't execute, just prepare
);

// Redeem PT at maturity
const redeemResult = await pendleHelper.redeemPT(
  '0x...', // PT address
  '1000000',
  false
);

Aave Helper

import { DefiBrainClient, AaveHelper, TransactionHelper, WalletHelper } from '@defibrain/sdk';

const client = new DefiBrainClient({ apiKey: 'your-key' });
const wallet = new WalletHelper();
await wallet.connect();

const txHelper = new TransactionHelper(wallet.getProvider()!, wallet.getChainId());
const aaveHelper = new AaveHelper(client, txHelper);

// Supply to Aave
const supplyResult = await aaveHelper.supply(
  '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
  '1000000', // 1 USDC
  false // Don't execute, just prepare
);

// Withdraw from Aave
const withdrawResult = await aaveHelper.withdraw(
  '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
  '1000000',
  false
);

Automatic Retry

const client = new DefiBrainClient({
  apiKey: 'your-key',
  retryOptions: {
    maxRetries: 3,
    initialDelay: 1000,
    maxDelay: 10000,
    backoffFactor: 2,
  },
});

// All API calls automatically retry on network errors
const result = await client.optimizeYield({ ... });

Input Validation

import { validateAddress, validateAmount, formatAmount, parseAmount } from '@defibrain/sdk';

// Validate address
validateAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'); // true

// Validate amount
validateAmount('1000000'); // true

// Format amount (wei to readable)
formatAmount('1000000000000000000', 18); // "1"

// Parse amount (readable to wei)
parseAmount('1.5', 18); // "1500000000000000000"

Why DefiBrain?

For End Users

  • Auto-Optimization: Automatically finds the best yield across multiple protocols
  • Simple API: One unified interface for all DeFi protocols
  • Batch Operations: Execute multiple actions in a single transaction
  • Gas Optimization: Built-in gas estimation and optimization

For Developers

  • Easy Integration: Add new protocols with ~70% less code
  • Reusable Infrastructure: No need to rebuild common functionality
  • Type Safety: Full TypeScript support with strong typing
  • Protocol Helpers: Simple, protocol-specific APIs (AaveHelper, PendleHelper, etc.)

See How to Integrate a Protocol for details.

Documentation

Spanish summaries:

  • ./docs/ES/README.md – índice y resumen en español
  • ./docs/ES/API.md – resumen de la API
  • ./docs/ES/CONFIGURATION.md – configuración básica
  • ./docs/ES/EXAMPLES.md – ejemplos rápidos
  • ./docs/ES/CONTRACTS.md – contratos incluidos en el SDK

Full documentation also available at: https://defibrain.oxg.fi/docs.html

License

MIT License - This SDK is open source.

Support

  • Documentation: https://defibrain.oxg.fi/docs.html
  • Discord: https://discord.gg/TU724DzWpV
  • Website: https://defibrain.oxg.fi