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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ponderfinance/sdk

v0.1.46

Published

SDK for interacting with Ponder DEX

Downloads

3,070

Readme

Ponder SDK

TypeScript SDK for interacting with the Ponder DEX protocol on Bitkub Chain.

Installation

npm install @ponderfinance/sdk
# or
yarn add @ponderfinance/sdk

Quick Start

import { PonderSDK } from '@ponderfinance/sdk'
import { createPublicClient, createWalletClient, http, custom } from 'viem'

// Initialize SDK
const sdk = new PonderSDK({
  chainId: 96, // Bitkub Chain
  // Optional: provide your own clients
  publicClient,
  walletClient
})

Core Features

Factory Operations

// Get pair address
const pairAddress = await sdk.factory.getPair(tokenA, tokenB)

// Create new pair
const result = await sdk.factory.createPair({
  tokenA: '0x...',
  tokenB: '0x...'
})
const { pairAddress, token0, token1 } = await result.wait()

Router Operations

// Add liquidity
await sdk.router.addLiquidity({
  tokenA: '0x...',
  tokenB: '0x...',
  amountADesired: parseEther('1'),
  amountBDesired: parseEther('1'),
  amountAMin: parseEther('0.95'),
  amountBMin: parseEther('0.95'),
  to: userAddress,
  deadline: BigInt(Math.floor(Date.now() / 1000) + 1200) // 20 minutes
})

// Get swap amounts
const amountsOut = await sdk.router.getAmountsOut(
  parseEther('1'),
  [tokenA, tokenB]
)

// Swap tokens
await sdk.router.swapExactTokensForTokens({
  amountIn: parseEther('1'),
  amountOutMin: parseEther('0.95'),
  path: [tokenA, tokenB],
  to: userAddress,
  deadline: BigInt(Math.floor(Date.now() / 1000) + 1200)
})

Pair Operations

const pair = sdk.getPair(pairAddress)

// Get reserves
const { reserve0, reserve1, blockTimestampLast } = await pair.getReserves()

// Add liquidity
await pair.mint(userAddress)

// Remove liquidity
await pair.burn(userAddress)

MasterChef Operations

// Get pool info
const poolInfo = await sdk.masterChef.poolInfo(0n)
const userInfo = await sdk.masterChef.userInfo(0n, userAddress)

// Get pending rewards
const pending = await sdk.masterChef.pendingPonder(0n, userAddress)

// Stake LP tokens
await sdk.masterChef.deposit(0n, parseEther('1'))

// Unstake LP tokens
await sdk.masterChef.withdraw(0n, parseEther('1'))

// Boost rewards with PONDER tokens
await sdk.masterChef.boostStake(0n, parseEther('100'))

React/Next.js Integration

import { usePublicClient, useWalletClient } from 'wagmi'
import { PonderSDK } from '@ponderfinance/sdk'
import { useMemo } from 'react'

function usePonderSDK() {
  const publicClient = usePublicClient()
  const { data: walletClient } = useWalletClient()

  const sdk = useMemo(() => {
    if (!publicClient) return null

    return new PonderSDK({
      chainId: 96,
      publicClient,
      walletClient: walletClient ?? undefined
    })
  }, [publicClient, walletClient])

  return sdk
}

// Usage in component
function SwapComponent() {
  const sdk = usePonderSDK()

  const handleSwap = async () => {
    if (!sdk) return
    
    const amountsOut = await sdk.router.getAmountsOut(
      parseEther('1'),
      [tokenA, tokenB]
    )
    
    // Execute swap...
  }

  return <button onClick={handleSwap}>Swap</button>
}

Error Handling

try {
  await sdk.router.swapExactTokensForTokens({
    // ... params
  })
} catch (error) {
  if (error.message.includes('Wallet client required')) {
    console.error('Please connect your wallet')
  } else if (error.message.includes('INSUFFICIENT_OUTPUT_AMOUNT')) {
    console.error('Slippage too high')
  } else {
    console.error('Swap failed:', error)
  }
}

Supported Chains

  • Bitkub Chain (ChainID: 96)
  • Bitkub Testnet (ChainID: 25925)

API Reference

See API Documentation for detailed information about all available methods and types.

TypeScript Support

The SDK is written in TypeScript and provides full type definitions for all exports.

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

License

MIT Licensed. See LICENSE for more details.