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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@x-fuji/sdk

v0.1.0

Published

## Flow

Readme

Fuji SDK

Flow

Init

  // import all chains and chainIds

  // init sdk
  const sdk = new Sdk({
    infuraId: INFURA_ID,
    // If you use streams, then you should set up Alchemy
    // because streams rely on web sockets and Infura doesn't
    // provide ws for its supported chains. On the other side,
    // Alchemy requires a different ID for each chain
    alchemy: {
      1: ETHEREUM_ALCHEMY_ID,
      5: GOERLI_ALCHEMY_ID,
      10: OPTIMISM_ALCHEMY_ID,
      137: POLYGON_ALCHEMY_ID,
      42161: ARBITRUM_ALCHEMY_ID,
      80001: POLYGON_MUMBAI_ALCHEMY_ID,
    },
    // `poktId` is optional, but if provided, it will take precedence over Infura
    poktId: POKT_ID
  });

Chains and tokens selection

For collateral

  // user selects chainA or chainA is selected by default
  // fetch collateral tokens available on chainA

  const collaterals = sdk.getCollateralForChain(chainId);

  // get balances of the user for each of the token
  const balancesCollateral = await sdk.getBatchTokenBalances(collaterals, account, chainId);

  // user selects a "token1" as collateral

For debt

  // user selects chainB or chainB is selected by default
  // fetch debt tokens available on chainB

  const debts = sdk.getDebtForChain(chainId);

  // get balances of the user for each of the token
  const balancesDebt = await sdk.getTokenBalancesFor(debts, account, chainId);

  // user selects a "token2" as debt

Vault data

Vault is an instance on a single chain, i.e. its collateral and debt token are from the same chain.

  1. Get all "Vault" for a given combo of tokens
  const vaultsResult = await sdk.getBorrowingVaultsFor(token1, token2);
  if (vaultsResult.success) {
    const vaults = vaultsResult.data;
    // vaults are sorted, starting by this with the lowest borrow rate
    // or if token1 and token2 are on the same chain, the first vault will
    // be on that chain

    const vault = vaults[0];
  }
  1. Pre-load some data for the vault so that it's available for a later use
  await vault.preLoad();

  // pre-load makes available vault.maxLtv and vault.liqRatio
  // that can be used to calculate health ratio and
  // liquidation price based on the amounts inputs below
  1. Get user deposit and borrow balances for this Vault
  const balanacesResult = await vault.getBalances(user);
  if (balanacesResult.success) {
    ...
    const { deposit, borrow } = balanacesResult.data;

    // if they are not 0, they have to be used in the health ratio and liquidation price math,
    // together with the amouts that the user has input
  }
  1. Get prices of collateral and debt token in $
  const [collateralResult, debtResult] = Promise.all([token1.getPriceUSD(), token2.getPriceUSD()]);
  if (collateralResult.success) {
    ...
  }
  1. fetch providers for this vault and their rates
  const providers = await vault.getProviders();

Amounts

  // user inputs "amount1" and "amount2"

  // check if there's enough allowance for token1 and amount1

  await sdk.getAllowanceOf(token1, user);
  if (needApproval) {
    // approve token1
  }

Transaction

  // Note: cost and estimateTime are hardcoded
  const { steps, actions, bridgeFees, estimateTime } = await sdk.previews.get({
    name: PreviewName.DEPOSIT_AND_BORROW,
    vault,
    srcChainId,
    amountIn: amount1,
    amountOut: amount2,
    tokenIn: token1,
    tokenOut: token2,
    account: user
  });

  // verify if user needs to sign a permit
  if (Sdk.needPermit(actions)) {
    const permitAction = Sdk.findPermitAction(actions)

    // signing the permit action has to be done through the vault
    const { domain, types, value } = await vault.signPermitFor(permitAction)

    const signature = await signer.signMessage(domain, types, value)
  }

  const result = await sdk.getTxDetails(actions, srcChainId, user, signature?);
  if (!result.success) {
    // display error
  }
  const txRequest = result.data;
  const tx = await signer.sendTransaction(txRequest);
  const receipt = await tx.wait();

  if (isCrossChain) {
    // poll every N seconds the following method to get the destination transaction hash
    const result = await sdk.getConnextTxDetails(srcChainId, receipt.transactionHash);
    if (!result.success) {
      // display error
      return;
    }
    if (result.data.status === PENDING || result.data.status === UNKNOWN) {
      // poll again
    }
  }