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

defi-toolbox

v0.0.0

Published

Small TypeScript library allowing easy local deployment of some common defi components.

Readme

Overview

Small TypeScript library allowing easy local deployment of some common defi components. Currently the library supports:

  • WETH
  • DAI
  • USDC (currently mocked with an ERC20)
  • Uniswap V2

For all components (except for USDC) the code was taken directly from etherscan.

Installation

Run:

npm install <TODO AFTER RELEASING PACKAGE>

Usage

Say you want to get a local deployment with WETH, DAI and UniswapV2 and swap 10 WETH for DAI. You can do this as follows:

  1. Fire up ganache. Note that the --chain.allowUnlimitedContractSize is needed tor the deployment of UniswapV2 (runs out of gas with the default ganache config).
ganache -p 8545 --chain.allowUnlimitedContractSize

And from another terminal fire up Node and try the following:

// Get an instance of the DefiToolbox. The toolbox is connected to the local ganache instance.
const { DefiToolbox } = require(".");
const tb = new DefiToolbox("http://localhost:8545");

// Get an instance of WETH. Note that this automatically deploys the contract to the local
// ganache instance on the first invocation. 
const weth = await tb.weth();
// weth is an instance of TruffleContract.

// Use the first account from web3.eth.getAccounts() as sender
const sender = await tb.firstAccount();

// Deposit some ETH in WETH
await weth.deposit({value: 1000000, from: sender });


// Get an instance of DAI. Note that we pass sender to the DAI constructor, so that sender
// is authorized to mint
const dai = await tb.dai(sender);

// Mint some dai to sender
await dai.mint(sender, 100000, { from: sender })

// Now get the UniswapV2 router. Note all deployment helpers have an implicit "sender"
// argument, that is the first account by default.
const router = await tb.uniswapV2Router();

// Now give the WETH/DAI pair some initial liquidity.
// The "2000000000" is some arbitrary deadline the future.
await dai.approve(router.address, 10000, { from: sender });
await weth.approve(router.address, 10000, { from: sender });
await router.addLiquidity(weth.address, dai.address, 10000, 10000, 0, 0, sender, 2000000000, { from: sender })

// Get WETH/DAI balances before the swap
const wethBefore = (await weth.balanceOf(sender)).toNumber();
const daiBefore = (await dai.balanceOf(sender)).toNumber();

console.error(`Before swap balance of ${sender}: WETH: ${wethBefore} DAI: ${daiBefore}`);

// Allow the router to spend 10 wei
await weth.approve(router.address, 10, { from: sender });

// Swap weth for dai
await router.swapExactTokensForTokens(
    10,
    0,
    [weth.address, dai.address],
    sender,
    2000000000,
    {
	from: sender
    }
);


// Get WETH/DAI balances after the swap
const wethAfter = (await weth.balanceOf(sender)).toNumber();
const daiAfter = (await dai.balanceOf(sender)).toNumber();

console.error(`After swap balance of ${sender}: WETH: ${wethAfter} DAI: ${daiAfter}`);
// Should print something like
// After swap balance of <sender>: WETH: 989990 DAI: 90009