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

@onmychain/hardhat-uniswap-v2-deploy-plugin

v1.0.4

Published

Simple Hardhat plugin that allows you to deploy UniswapV2 (Factory, Router, WETH9) to your network.

Downloads

350

Readme

Build Node.js Package

hardhat-uniswap-v2-deploy-plugin

Simple hardhat plugin that allows you to deploy UniswapV2 (Factory, Router, WETH9) to your network.

Hardhat plugin.

What

This plugin extends your Hardhat Runtime Environment, allowing you to deploy in one command the full UniswapV2 stack (Factory, Router, WETH9). You can use it to test features such as pair creation, liquidity provisioning, and swaps.

Additionally, you can use the Interfaces (IUniswapV2Factory, IUniswapV2Router, and IUniswapV2Pair) to communicate directly with testnet / mainnet.

Feedback, improvment suggestions are welcome.

Installation

Install the plugin.

npm install --save-dev @onmychain/hardhat-uniswap-v2-deploy-plugin

or

yarn add --dev @onmychain/hardhat-uniswap-v2-deploy-plugin

Import the plugin in your hardhat.config.js:

require("@onmychain/hardhat-uniswap-v2-deploy-plugin");

Or if you are using TypeScript, in your hardhat.config.ts:

import "@onmychain/hardhat-uniswap-v2-deploy-plugin";

Environment extensions

The UniswapV2Deployer extension allows you to deploy the UniswapV2 stack on your network.

This plugin extends the Hardhat Runtime Environment by adding an UniswapV2Deployer field whose type is UniswapV2Deployer.

Usage

It's so easy.

import { ethers, UniswapV2Deployer } from "hardhat"

async function main() {
  [signer] = await this.hre.ethers.getSigners();
  const deployer = new UniswapV2Deployer();
  const { factory, router, weth9 } = await deployer.deploy(signer);

  // Now you can interact with the different UniswapV2 contracts
  // ...
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

There are no additional steps you need to take for this plugin to work.

Detailed Usage Example

Please see protect.test.ts file. It shows you how to deploy and interact with the contracts i.e. adding liquidity, swapping tokens.

Below is a full example of the usage.

const [signer] = await ethers.getSigners()
const { weth9, factory, router } = await UniswapV2Deployer.deploy(signer)
const Token = await ethers.getContractFactory("Token")
const token = await Token.deploy(eth(1000))
await token.deployed()

await weth9.approve(router.address, eth(1000))
await token.approve(router.address, eth(1000))

await router.addLiquidityETH(
    token.address,
    eth(1000),
    eth(1000),
    eth(100),
    signer.address,
    constants.MaxUint256,
    { value: eth(1000) }
)

await router.swapExactETHForTokens(
    0,
    [weth9.address, token.address],
    signer.address,
    constants.MaxUint256,
    { value: eth(1) }
);