Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

@balancer/sdk

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@balancer/sdk

SDK for interacting with the Balancer protocol

Source
npmnpm
Version
0.5.0
Version published
Maintainers
1
Created
Source

SDK

WIP upgrade of the SDK. Not meant for production usage yet and interfaces may have frequent breaking changes until a stable release.

Setup

pnpm install

Requirements

  • fetch

Polyfill

If your platform does not support one of the required features, it is also possible to import a polyfill.

  • fetch -> node-fetch

Testing

Testing requires access to an archive node for onchain quote comparisons. This can be done using Infura.

pnpm test

Balancer Api Provider

The Balancer API Provider is a provider that facilitates data fetching from the Balancer API, it can be used for:

  • Fetch Pool State for AddLiquidity;
  • Fetch Pool State for RemoveLiquidity.

Usage for adding liquidity to a Pool

  import { BalancerApi, AddLiquidity } from "@balancer/sdk";
    ...
    const addLiquidityInput: AddLiquidityProportionalInput = {
      bptOut,
      chainId,
      rpcUrl,
      kind: AddLiquidityKind.Proportional,
    };

    const balancerApi = new BalancerApi('https://backend-v3-canary.beets-ftm-node.com/graphql', 1);
    const poolState = await balancerApi.pools.fetchPoolState('0x5f1d6874cb1e7156e79a7563d2b61c6cbce03150000200000000000000000586');
    const addLiquidity = new AddLiquidity();
    const queryOutput = await addLiquidity.query(addLiquidityInput, poolState);
    const { call, to, value, maxAmountsIn, minBptOut } =
        addLiquidity.buildCall({
            ...queryOutput,
            slippage,
            sender: signerAddress,
            recipient: signerAddress,
        });
    const client = createClient({
      ...
    })
    
    await client.sendTransaction({
      account: signerAddress,
      chain: client.chain,
      data: call,
      to,
      value,
    });

Full working add liquidity example: examples/addLiquidity.ts

Usage for removing liquidity from a Pool

import { BalancerApi, RemoveLiquidity } from "@balancer/sdk";
...
const removeLiquidityInput: RemoveLiquiditySingleTokenInput = {
  chainId,
  rpcUrl,
  bptIn,
  tokenOut,
  kind: RemoveLiquidityKind.SingleToken,
};

const balancerApi = new BalancerApi('https://backend-v3-canary.beets-ftm-node.com/graphql', 1);
const poolState = await balancerApi.pools.fetchPoolState('0x5f1d6874cb1e7156e79a7563d2b61c6cbce03150000200000000000000000586');
const removeLiquidity = new RemoveLiquidity();
const queryOutput = await removeLiquidity.query(removeLiquidityInput, poolState);
const { call, to, value, maxAmountsIn, minBptOut } =
  removeLiquidity.buildCall({
    ...queryOutput,
    slippage,
    sender: signerAddress,
    recipient: signerAddress,
  });
const client = createClient({
  ...
})

await client.sendTransaction({
  account: signerAddress,
  chain: client.chain,
  data: call,
  to,
  value,
});

Full working remove liquidity example: examples/removeLiquidity.ts

Pool Creation

Pool Creation functionality is available for the latest versions of Weighted Pools (V4) and Composable Stable Pools (V5). For usage check our examples:

Anvil client

To download and install the anvil client, run the following commands (MacOS):

  • curl -L https://foundry.paradigm.xyz | bash
  • brew install libusb
  • source /Users/$(whoami)/.zshenv
  • foundryup

For other SO's check https://book.getfoundry.sh/getting-started/installation

FAQs

Package last updated on 15 Dec 2023

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