Giter Club home page Giter Club logo

b-sdk's Introduction

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.

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: RemoveLiquiditySingleTokenExactInInput = {
  chainId,
  rpcUrl,
  bptIn,
  tokenOut,
  kind: RemoveLiquidityKind.SingleTokenExactIn,
};

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 And Initialization

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

For usage of Pool Initialization check our example:

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

b-sdk's People

Contributors

brunoguerios avatar johngrantuk avatar mikemcdonald avatar danielmkm avatar agualis avatar lgahdl avatar github-actions[bot] avatar franzns avatar gmbronco avatar thal0x avatar

Stargazers

Jircs$1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.