New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@georgeroman/balancer-v2-pools

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@georgeroman/balancer-v2-pools

<code>balancer-v2-pools</code>

  • 0.0.2
  • npm
  • Socket score

Version published
Weekly downloads
130
decreased by-49.61%
Maintainers
1
Weekly downloads
 
Created
Source

balancer-v2-pools


Simple SDK for simulating the exact on-chain behaviour of various Balancer v2 pools.

Usage instructions

const pool = await WeightedPool.initFromRealPool(
  // WETH/DAI 60/40 on Mainnet
  "0x0b09dea16768f0799065c475be02919503cb2a3500020000000000000000001a"
);

// Swap
const amountOut = pool.swapGivenIn("WETH", "DAI", "100");

// Join
const bptOut = pool.joinExactTokensInForBptOut({
  WETH: "1",
  DAI: "2000",
});

// Exit
const tokensOut = pool.exitExactBptInForTokensOut("1.23");

Setup instructions

Mainnet forking is used for testing in order to make sure the SDK exactly match the EVM. Make sure to have a .env file in the root directory, containing the following:

RPC_URL=
BLOCK_NUMBER=

The setup I recommend for deterministic tests is the following:

For Mainnet (eg. weighted pools):

RPC_URL=https://eth-mainnet.alchemyapi.io/v2/ALCHEMY_KEY
BLOCK_NUMBER=12552900

For Kovan (eg. stable pools):

RPC_URL=https://eth-kovan.alchemyapi.io/v2/ALCHEMY_KEY
BLOCK_NUMBER=25880708

To execute the tests locally, simply run:

# Install dependencies
npm install

# Run tests
npm test

Note that for now, the stable pool tests use Kovan instances, while the weighted pool tests use Mainnet instances. Since we're using network forking for running the tests, this implies that it's not possible to run the stable pool and weighted pool tests at the same time. Once the stable pool get deployed to Mainnet, this will get fixed but in the meantime you have to use different .env files, one linking to Kovan and another linking to Mainnet.

To execute selected tests only, run:

npm test -- ./test/weighted/math.ts ./test/weighted/pool.ts

Keywords

FAQs

Package last updated on 07 Jul 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc