Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@uniswap/v2-core
Advanced tools
@uniswap/v2-core is a core smart contract library for the Uniswap V2 decentralized exchange protocol. It provides the essential building blocks for creating and managing liquidity pools, executing swaps, and handling token pairs on the Ethereum blockchain.
Liquidity Pool Creation
This feature allows users to create a new liquidity pool for a pair of ERC-20 tokens. The code sample demonstrates how to interact with the Uniswap V2 Factory contract to create a new token pair.
const { ethers } = require('ethers');
const UniswapV2Factory = require('@uniswap/v2-core/build/UniswapV2Factory.json');
async function createPair(factoryAddress, tokenA, tokenB) {
const provider = new ethers.providers.JsonRpcProvider();
const wallet = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);
const factory = new ethers.Contract(factoryAddress, UniswapV2Factory.abi, wallet);
const tx = await factory.createPair(tokenA, tokenB);
await tx.wait();
console.log('Pair created:', await factory.getPair(tokenA, tokenB));
}
Swapping Tokens
This feature enables token swapping through the Uniswap V2 protocol. The code sample shows how to use the Uniswap V2 Router to swap a specific amount of input tokens for a minimum amount of output tokens along a specified path.
const { ethers } = require('ethers');
const UniswapV2Router02 = require('@uniswap/v2-periphery/build/UniswapV2Router02.json');
async function swapTokens(routerAddress, amountIn, amountOutMin, path, to, deadline) {
const provider = new ethers.providers.JsonRpcProvider();
const wallet = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);
const router = new ethers.Contract(routerAddress, UniswapV2Router02.abi, wallet);
const tx = await router.swapExactTokensForTokens(amountIn, amountOutMin, path, to, deadline);
await tx.wait();
console.log('Swap executed');
}
Retrieving Pair Information
This feature allows users to retrieve information about a specific liquidity pair, such as the current reserves of the two tokens. The code sample demonstrates how to access the reserves of a Uniswap V2 pair contract.
const { ethers } = require('ethers');
const UniswapV2Pair = require('@uniswap/v2-core/build/UniswapV2Pair.json');
async function getReserves(pairAddress) {
const provider = new ethers.providers.JsonRpcProvider();
const pair = new ethers.Contract(pairAddress, UniswapV2Pair.abi, provider);
const reserves = await pair.getReserves();
console.log('Reserves:', reserves);
}
SushiSwap is a decentralized exchange that started as a fork of Uniswap. It offers additional features like yield farming and staking, alongside the core functionalities of creating liquidity pools and token swaps. SushiSwap aims to provide more community-driven governance and incentives.
In-depth documentation on Uniswap V2 is available at uniswap.org.
The built contract artifacts can be browsed via unpkg.com.
The following assumes the use of node@>=10
.
yarn
yarn compile
yarn test
FAQs
🎛 Core contracts for the UniswapV2 protocol
We found that @uniswap/v2-core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.