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

@abhikumar_98/kuru-sdk

v1.0.15

Published

The `@kuru-labs/kuru-sdk` provides various functionalities for interacting with the Kuru protocol. Below are examples of how to use the SDK for different operations.

Downloads

523

Readme

Kuru SDK Documentation

The @kuru-labs/kuru-sdk provides various functionalities for interacting with the Kuru protocol. Below are examples of how to use the SDK for different operations.

Installation

npm install @kuru-labs/kuru-sdk

Configuration

Ensure you have a configuration file (config.json) with the necessary details such as rpcUrl, contractAddress, etc.

Example config.json:

{
    "rpcUrl": "https://your-rpc-url",
    "contractAddress": "your-contract-address",
    "marginAccountAddress": "your-margin-account-address",
    "baseTokenAddress": "your-base-token-address",
    "quoteTokenAddress": "your-quote-token-address",
    "routerAddress": "your-router-address",
    "userAddress": "your-user-address"
}

Ensure you export your private key to use the examples

export PRIVATE_KEY=<0xpvt_key>

Example Usage

Cancel Order

To cancel orders using the Kuru SDK:

import { ethers, BigNumber } from "ethers";
import * as KuruSdk from "@kuru-labs/kuru-sdk";
import * as KuruConfig from "./config.json";

const { rpcUrl, contractAddress } = KuruConfig;
const privateKey = process.env.PRIVATE_KEY as string;

const args = process.argv.slice(2);

(async () => {
    const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
    const signer = new ethers.Wallet(privateKey, provider);

    await KuruSdk.OrderCanceler.cancelOrders(
        signer,
        contractAddress,
        args.map(arg => BigNumber.from(parseInt(arg)))
    );
})();

Deposit

To deposit tokens into a margin account:

import { ethers } from "ethers";
import * as KuruSdk from "@kuru-labs/kuru-sdk";
import * as KuruConfig from "./config.json";

const { userAddress, rpcUrl, marginAccountAddress, baseTokenAddress, quoteTokenAddress } = KuruConfig;
const privateKey = process.env.PRIVATE_KEY as string;

(async () => {
    const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
    const signer = new ethers.Wallet(privateKey, provider);

    await KuruSdk.MarginDeposit.deposit(
        signer,
        marginAccountAddress,
        userAddress,
        baseTokenAddress,
        100000,
        18
    );

    await KuruSdk.MarginDeposit.deposit(
        signer,
        marginAccountAddress,
        userAddress,
        quoteTokenAddress,
        100000,
        18
    );
})();

Estimate Base for Sell

To estimate the required base for a sell operation:

import { ethers } from "ethers";
import * as KuruSdk from "@kuru-labs/kuru-sdk";
import * as KuruConfig from "./config.json";

const { rpcUrl, contractAddress } = KuruConfig;
const args = process.argv.slice(2);
const amount = parseFloat(args[0]);

(async () => {
    const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
    const marketParams = await KuruSdk.ParamFetcher.getMarketParams(provider, contractAddress);

    const estimate = await KuruSdk.CostEstimator.estimateRequiredBaseForSell(
        provider,
        contractAddress,
        marketParams,
        amount
    );

    console.log(`Estimated required base: ${estimate}`);
})();

Estimate Buy

To estimate the buy amount:

import { ethers } from "ethers";
import * as KuruSdk from "@kuru-labs/kuru-sdk";
import * as KuruConfig from "./config.json";

const { rpcUrl, contractAddress } = KuruConfig;
const args = process.argv.slice(2);
const size = parseFloat(args[0]);

(async () => {
    const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
    const marketParams = await KuruSdk.ParamFetcher.getMarketParams(provider, contractAddress);

    const estimate = await KuruSdk.CostEstimator.estimateBuy(
        provider,
        contractAddress,
        marketParams,
        size
    );

    console.log(`Estimated buy: ${estimate}`);
})();

Find Best Path

To find the best path for a swap:

import { ethers } from "ethers";
import * as KuruSdk from "@kuru-labs/kuru-sdk";
import * as KuruConfig from "./config.json";

const { rpcUrl, baseTokenAddress, quoteTokenAddress } = KuruConfig;
const size = parseFloat(process.argv[2]);

(async () => {
    const provider = new ethers.providers.JsonRpcProvider(rpcUrl);

    const bestPath = await KuruSdk.PathFinder.findBestPath(
        provider,
        baseTokenAddress,
        quoteTokenAddress,
        size
    );

    console.log(`Best path: ${bestPath}`);
})();

Market Buy

To perform a market buy:

import { ethers } from "ethers";
import * as KuruSdk from "@kuru-labs/kuru-sdk";
import * as KuruConfig from "./config.json";

const { rpcUrl, contractAddress } = KuruConfig;
const privateKey = process.env.PRIVATE_KEY as string;
const size = parseFloat(process.argv[2]);

(async () => {
    const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
    const signer = new ethers.Wallet(privateKey, provider);
    const marketParams = await KuruSdk.ParamFetcher.getMarketParams(provider, contractAddress);

    await KuruSdk.IOC.placeMarket(
        signer,
        contractAddress,
        marketParams,
        {
            size,
            isBuy: true,
            fillOrKill: true
        }
    );
})();

Place Limit Buy

To place a limit buy order:

import { ethers } from "ethers";
import * as KuruSdk from "@kuru-labs/kuru-sdk";
import * as KuruConfig from "./config.json";

const { rpcUrl, contractAddress } = KuruConfig;
const privateKey = process.env.PRIVATE_KEY as string;
const args = process.argv.slice(2);
const price = parseFloat(args[0]);
const size = parseFloat(args[1]);

(async () => {
    const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
    const signer = new ethers.Wallet(privateKey, provider);
    const marketParams = await KuruSdk.ParamFetcher.getMarketParams(provider, contractAddress);

    await KuruSdk.GTC.placeLimit(
        signer,
        contractAddress,
        marketParams,
        {
            price,
            size,
            isBuy: true,
            postOnly: true
        }
    );
})();

Swap

To perform a token swap:

import { ethers } from "ethers";
import * as KuruSdk from "@kuru-labs/kuru-sdk";
import * as KuruConfig from "./config.json";

const { rpcUrl, routerAddress, baseTokenAddress, quoteTokenAddress } = KuruConfig;
const privateKey = process.env.PRIVATE_KEY as string;
const size = parseFloat(process.argv[2]);

(async () => {
    const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
    const signer = new ethers.Wallet(privateKey, provider);

    const routeOutput = await KuruSdk.PathFinder.findBestPath(
        provider,
        baseTokenAddress,
        quoteTokenAddress,
        size
    );

    await KuruSdk.TokenSwap.swap(
        signer,
        routerAddress,
        routeOutput,
        size,
        18,
        18,
        10
    );
})();