# Defi Module

Defi module handles operations related to DeFi protocols, including farms and whitelisted tokens.

To learn more about how to use the AI Agent SDK to interact with the wallet module, please visit [AI Agent SDK Defi Operations](/crypto.com-ai-agent-sdk/core-concepts-overview/blockchain-functions/defi-operations.md).

#### 7.1 Get Whitelisted Tokens

Fetches whitelisted tokens for a specific DeFi protocol.

{% tabs %}
{% tab title="Python" %}
Function Name

```python
get_whitelisted_tokens
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```python
  protocol (DefiProtocol): The DeFi protocol (e.g., DefiProtocol.H2, DefiProtocol.VVS)
  ```
* Example Code

  ```python
  from crypto_com_developer_platform_client import Defi, DefiProtocol

  tokens = Defi.get_whitelisted_tokens(DefiProtocol.H2)
  print(tokens)
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```python
  List of whitelisted tokens for the project.
  ```
* Example Return

  ```python
  {'status': 'Success', 'data': [{'id': example-id, 'name': 'example-name', 'symbol': 'example-symbol', 'address': 'example-address', 'decimal': example-decimal, 'link': 'example-link', 'isSwappable': example-boolean, 'logoImagePngUrl': 'example-url', 'logoImageSvgUrl': 'example-url', 'chain': 'example-chain-name', 'chainId': example-chain-id}, ... ]}
  ```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="TypeScript" %}
Function Name

```typescript
getWhitelistedTokens
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```typescript
  {DefiProtocol} protocol: The DeFi protocol to fetch tokens for.
  ```
* Example Code

  ```typescript
  import { Defi, DefiProtocol } from '@crypto.com/developer-platform-client';

  try {
    const tokens = await Defi.getWhitelistedTokens(DefiProtocol.H2);
    console.log(tokens);
  }
    catch(err) {
    console.log(err);
  }
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```typescript
  {Promise<ApiResponse<WhitelistedToken[]>>}: A promise that resolves to the whitelisted tokens.
  ```
* Errors

  ```typescript
  {Error}: Throws an error if the request fails.
  ```
* Example Return

  ```typescript
  {
    status: 'Success',
    data: [
      {
        id: example-id,
        name: example-name,
        symbol: 'example-symbol,
        address: example-address,
        decimal: example-decimal,
        link: example-link,
        isSwappable: example-boolean,
        logoImagePngUrl: example-url,
        logoImageSvgUrl: example-url,
        chain: example-chain-name,
        chainId: example-chain-id
      }
      ...
    ]
  }
  ```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

#### 7.2 Get All Farms

Fetches all farms for a specific DeFi protocol.

{% tabs %}
{% tab title="Python" %}
Function Name

```python
get_all_farms
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```python
  protocol (DefiProtocol): The DeFi protocol (e.g., DefiProtocol.H2, DefiProtocol.VVS)
  ```
* Example Code

  ```python
  from crypto_com_developer_platform_client import Defi, DefiProtocol

  farms = Defi.get_all_farms(DefiProtocol.VVS)
  print(farms)
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```python
  List of all farms for the project.
  ```
* Example Return

  ```python
  {'status': 'Success', 'data': [{'id': exmaple-id, 'pid': exmaple-pid, 'lpSymbol': 'exmaple-lp-symbol', 'lpAddress': 'exmaple-lp-address', 'token': {'id': exmaple-id, 'symbol': 'exmaple-symbol', 'address': 'exmaple-address'}, 'quoteToken': {'id': exmaple-id, 'symbol': 'exmaple-symbol', 'address': 'exmaple-address'}, 'version': 'exmaple-version', 'suffix': 'exmaple-suffix', 'rewardStartAt': 'exmaple-start-time', 'rewardEndAt': 'exmaple-end-time', 'isFinished': exmaple-boolean, 'isMigrated': exmaple-boolean, 'isBoostEnable': exmaple-boolean, 'isBoostFarmExpired': exmaple-boolean, 'isAutoHarvestEnabled': exmaple-boolean, 'rewarders': [{'address': 'exmaple-address', 'token': {'id': exmaple-id, 'symbol': 'exmaple-symbol', 'address': 'exmaple-addrss'}, 'isFinished': exmaple-boolean}], 'chain': 'exmaple-chain-name', 'chainId': exmaple-chain-id, 'baseApr': exmaple-base-apr, 'baseApy': exmaple-base-apy, 'lpApr': exmaple-lp-apr, 'lpApy': exmaple-lp-apy}, ... ]}
  ```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="TypeScript" %}
Function Name

```typescript
getAllFarms
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```typescript
  {DefiProtocol} protocol: The DeFi protocol to fetch farms for.
  ```
* Example Code

  ```typescript
  import { Defi, DefiProtocol } from '@crypto.com/developer-platform-client';

  try {
    const farms = await Defi.getAllFarms(DefiProtocol.VVS);
    console.log(farms);
  }
    catch(err) {
    console.log(err);
  }
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```typescript
  {Promise<ApiResponse<Farm[]>>}: A promise that resolves to the farms.
  ```
