Skip to content

SDK for simulating the exact on-chain behaviour of various Balancer V2 pools

Notifications You must be signed in to change notification settings

sergioyuhjtman/balancer-v2-pools

 
 

Repository files navigation

balancer-v2-pools


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

NPM

Usage instructions

import { WeightedPool } from "@georgeroman/balancer-v2-pools";

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 definitions (the given block number must include the instances of the pools used in the tests):

RPC_URL=
BLOCK_NUMBER=

The setup I recommend for deterministic tests is the following:

RPC_URL=https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_KEY}
BLOCK_NUMBER=13128465

To execute the tests locally, simply run:

# Install dependencies
npm install

# Run tests
npm test

About

SDK for simulating the exact on-chain behaviour of various Balancer V2 pools

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Solidity 53.2%
  • TypeScript 46.8%