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

@wardenswap/bestrate-sdk-beta

v2.8.0

Published

- Update src/config.ts to add more tables

Downloads

242

Readme

WardenSwap Best Rate Query SDK

An JavaScript/TypeScript SDK library for querying trading quotes from WardenSwap platform. In order to begin trading on WardenSwap, we need the trading path that provide the best rate. The SDK help finding the path with ease!

For more information, check out our documentation here: https://docs.wardenswap.finance/warden/wardenswap-sdk/overview

Installation

# For NPM
npm install @wardenswap/bestrate-sdk-private

# For Yarn
yarn add @wardenswap/bestrate-sdk-private

Example

Here is the example if JavaScript code for querying best rate and perform a simple swap via WardenSwap SDK.

// npm install @wardenswap/bestrate-sdk-private ethers
const { WardenBestRate } = require('@wardenswap/bestrate-sdk-private')
const { ethers } = require('ethers')

// WardenRouter_2_0.abi.json can be found here: https://gist.github.com/AncientWarden/4aeae54509dd21020ab29a13c804cb57
// or BSCScan: https://bscscan.com/address/0x451ef8D6B645a60115EB8b8bEa76B39C0C761004#code
const wardenRouterAbi = require('./WardenRouter_2_0.abi.json')

const WARDEN_ROUTER_ADDRESS = '0x451ef8D6B645a60115EB8b8bEa76B39C0C761004'

const src = '0xe9e7cea3dedca5984780bafc599bd69add087d56' // source Token Address: BUSD
const dest = '0x0feadcc3824e7f3c12f40e324a60c23ca51627fc' // destination Token Address: WAD
const amountIn = ethers.utils.parseUnits('10', 18) // 10 BUSD in BigNumber
const gasFee = ethers.BigNumber.from('5000000000') // default BSC gas fee for rate calculation
const options = { enableSplit: false } // calculate without using split trades

// initialize provider, requires version of ether.js >= 5.4.0
const provider = new ethers.providers.JsonRpcProvider('https://bsc-dataseed.binance.org')

async function getQuote() {
    // initialize the warden client
    const wardenClient = new WardenBestRate(provider, 'bsc')

    // get the quote detail with warden client
    const quote = await wardenClient.getQuote(src, dest, amountIn, gasFee, options)
    console.log('quote:', quote)

    return quote
}

async function swap(quote) {
    // add the acceptable slippage of 1% to amountOut
    // since the actual amount can be lower or higher.
    const minAmountOut = ethers.BigNumber.from(quote.amountOut).mul(99).div(100)

    // Get the signer with private key
    // For using with Metamask, see: https://docs.ethers.io/v5/getting-started/#getting-started--connecting
    const signer = new ethers.Wallet(YOUR_PRIVATE_KEY, provider)
    const wardenContract = new ethers.Contract(WARDEN_ROUTER_ADDRESS, wardenRouterAbi, signer)

    // send a swap transaction to warden contract
    const swapTx = await wardenContract.swap(
        quote.swapAddress,
        quote.data,
        quote.depositAddress,
        src,
        amountIn,
        dest,
        minAmountOut,
        signer.address, // dest token receiver
        0, // Partner ID for profit sharing, default to 0
        0) // metadata, reserved for future use

    console.log(`swap tx successfully submitted, tx hash: ${swapTx.hash}`)
}

getQuote().then(quote => swap(quote))