Skip to main content

Provide Liquidity

Overview

This documentation will guide you through the process of providing liquidity on the Chromatic Protocol.

Prerequisites

Before providing liquidity, ensure that you have completed the following steps:

  • Set up the Chromatic Protocol SDK by following the installation instructions.

Add Liquidity

Providing liquidity in the Chromatic Protocol involves two stages: "Add Liquidity" and "Claim Liquidity".

In the "Add Liquidity" stage, you create a pending liquidity position to contribute liquidity to the market.

To add liquidity to a market, use the addLiquidity method of the ChromaticRouter instance:

  • feeRate : The fee rate of Bin to provide liquidity.
  • amount : The amount of liquidity to add.
const marketAddress = '0x...'
await client
.router()
.addLiquidity(marketAddress, { feeRate: 100, amount: ethers.utils.parseEther('10') });

To provide liquidity to multiple Bins at once, you can use the addLiquidities method of the ChromaticRouter instance:

const marketAddress = '0x...'
await client.router().addLiquidities(marketAddress, [
{ feeRate: 100, amount: ethers.utils.parseEther('5') },
{ feeRate: 200, amount: ethers.utils.parseEther('5') }
]);

The addLiquidity and addLiquidities methods are asynchronous and return Promises. Therefore, you need to use await to wait for the adding liquidity process to complete.

Retrieving the Receipt

Once the transaction is completed, you can retrieve the LP receipt by using the lpReceipts method of the ChromaticLens.

const lpReceipts = await client.lens().lpReceipts(marketAddress);

The lpReceipts method is also asynchronous and returns a Promise that resolves to the receipt of addLiqudity.

Claim Liquidity

Once you finish adding liquidity, you can proceed to claim your liquidity. By doing so, your funds will be added to the liquidity pool, making you an active liquidity provider. This allows you to earn rewards and receive fees based on your contribution.

To claim liquidity for a market after adding liquidity and when the oracle price has been updated, you can use the claimLiquidity method of the ChromaticRouter instance:

  • lpReceiptId: The receipt ID of the addLiquidity transaction
const marketAddress = '0x...';
const lpReceiptId = 1;
await client.router().claimLiquidity(marketAddress, lpReceiptId);

To claim liquidity for multiple receipts at once, you can use the claimLiquidites method of the ChromaticRouter instance:

  • lpReceiptIds: The list of receipt ID of the addLiquidities transaction
const marketAddress = '0x...';
const lpReceiptIds = [1, 2];
await client.router().claimLiquidites(marketAddress, lpReceiptIds);

The claimLiquidity method is asynchronous and returns a Promise, so you need to use await to wait for the claim liquidity process to complete.

Retrieving Liquidity

Once the transaction is completed, you can retrieve your own liquidity using the ownedLiquidityBins method of ChromaticLens:

const marketAddress = '0x...';
const signerAddress = '0x...';
const myBins = await client.lens().ownedLiquidityBins(marketAddress, signerAddress);

The ownedLiquidityBins method is also asynchronous and returns a Promise that resolves to the own liquidity.