WIP upgrade of the SDK. Not meant for production usage yet and interfaces may have frequent breaking changes until a stable release.
pnpm install
fetch
If your platform does not support one of the required features, it is also possible to import a polyfill.
fetch
-> node-fetch
Testing requires access to an archive node for onchain quote comparisons. This can be done using Infura.
pnpm test
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.
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
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 functionality is available for the latest versions of Weighted Pools (V4) and Composable Stable Pools (V5). For usage of Pool Creation check our examples:
- Weighted Pool Creation (V4)examples/createPoolWeighted.ts
- Composable Stable Pool Creation (V5)examples/createPoolComposableStable.ts
For usage of Pool Initialization check our example:
- Pool Initialization examples/createPoolComposableStable.ts
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