# Liquidity Providers

### LiquidityProviderTool ⇐ `WriteAccessHandler`

Functions to provide liquidity. This class requires a private key and executes smart-contract interactions that require gas-payments.

**Kind**: global class\
**Extends**: `WriteAccessHandler`

* [LiquidityProviderTool](broken://pages/Df6ut8P2q6xBQ3nLpIsw) ⇐ `WriteAccessHandler`
  * [new LiquidityProviderTool(config, signer)](broken://pages/Df6ut8P2q6xBQ3nLpIsw)
  * [.addLiquidity(poolSymbolName, amountCC)](broken://pages/Df6ut8P2q6xBQ3nLpIsw) ⇒
  * [.initiateLiquidityWithdrawal(poolSymbolName, amountPoolShares)](broken://pages/Df6ut8P2q6xBQ3nLpIsw) ⇒
  * [.executeLiquidityWithdrawal(poolSymbolName)](broken://pages/Df6ut8P2q6xBQ3nLpIsw) ⇒

#### new LiquidityProviderTool(config, signer)

Constructor

| Param  | Type                 | Description                                                    |
| ------ | -------------------- | -------------------------------------------------------------- |
| config | `NodeSDKConfig`      | Configuration object, see PerpetualDataHandler. readSDKConfig. |
| signer | `string` \| `Signer` | Private key or ethers Signer of the account                    |

**Example**

```js
import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
async function main() {
  console.log(LiquidityProviderTool);
  // load configuration for Polygon zkEVM (testnet)
  const config = PerpetualDataHandler.readSDKConfig("cardona");
  // LiquidityProviderTool (authentication required, PK is an environment variable with a private key)
  const pk: string = <string>process.env.PK;
  let lqudtProviderTool = new LiquidityProviderTool(config, pk);
  // Create a proxy instance to access the blockchain
  await lqudtProviderTool.createProxyInstance();
}
main();
```

#### liquidityProviderTool.addLiquidity(poolSymbolName, amountCC) ⇒

Add liquidity to the PnL participant fund. The address gets pool shares in return.

**Kind**: instance method of [`LiquidityProviderTool`](broken://pages/Df6ut8P2q6xBQ3nLpIsw)\
**Returns**:

Transaction object

| Param          | Type     | Description                        |
| -------------- | -------- | ---------------------------------- |
| poolSymbolName | `string` | Name of pool symbol (e.g. MATIC)   |
| amountCC       | `number` | Amount in pool-collateral currency |

**Example**

```js
import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
async function main() {
  console.log(LiquidityProviderTool);
  // setup (authentication required, PK is an environment variable with a private key)
  const config = PerpetualDataHandler.readSDKConfig("cardona");
  const pk: string = <string>process.env.PK;
  let lqudtProviderTool = new LiquidityProviderTool(config, pk);
  await lqudtProviderTool.createProxyInstance();
  // add liquidity
  await lqudtProviderTool.setAllowance("MATIC");
  let respAddLiquidity = await lqudtProviderTool.addLiquidity("MATIC", 0.1);
  console.log(respAddLiquidity);
}
main();
```

#### liquidityProviderTool.initiateLiquidityWithdrawal(poolSymbolName, amountPoolShares) ⇒

Initiates a liquidity withdrawal from the pool It triggers a time-delayed unlocking of the given number of pool shares. The amount of pool shares to be unlocked is fixed by this call, but not their value in pool currency.

**Kind**: instance method of [`LiquidityProviderTool`](broken://pages/Df6ut8P2q6xBQ3nLpIsw)\
**Returns**:

Transaction object.

| Param            | Type     | Description                                                      |
| ---------------- | -------- | ---------------------------------------------------------------- |
| poolSymbolName   | `string` | Name of pool symbol (e.g. MATIC).                                |
| amountPoolShares | `string` | Amount in pool-shares, removes everything if > available amount. |

**Example**

```js
import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
async function main() {
  console.log(LiquidityProviderTool);
  // setup (authentication required, PK is an environment variable with a private key)
  const config = PerpetualDataHandler.readSDKConfig("cardona");
  const pk: string = <string>process.env.PK;
  let lqudtProviderTool = new LiquidityProviderTool(config, pk);
  await lqudtProviderTool.createProxyInstance();
  // initiate withdrawal
  let respRemoveLiquidity = await lqudtProviderTool.initiateLiquidityWithdrawal("MATIC", 0.1);
  console.log(respRemoveLiquidity);
}
main();
```

#### liquidityProviderTool.executeLiquidityWithdrawal(poolSymbolName) ⇒

Withdraws as much liquidity as there is available after a call to initiateLiquidityWithdrawal. The address loses pool shares in return.

**Kind**: instance method of [`LiquidityProviderTool`](broken://pages/Df6ut8P2q6xBQ3nLpIsw)\
**Returns**:

Transaction object.

| Param          |
| -------------- |
| poolSymbolName |

**Example**

```js
import { LiquidityProviderTool, PerpetualDataHandler } from '@d8x/perpetuals-sdk';
async function main() {
  console.log(LiquidityProviderTool);
  // setup (authentication required, PK is an environment variable with a private key)
  const config = PerpetualDataHandler.readSDKConfig("cardona");
  const pk: string = <string>process.env.PK;
  let lqudtProviderTool = new LiquidityProviderTool(config, pk);
  await lqudtProviderTool.createProxyInstance();
  // remove liquidity
  let respRemoveLiquidity = await lqudtProviderTool.executeLiquidityWithdrawal("MATIC", 0.1);
  console.log(respRemoveLiquidity);
}
main();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://d8x.gitbook.io/d8x/node-sdk/modules/liquidity-providers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
