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

@sovryn/sdk

v2.0.4

Published

## Installation

Downloads

97

Readme

Sovryn SDK

Installation

yarn add @sovryn/sdk @sovryn/contracts @sovryn/ethers-provider ethers @ethersproject/providers @ethersproject/abstract-provider

Smart Router

Smart router is a wrapper around the smart contracts that allows you to interact with the smart contracts for swapping tokens in a more convenient way.

Usage

import { SmartRouter, DEFAULT_SWAP_ROUTES } from '@sovryn/sdk';
import { getProvider } from '@sovryn/ethers-provider';

// Get ethers provider
const provider = getProvider();

// Create a new instance of the smart router, passing the provider and the swap routes to use
const smartRouter = new SmartRouter(provider, DEFAULT_SWAP_ROUTES);

// Get token addresses we want to swap
const xusdToken = '0xb5999795BE0EbB5bAb23144AA5FD6A02D080299F';
const sovToken = '0xEFc78fc7d48b64958315949279Ba181c2114ABBd';
const amount = 100;

// Get the best swap route for a token pair
// result contains the best route and the amount of tokens we will get
// { route: SwapRoute, quote: BigNumber }
const result = await smartRouter.getBestQuote(ChainIds.RSK_MAINNET, xusdToken, sovToken, amount);

// Check if we need to permit xusd token to be able to swap
// permitTxData will return the permit data to be signed by the user
const permitTxData = await result.route.permit(xusdToken, sovToken, amount)
let signedPermit: string | undefined;
if (permitTxData) {
  // ask user to sign the transaction with permitTxData as data
  signedPermit = await signPermit(permitTxData);
}

// If permit is possible and approval is not required, we can skip the approval step
if (!permitTxData || permitTxData?.approvalRequired) {
  // Check if we need to approve xusd token to be able to swap
  // approveTxData will return the transaction data to be signed by the user
  // In most cases it will only have `to` and `data` fields
  const approveTxData = await result.route.approve(xusdToken, sovToken, amount)
  if (approveTxData) {
    // ask user to sign the transaction with approveTxData as data
  }
}

// Swap tokens
const txData = await result.route.swap(xusdToken, sovToken, amount, {
  // pass the permit data if permit is required
  typedDataValue: permitTxData?.typedData?.values,
  // pass signature if permit is required
  typedDataSignature: signedPermit,
});

// Sign the transaction with the user wallet of your choosing and send it to the network
const tx = await signAndSend(txData);