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

@reach-sh/humble-sdk

v2.1.3-o

Published

A Javascript library for interacting with the HumbleSwap DEx

Downloads

444

Readme

HumbleSDK v2.0.0

A Javascript library for interacting with the HumbleSwap DEx.


Documentation

Documentation has moved here.


v2 Changes

v2 introduces a few changes and adds new functionality, including staking pools. Some functions may have been renamed: review changes in our changelog, and view our documentation for additional info.


Installing the SDK

Option 1. NPM (recommended)

The fastest way is to use npm:

$. npm i -s @reach-sh/humble-sdk

Option 2. Cloning the repo directly

To get started without NPM, you can clone and build the SDK from the repository.

# Clone the repository 
$. git clone https://github.com/reach-sh/humble-sdk.git

# Enter the directory with the repo (replace with path to your repository clone)
$. cd path/to/humble-sdk 

# and install dependencies (there aren't a lot)
$. npm install

# Build the SDK. Will output to a ./lib directory in the same folder as the 
# package.json file. This takes seconds and doesn't output anything to your terminal.
$. npm run build

You will know it is complete when your (terminal's) typing prompt reappears.
Then, as a FINAL STEP, copy or move the new lib/ directory into your project. This will allow you to access it like any other JS module:

import { initHumbleSDK } from "path/to/lib";

Example Usage

Subscribing to a stream of Liquidity Pool data

import { subscribeToPoolStream, createReachAPI } from "@reach-sh/humble-sdk";

const stdlib = createReachAPI();
const acc = await stdlib.createAccount();

// Fetch existing streams and get notified when a new one is created
subscribeToPoolStream(acc, {
    // Pool ID (and id of pool tokens) received from contract.
    // Pool data has NOT been fetched yet.
    onPoolReceived: (info) => { 
        const [poolAddr, tokenAId, tokenBId] = info;
        // ... do something with data
     },

    // Pool and Token data has been received from network. 
    onPoolFetched: (result: FetchPoolTxnResult) => { 
        const { succeeded, poolAddress, data, message } = result;
        if (succeeded) // ... do something with data
     }
})

Swapping between a pair of tokens

Note: Swapping does not use routing. Read the docs to learn how to fetch pools for DEx operations.

import { calculateTokenSwap, performSwap } from "@reach-sh/humble-sdk";

const pool = /* pool source */

// Calculate expected swap output
const { tokenAId, tokenBId } = pool;
const amountA = 100;
const swap = calculateTokenSwap({ 
    pool, 
    swap: { amountA, tokenAId, tokenBId } 
});

// Perform swap
const swapOpts = { poolAddress: pool.poolAddress, swap, pool };
const { data, message, succeeded } = await performSwap(acc, swapOpts);
// if (succeeded) data == { amountIn: string; amountOut: string }

Local Testing

The humble-sdk contains some helper scripts for running the SDK on a command line. See more here