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

kaidex-sdk

v0.2.2

Published

KaiDex SDK is a javascript library designed to help interact with KaiDex. It provides tools and utilities to convert clients' input params into KaiDex's smart contract compatible arguments. From which developers can freely build their own applications o

Downloads

3

Readme

Introduction

KaiDex SDK is a javascript library designed to help interact with KaiDex. It provides tools and utilities to convert clients' input params into KaiDex's smart contract compatible arguments. From which developers can freely build their own applications on top of KaiDex.

I. Install

npm

  npm install kaidex-sdk

yarn

  yarn add kaidex-sdk

From source

  npm install https://github.com/kardiachain/kaidex-sdk

II. Usage

Quick start:

Initially, please provide required endpoints for all the KaiDex smart contracts:

Constructor params: KaidexOptions

import KaidexClient from 'kaidex-sdk';

const kaidexClient = new KaidexClient({
    smcAddresses: {
        router: ROUTER_SMC_ADDRESS,
        limitOrder: LIMIT_ORDER_SMC_ADDRESS,
        factory: FACTORY_SMC_ADDRESS,
        wkai: WKAI_SMC_ADDRESS
    },
    rpcEndpoint: RPC_ENDPOINT
})

2.1 Transactions:

To create transactions in KaiDex SMC, please provide required input-parameters for each method. The client will return processed data, including methodName, arguments, KaiAmount, which is then used to interact with corresponding ABI via kaidexClient.invokeSMC() method.

Invoke SMC: kaidexClient.invokeSMC()

Add liquidity: kaidexClient.addLiquidityCallParameters()

const { methodName, args, amount } = kaidexClient.addLiquidityCallParameters({
    inputAmount,
    outputAmount,
    tokenA,
    tokenB,
    walletAddress,
    slippageTolerance,
    txDeadline
})

const txResponse = await kaidexClient.invokeSMC({
    abi: kaidexClient.abis.router,
    smcAddr: kaidexClient.smcAddresses.router,
    methodName: methodName,
    params: args,
    amount: amount
})

Remove liquidity: kaidexClient.removeLiquidityCallParameters()

const { methodName, args, amount } = await kaidexClient.removeLiquidityCallParameters({
    pair,
    withdrawAmount,
    walletAddress,
    slippageTolerance,
    txDeadline,
})

const txResponse = await kaidexClient.invokeSMC({
    abi: kaidexClient.abis.router,
    smcAddr: kaidexClient.smcAddresses.router,
    methodName: methodName,
    amount: amount,
    params: args
})

Swap tokens: kaidexClient.marketSwapCallParameters

const { methodName, args, amount } = kaidexClient.marketSwapCallParameters({
    amountIn,
    amountOut,
    inputToken,
    outputToken,
    addressTo,
    inputType,
    txDeadline,
    slippageTolerance
})

const txResponse = await kaidexClient.invokeSMC({
    abi: this.abis.router,
    smcAddr: this.smcAddresses.router,
    methodName,
    amount,
    params: args
})

2.2 Utils:

Get token balance: kaidexClient.getTokenBalance()

  • params:
tokenAddress: string
walletAddress: string
const tokenBalance = await kaidexClient.getTokenBalance(tokenAddress, walletAddress)

Check token's approval state: kaidexClient.getApprovalState()

  • params:
tokenAddr: string;
decimals: number;
walletAddress: string;
spenderAddress: string;
amountToCheck: number | string;
const isApproved = await kaidexClient.getApprovalState({
    tokenAddr,
    decimals,
    walletAddress, 
    spenderAddress,
    amountToCheck
})

Check price impact: kaidexClient.calculatePriceImpact()

const priceImpact = await kaidexClient.calculatePriceImpact(inputToken, outputToken, amountIn, amountOut)

Check pair's reserves: kaidexClient.getReverses()

  • params:
tokenA: string
tokenB: string
const { reserveA, reserveB } = await kaidexClient.getReverses(tokenA, tokenB)

Calculate output amount: kaidexClient.calculateOutputAmount()

const outputAmount = await kaidexClient.calculateOutputAmount(amount, inputToken, outputToken, inputType)

III. Types:

Usage

import {
    KaidexOptions,
    Token,
    PooledTokens,
    LiquidityPair,
    SMCParams,
    InputParams
} from 'kaidex-sdk'

Kaidex Options

interface KaidexOptions {
    rpcEndpoint?: string;
    abis?: ABIS;
    smcAddresses?: SmcAddresses;
}

interface ABIS {
    factory?: any;
    krc20?: any;
    limitOrder?: any;
    router?: any;
}

interface SmcAddresses {
    router?: string;
    factory?: string;
    limitOrder?: string;
    wkai?: string;
}

Token and pair

interface Token {
  tokenAddress: string;
  name: string;
  symbol: string;
  decimals: number;
}

interface PooledTokens {
  reserveA: string;
  reserveB: string;
}

interface LiquidityPair {
    balance: string;
    name: string;
    pairAddress: string;
    tokenA: Token;
    tokenB: Token;
    provider: string;
    pooledTokens: PooledTokens;
}

Enum

enum TradeType {
    BUY = 0,
    SELL = 1,
}

enum InputType {
    EXACT_IN = 0,
    EXACT_OUT = 1,
}

SMCParams

namespace SMCParams {
  interface CallParams {
    methodName: string;
    args: (string | string[] | number)[];
    amount?: number | string;
  }

  interface InvokeParams {
    abi: any;
    smcAddr: string;
    methodName: string;
    params: (string | string[] | number)[];
    amount?: number;
    gasLimit?: number;
    gasPrice?: number;
  }
}

InputParams

namespace InputParams {
    interface CalculateOutputAmount {
        amount: number | string;
        inputToken: Token;
        outputToken: Token;
        inputType: InputType;
    }

    interface CalculatePriceImpact {
        inputToken: Token;
        outputToken: Token;
        amountIn: string;
        amountOut: string;
    }

    interface AddLiquidity {
        inputAmount: string | number;
        outputAmount: string | number;
        tokenA: Token;
        tokenB: Token;
        walletAddress: string;
        slippageTolerance: string | number;
        txDeadline: number;
    }

    interface RemoveLiquidity {
        pair: LiquidityPair;
        withdrawAmount: string;
        walletAddress: string;
        slippageTolerance: string | number;
        txDeadline: number;
    }

    interface MarketSwap {
        amountIn: string;
        amountOut: string;
        inputToken: Token;
        outputToken: Token;
        addressTo: string;
        inputType: InputType;
        txDeadline: number;
        slippageTolerance: string | number;
    }
}