Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
@balancer-labs/balancer-js
Advanced tools
Readme
Balancer.js is a JavaScript SDK which provides commonly used utilities for interacting with the V2 Balancer Protocol. It is especially useful for working with different kinds of data that must be supplied in encoded form, such as the userData
for joins and exits, or extracting information from data encoded by the protocol, such as the Pool IDs. Each subdirectory contains utilities for working with a particular module. Utils contains general utilities, such as helpers for working with signatures, and mapping encoded smart contract error codes to text.
$ npm install @balancer-labs/balancer-js
Some examples of common uses for Balancer.js are shown below
Each Balancer pool is referenced by its own unique pool ID. This ID contains various information about the pool in an encoded form. Balancer.js exposes functions to easily extract various information from this ID.
Sample code that calculates a pool's address from its pool ID to allow approving another address to move the user's BPT:
import { getPoolAddress } from "@balancer-labs/balancer-js";
import { IERC20Abi } from ./IERC20.json
const poolId = "0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014"
const poolAddress = getPoolAddress(poolId)
// poolAddress = "0x5c6ee304399dbdb9c8ef030ab642b10820db8f56"
const bptToken = new Contract(poolAddress, IERC20Abi, provider)
await bptToken.approve("0x012345....", "10000")
To provide liquidity to a Balancer pool, various fields must be provided in an encoded form as the userData
field within the joinPool
call. Balancer.js exposes functions to simplify encoding the userData
field used for joining and exiting various pool types to prevent errors. Similar utilities are available for exitPool
. Note that different pool types may support a different set of join and exit calls, so make sure you're using the correct encoder.
Sample code that provides the initial liquidity to a WeightedPool:
import { WeightedPoolEncoder } from "@balancer-labs/balancer-js";
const poolId = "0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014"
const tokens = ["0x012345....", "0x789ABC...."]
const amountsIn = [BigNumber.from("10000"), BigNumber.from("10000")];
const tx = await vault.joinPool(
poolId,
userAddress,
userAddress,
{
assets: tokens,
maxAmountsIn: amountsIn,
fromInternalBalance: true,
userData: WeightedPoolEncoder.joinInit(amountsIn),
}
);
FAQs
JavaScript utilities for interacting with the Balancer Protocol V2
The npm package @balancer-labs/balancer-js receives a total of 117 weekly downloads. As such, @balancer-labs/balancer-js popularity was classified as not popular.
We found that @balancer-labs/balancer-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.