# REF Finance

### Supported Chains

Available on **Near Mainnet and Testnet**

### Available Endpoints:

*Click on the endpoint to jump to the section with full details*

* [<mark style="color:blue;">**/getprice**</mark>](#getprice) <mark style="color:blue;">`GET`</mark> - Returns the swap quotation for a given token pair on Cetus.
* [<mark style="color:blue;">**/getuserliquidity**</mark>](#getuserliquidity) <mark style="color:blue;">`GET`</mark> - Returns the balance of a particular token pair of accounts.&#x20;
* [<mark style="color:blue;">**/getpoolliquidity**</mark>](#getpoolliquidity) <mark style="color:blue;">`GET`</mark> - Returns the total liquidity for a specified pool.
* [<mark style="color:blue;">**/gettokenliquidity**</mark>](#gettokenliquidity) <mark style="color:blue;">`GET`</mark> - Returns the individual token liquidity within the specified liquidity pool.
* [<mark style="color:blue;">**/swap**</mark>](#swap) <mark style="color:green;">`POST`</mark> - Initiate a swap transaction on a specified DEX.&#x20;
* [<mark style="color:blue;">**/**</mark>](#swap)[<mark style="color:blue;">**addliquidity**</mark>](#addliquidity) <mark style="color:green;">`POST`</mark> - Add liquidity to a specified pool in a specified DEX.&#x20;
* [<mark style="color:blue;">**/**</mark>](#swap)[<mark style="color:blue;">**removeliquidity**</mark>](#removeliquidity)<mark style="color:green;">`POST`</mark> - Remove liquidity from a specified pool for a specified DEX.

### DEX IDs

Many endpoints have a parameter where you can provide a DEX ID.&#x20;

Below is a list of DEX IDs related to Cetus. For a complete list and more information, please see the [DEX ID](https://docs.expand.network/ids/dex-ids) page.

| DEX Name    | Chain        | DEX ID |
| ----------- | ------------ | ------ |
| REF Finance | Near Mainnet | 3400   |
| REF Finance | Near Testnet | 3401   |

## Endpoint Details

### /getprice

Returns the swap quotation for a given token pair.

<mark style="color:blue;">`GET`</mark> `https://api.expand.network/dex/getprice`

#### Query Parameter

| Name                                       | Type   | Description                                                                      |
| ------------------------------------------ | ------ | -------------------------------------------------------------------------------- |
| rpc                                        | String | Remote procedural call URL.                                                      |
| dexId<mark style="color:red;">\*</mark>    | String | Refer to the [DEX ID](https://docs.expand.network/ids/dex-ids) page for details. |
| amountIn<mark style="color:red;">\*</mark> | String | Amount of token.                                                                 |
| path<mark style="color:red;">\*</mark>     | String | Comma separated values of token addresses whose price is to be fetched.          |

{% tabs %}
{% tab title="Sample Request" %}

```url
https://api.expand.network/dex/getprice?path=17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1%2Cwrap.near&amountIn=100000000&dexId=3400
```

{% endtab %}

{% tab title="Sample Response" %}

```json
{
  "status": 200,
  "msg": "success",
  "data": {
    "amountIn": "100000000",
    "path": [
      "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1",
      "wrap.near"
    ],
    "amountsOut": [
      "100000000",
      "31456689936699508113692653"
    ]
  }
}
```

{% endtab %}
{% endtabs %}

### /getuserliquidity

Returns  the balance of a particular token pair of an account.

<mark style="color:blue;">`GET`</mark> `https://api.expand.network/dex/getuserliquidity`

#### Query Parameter

| Name                                          | Type   | Description                                                                      |
| --------------------------------------------- | ------ | -------------------------------------------------------------------------------- |
| rpc                                           | String | Remote procedural call URL.                                                      |
| dexId<mark style="color:red;">\*</mark>       | String | Refer to the [DEX ID](https://docs.expand.network/ids/dex-ids) page for details. |
| address<mark style="color:red;">\*</mark>     | String | Public address of liquidity provider.                                            |
| poolAddress<mark style="color:red;">\*</mark> | String | Pool address whose liquidity is to be fetched.                                   |

{% tabs %}
{% tab title="Sample Request" %}

```url
https://api.expand.network/dex/getuserliquidity?poolAddress=17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1%7Cwrap.near%7C100&address=g20_dex.near&dexId=3400
```

{% endtab %}

{% tab title="Sample Response" %}

```json
{
  "status": 200,
  "msg": "success",
  "data": {
    "pairAddress": "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1|wrap.near|100",
    "liquidity": "7123964496422730"
  }
}
```

{% endtab %}
{% endtabs %}

### /getpoolliquidity

Returns the total liquidity for a specified pool.

<mark style="color:blue;">`GET`</mark> `https://api.expand.network/dex/getpoolliquidity`

#### Query Parameter

| Name                                          | Type   | Description                                                                      |
| --------------------------------------------- | ------ | -------------------------------------------------------------------------------- |
| rpc                                           | String | Remote procedural call URL.                                                      |
| dexId<mark style="color:red;">\*</mark>       | String | Refer to the [DEX ID](https://docs.expand.network/ids/dex-ids) page for details. |
| poolAddress<mark style="color:red;">\*</mark> | String | Pool address whose liquidity is to be fetched.                                   |

{% tabs %}
{% tab title="Sample Request" %}

```url
https://api.expand.network/dex/getpoolliquidity?poolAddress=17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1%7Cwrap.near%7C100&dexId=3400
```

{% endtab %}

{% tab title="Sample Response" %}

```json
{
  "status": 200,
  "msg": "success",
  "data": {
    "totalLiquidity": "492779401499816349"
  }
}
```

{% endtab %}
{% endtabs %}

### /gettokenliquidity

Returns the individual token liquidity within the specified liquidity pool.

<mark style="color:blue;">`GET`</mark> `https://api.expand.network/dex/gettokenliquidity`

#### Query Parameter

| Name                                          | Type   | Description                                                                      |
| --------------------------------------------- | ------ | -------------------------------------------------------------------------------- |
| rpc                                           | String | Remote procedural call URL.                                                      |
| dexId<mark style="color:red;">\*</mark>       | String | Refer to the [DEX ID](https://docs.expand.network/ids/dex-ids) page for details. |
| poolAddress<mark style="color:red;">\*</mark> | String | Pool address whose liquidity is to be fetched.                                   |

{% tabs %}
{% tab title="Sample Request" %}

```url
https://api.expand.network/dex/gettokenliquidity?poolAddress=17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1%7Cwrap.near%7C100&dexId=3400
```

{% endtab %}

{% tab title="Sample Response" %}

```json
{
  "status": 200,
  "msg": "success",
  "data": {
    "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1": "816215156745",
    "wrap.near": "553177251133018373561114031157"
  }
}
```

{% endtab %}
{% endtabs %}

### /swap

Initiate a swap transaction on a specified DEX.

<mark style="color:green;">POST</mark> `https://api.expand.network/dex/swap`

#### Request Body

| Name                                       | Type   | Description                                                                      |
| ------------------------------------------ | ------ | -------------------------------------------------------------------------------- |
| rpc                                        | String | Remote procedural call URL.                                                      |
| dexId<mark style="color:red;">\*</mark>    | String | Refer to the [DEX ID](https://docs.expand.network/ids/dex-ids) page for details. |
| path<mark style="color:red;">\*</mark>     | String | Comma separated values of token addresses.                                       |
| amountIn<mark style="color:red;">\*</mark> | String | Amount of token to be swapped.                                                   |
| from<mark style="color:red;">\*</mark>     | String | Address of the sender of the token.                                              |

{% tabs %}
{% tab title="Sample Request" %}

```json
{
  "from": "trader-near.near",
  "path": [
    "a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.factory.bridge.near",
    "wrap.near"
  ],
  "amountIn": "100000000000",
  "dexId": "3400"
}
```

{% endtab %}

{% tab title="Sample Response" %}

```json
{
  "status": 200,
  "msg": "success",
  "data": {
    "chainId": "1200",
    "from": "trader-near.near",
    "to": "a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.factory.bridge.near",
    "data": [
      "eyJyZWNlaXZlcklkIjoiYTBiODY5OTFjNjIxOGIzNmMxZDE5ZDRhMmU5ZWIwY2UzNjA2ZWI0OC5mYWN0b3J5LmJyaWRnZS5uZWFyIiwiZnVuY3Rpb25DYWxscyI6W3sibWV0aG9kTmFtZSI6ImZ0X3RyYW5zZmVyX2NhbGwiLCJhcmdzIjp7InJlY2VpdmVyX2lkIjoiZGNsdjIucmVmLWxhYnMubmVhciIsImFtb3VudCI6IjEwMDAwMDAwMDAwMCIsIm1zZyI6IntcIlN3YXBcIjp7XCJwb29sX2lkc1wiOltcImEwYjg2OTkxYzYyMThiMzZjMWQxOWQ0YTJlOWViMGNlMzYwNmViNDguZmFjdG9yeS5icmlkZ2UubmVhcnx3cmFwLm5lYXJ8MjAwMFwiXSxcIm91dHB1dF90b2tlblwiOlwid3JhcC5uZWFyXCIsXCJtaW5fb3V0cHV0X2Ftb3VudFwiOlwiMFwiLFwiY2xpZW50X2lkXCI6XCJcIn19In0sImdhcyI6IjE4MDAwMDAwMDAwMDAwMCIsImFtb3VudCI6IjAuMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAxIn1dfQ=="
    ],
    "referenceId": "af32b034389e4f42941f488c856ec04e"
  }
}
```

{% endtab %}
{% endtabs %}

### /addliquidity

Add liquidity to a specified pool in a specified DEX.

<mark style="color:green;">POST</mark> `https://api.expand.network/dex/addliquidity`

#### Request Body

| Name                                         | Type   | Description                                                                      |
| -------------------------------------------- | ------ | -------------------------------------------------------------------------------- |
| rpc                                          | String | Remote procedural call URL.                                                      |
| dexId<mark style="color:red;">\*</mark>      | String | Refer to the [DEX ID](https://docs.expand.network/ids/dex-ids) page for details. |
| path<mark style="color:red;">\*</mark>       | String | Comma separated values of token addresses.                                       |
| amountIn                                     | String | Amount of token to be swapped.                                                   |
| amountAMin<mark style="color:red;">\*</mark> | String | Minimum amount of token0.                                                        |
| amountBMin<mark style="color:red;">\*</mark> | String | Minimum amount of token1.                                                        |
| from<mark style="color:red;">\*</mark>       | String | Address of the sender of the token.                                              |

{% tabs %}
{% tab title="Sample Request" %}

```json
{
    "from": "trader-near.near",
    "path": [
        "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1",
        "wrap.near"
    ],
    "amountIn": [
        "1000000000",
        "1000000000"
    ],
    "amountAMin": "0",
    "amountBMin": "0",
    "dexId": "3400"
}
```

{% endtab %}

{% tab title="Sample Response" %}

```json
{
  "status": 200,
  "msg": "success",
  "data": {
    "chainId": "1200",
    "from": "trader-near.near",
    "to": "dclv2.ref-labs.near",
    "value": "0",
    "data": [
      "eyJzaWduZXJJZCI6InRyYWRlci1uZWFyLm5lYXIiLCJyZWNlaXZlcklkIjoiZGNsdjIucmVmLWxhYnMubmVhciIsImFjdGlvbnMiOlt7InR5cGUiOiJGdW5jdGlvbkNhbGwiLCJwYXJhbXMiOnsibWV0aG9kTmFtZSI6InN0b3JhZ2VfZGVwb3NpdCIsImFyZ3M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oiZGNsdjIucmVmLWxhYnMubmVhciIsImFtb3VudCI6IjEwMDAwMDAwMDAiLCJtc2ciOiJcIkRlcG9zaXRcIiJ9LCJnYXMiOiIxNTAwMDAwMDAwMDAwMDAiLCJkZXBvc2l0IjoiMSJ9fV19",
      "eyJzaWduZXJJZCI6InRyYWRlci1uZWFyLm5lYXIiLCJyZWNlaXZlcklkIjoiZGNsdjIucmVmLWxhYnMubmVhciIsImFjdGlvbnMiOlt7InR5cGUiOiJGdW5jdGlvbkNhbGwiLCJwYXJhbXMiOnsibWV0aG9kTmFtZSI6ImFkZF9saXF1aWRpdHkiLCJhcmdzIjp7InBvb2xfaWQiOiIxNzIwODYyOGY4NGY1ZDZhZDMzZjBkYTNiYmJlYjI3ZmZjYjM5OGVhYzUwMWEzMWJkNmFkMjAxMWUzNjEzM2ExfHdyYXAubmVhcnwxMDAiLCJsZWZ0X3BvaW50Ijo0MDI5MjgsInJpZ2h0X3BvaW50Ijo0MDI5MzIsImFtb3VudF94IjoiMTAwMDAwMDAwMCIsImFtb3VudF95IjoiMTAwMDAwMDAwMCIsIm1pbl9hbW91bnRfeCI6IjAiLCJtaW5fYW1vdW50X3kiOiIwIn0sImdhcyI6IjE1MDAwMDAwMDAwMDAwMCIsImRlcG9zaXQiOiIwIn19XX0="
    ],
    "referenceId": "7af3999b9d0f46399e4ff06c2e47c29b"
  }
}
```

{% endtab %}
{% endtabs %}

### /removeliquidity

Remove liquidity from a specified pool for a specified DEX.

<mark style="color:green;">POST</mark> `https://api.expand.network/dex/removeliquidity`

#### Request Body

| Name                                          | Type   | Description                                                                      |
| --------------------------------------------- | ------ | -------------------------------------------------------------------------------- |
| rpc                                           | String | Remote procedural call URL.                                                      |
| dexId<mark style="color:red;">\*</mark>       | String | Refer to the [DEX ID](https://docs.expand.network/ids/dex-ids) page for details. |
| poolAddress<mark style="color:red;">\*</mark> | String | Pool address whose liquidity is to be removed.                                   |
| from<mark style="color:red;">\*</mark>        | String | Address of the sender of the token.                                              |
| liquidity<mark style="color:red;">\*</mark>   | String | The liquidity to be removed.                                                     |
| amountAMin<mark style="color:red;">\*</mark>  | String | Minimum amount of Token0                                                         |
| amountBMin<mark style="color:red;">\*</mark>  | String | Minimum amount of Token1                                                         |

{% tabs %}
{% tab title="Sample Request" %}

```json
{
    "from": "g20_dex.near",
    "poolAddress": "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1|wrap.near|100",
    "liquidity": "100000",
    "amountAMin": "0",
    "amountBMin": "0",
    "dexId": "3400"
}
```

{% endtab %}

{% tab title="Sample Response" %}

```json
{
  "status": 200,
  "msg": "success",
  "data": {
    "chainId": "1200",
    "from": "g20_dex.near",
    "to": "dclv2.ref-labs.near",
    "data": [
      "eyJyZWNlaXZlcklkIjoiZGNsdjIucmVmLWxhYnMubmVhciIsImZ1bmN0aW9uQ2FsbHMiOlt7Im1ldGhvZE5hbWUiOiJiYXRjaF9yZW1vdmVfbGlxdWlkaXR5IiwiYXJncyI6eyJyZW1vdmVfbGlxdWlkaXR5X2luZm9zIjpbeyJscHRfaWQiOiIxNzIwODYyOGY4NGY1ZDZhZDMzZjBkYTNiYmJlYjI3ZmZjYjM5OGVhYzUwMWEzMWJkNmFkMjAxMWUzNjEzM2ExfHdyYXAubmVhcnwxMDAjODg2MCIsImFtb3VudCI6IjEwMDAwMCIsIm1pbl9hbW91bnRfeCI6IjAiLCJtaW5fYW1vdW50X3kiOiIwIn1dfSwiZ2FzIjoiMjUwMDAwMDAwMDAwMDAwIn1dfQ=="
    ],
    "referenceId": "a637cf04fee54c288925a8d80a312c1f"
  }
}
```

{% endtab %}
{% endtabs %}