* Errors

  ```typescript
  {Error}: Throws an error if the request fails.
  ```
* Example Return

  ```typescript
  {
    status: 'Success',
    data: [
      {
        id: example-id,
        pid: example-pid,
        lpSymbol: example-symbol,
        lpAddress: example-address,
        token: example-token,
        quoteToken: example-token,
        version: example-version,
        suffix: example-suffix,
        rewardStartAt: example-start-time,
        rewardEndAt: example-end-time,
        isFinished: example-boolean,
        isMigrated: example-boolean,
        isBoostEnable: example-boolean,
        isBoostFarmExpired: example-boolean,
        isAutoHarvestEnabled: example-boolean,
        rewarders: example-array,
        chain: example-chain-name,
        chainId: example-chain-id,
        baseApr: example-base-apr,
        baseApy: example-base-apy,
        lpApr: example-lp-apr,
        lpApy: example-lp-apy
      }
      ...
    ]
  }
  ```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

#### 7.3 Get Farm By Symbol

Fetches a specific farm by its symbol for a DeFi protocol.

{% tabs %}
{% tab title="Python" %}
Function Name

```python
get_farm_by_symbol
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```python
  protocol (DefiProtocol): The DeFi protocol (e.g., DefiProtocol.H2, DefiProtocol.VVS)
  symbol (str): The farm symbol (e.g., 'zkCRO-MOON', 'CRO-GOLD')
  ```
* Example Code

  ```python
  from crypto_com_developer_platform_client import Defi, DefiProtocol

  farm = Defi.get_farm_by_symbol(DefiProtocol.H2, 'zkCRO-MOON')
  print(farm)
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```python
  Information about the specific farm
  ```
* Example Return

  ```python
  {'status': 'Success', 'data': {'id': example-id, 'pid': example-pid, 'lpSymbol': 'example-lp-symbol', 'lpAddress': 'example-lp-address', 'token': {'id': example-id, 'symbol': 'example-symbol', 'address': 'example-address'}, 'quoteToken': {'id': example-id, 'symbol': 'example-symbol', 'address': 'example-address'}, 'version': 'example-version', 'suffix': 'example-suffix', 'rewardStartAt': 'example-start-time', 'rewardEndAt': 'example-end-time', 'isFinished': example-boolean, 'isMigrated': example-boolean, 'isBoostEnable': example-boolean, 'isBoostFarmExpired': example-boolean, 'isAutoHarvestEnabled': example-boolean, 'rewarders': [{'address': 'example-address', 'token': {'id': example-id, 'symbol': 'example-symbol', 'address': 'example-address'}, 'isFinished': example-boolean}], 'chain': 'example-chain-name', 'chainId': example-chain-id, 'baseApr': example-baser-apr, 'baseApy': example-base-apy, 'lpApr': example-lp-apr, 'lpApy': example-lp-apy, 'rewarderAprs': [{'address': 'example-address', 'tokenAddress': 'example-addrss', 'tokenSymbol': 'example-symbol', 'apr': example-apr, 'apy': example-apy}]}}
  ```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="TypeScript" %}
Function Name

```typescript
getFarmBySymbol
```

{% tabs %}
{% tab title="Query" %}

* Arguments

  ```typescript
  {DefiProtocol} protocol: The DeFi protocol to fetch the farm from.
  {string} symbol: The symbol of the farm to fetch.
  ```
* Example Code

  ```typescript
  import { Defi, DefiProtocol } from '@crypto.com/developer-platform-client';

  try {
    const farm = await Defi.getFarmBySymbol(DefiProtocol.H2, 'zkCRO-MOON');
    console.log(farm);
  }
    catch(err) {
    console.log(err);
  }
  ```

{% endtab %}

{% tab title="Response" %}

* Returns

  ```typescript
  {Promise<ApiResponse<Farm>>} - A promise that resolves to the farm details.
  ```
* Errors

  ```typescript
  {Error}: Throws an error if the request fails.
  ```
* Example Return

  ```typescript
  {
    status: 'Success',
    data: {
      id: example-id,
      pid: example-pid,
      lpSymbol: example-lp-symbol,
      lpAddress: example-lp-address,
      token: {
        id: example-id,
        symbol: example-symbol,
        address: example-address
      },
      quoteToken: {
        id: example-id,
        symbol: example-symbol,
        address: example-address
      },
      version: example-version,
      suffix: example-suffix,
      rewardStartAt: example-start-time,
      rewardEndAt: example-end-time,
      isFinished: example-boolean,
      isMigrated: example-boolean,
      isBoostEnable: example-boolean,
      isBoostFarmExpired: example-boolean,
      isAutoHarvestEnabled: example-boolean,
      rewarders: example-array,
      chain: example-chain-name,
      chainId: example-chain-id,
      baseApr: example-base-apr,
      baseApy: example-base-apy,
      lpApr: example-lp-apr,
      lpApy: example-lp-apy,
      rewarderAprs: example-array
    }
  }
  ```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}


---

# 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://ai-agent-sdk-docs.crypto.com/crypto.com-developer-platform/on-chain-developer-platform-client-sdk/defi-module.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.
