# SDEX

### /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?dexId=2400&amountIn=100000000000000000&path=yUSDC%3AGDGTVWSM4MGS4T7Z6W4RPWOCHE2I6RDFCIFZGS3DOA63LWQTRNZNTTFF%2CXLM
```
{% endtab %}

{% tab title="Sample Response" %}
```json
{
    "status": 200,
    "msg": "success",
    "data": {
        "amountIn": "100000000000000000",
        "path": [
            "yUSDC:GDGTVWSM4MGS4T7Z6W4RPWOCHE2I6RDFCIFZGS3DOA63LWQTRNZNTTFF",
            "XLM"
        ],
        "amountsOut": [
            "100000000000000000",
            "6403037405751"
        ]
    }
}
```
{% 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.                                                                                                                                                                                 |
| path<mark style="color:red;">\*</mark>    | String | <p>Comma separated values of token addresses whose price is to be fetched.<br>Note: <br>1) Assets should be in lexicographic order.<br>2) For assets other than XLM (Native token), the token issuer is required.</p> |

{% tabs %}
{% tab title="Sample Request" %}
```url
https://api.expand.network/dex/getuserliquidity?address=GDZUSPMPAWY3JF6J4BEC7RVVVOUKCQZJRVA4NAA6HCS2GRG57DIMGCW3&dexId=2400&path=XBTC%3AGA7JNTXAHMMDUTLX72UM5PWHOAMJEDUQ6GREQZBLMAPVF5WM2JH4XBTC%2CyXLM%3AGARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55
```
{% endtab %}

{% tab title="Sample Response" %}
```json
{
    "status": 200,
    "msg": "success",
    "data": {
        "pairAddress": "fd2b4dbb80fe7e2a93caf8ff42b1c6cc74c1c2b9c0b7cc41e1c21955b01fc1f5",
        "liquidity": "31306548835",
        "tokenA": "319735818813889",
        "tokenB": "11224502"
    }
}
```
{% 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=ffff7fe3743b3c63b12e80f22aed5e8799aa986e25fe155a19277b660d547e71&dexId=2400
```
{% endtab %}

{% tab title="Sample Response" %}
```json
{
    "status": 200,
    "msg": "success",
    "data": {
        "totalLiquidity": "313065488356"
    }
}
```
{% 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=843659d3962c3193a16388d60702e725940d36ec534727dc2308e8e7e427dbdd&dexId=2400
```
{% endtab %}

{% tab title="Sample Response" %}
```json
{
    "status": 200,
    "msg": "success",
    "data": {
        "native": "222295315",
        "BTC:GBWCFQGDIUJ35X3VTUDB2LHCJFIPZJGDE3XOGMKPWA2D3EZPL2LBNBTC": "2467709804653380"
    }
}
```
{% endtab %}
{% endtabs %}

### /getliquidityholders

Returns the total number of liquidity holders in the specified pool.

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

#### 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/getliquidityholders?poolAddress=66b2286fa2cabdf1914abea058e3a18b1267643d818ae76dc1a5994fb22b9886&dexId=2400
```
{% endtab %}

{% tab title="Sample Response" %}
```json
{
    "status": 200,
    "msg": "success",
    "data": {
        "totalTokenHolders": "803"
    }
}
```
{% 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 | <p>Comma-separated values of token addresses, inside an array, to swap.<br>Note: For assets other than XLM (Native token), the token issuer is required.</p> |
| amountIn<mark style="color:red;">\*</mark>     | String | Amount of token to be swapped.                                                                                                                               |
| amountOutMin<mark style="color:red;">\*</mark> | String | Minimum amount accepted as the result of swap.                                                                                                               |
| from<mark style="color:red;">\*</mark>         | String | Address of the sender of the token.                                                                                                                          |
| slippage                                       | String | <p>Percentage of total swap value. By default, 1.</p><p>0 &#x3C;= slippage value &#x3C;= 10</p>                                                              |

{% tabs %}
{% tab title="Sample Request" %}
```json
{
    "amountIn": "150000000",
    "amountOutMin": "12",
    "from": "GARNHXH36IUZE4F5MON5XBQX37OGVFGCOPOPN7CPQL3TP7VX2XI35QUJ",
    "slippage": "10",
    "dexId": "2400",
    "path": [
      "XLM",
      "apUSDC:GALLBRBQHAPW5FOVXXHYWR6J4ZDAQ35BMSNADYGBW25VOUHUYRZM4XIL"
    ]
}
```
{% endtab %}

{% tab title="Sample Response" %}
```json
{
    "status": 200,
    "msg": "success",
    "data": {
        "chainId": "1500",
        "from": "GARNHXH36IUZE4F5MON5XBQX37OGVFGCOPOPN7CPQL3TP7VX2XI35QUJ",
        "gas": "100",
        "data": "AAAAAgAAAAAi09z78imScL1jm9uGF9/capTCc9z2/E+C9zf+t9XRvgAAAGQDC8UiAAAACQAAAAEAAAAAAAAAAAAAAABmxhT0AAAAAAAAAAEAAAAAAAAADQAAAAAAAAAACPDRgAAAAAAi09z78imScL1jm9uGF9/capTCc9z2/E+C9zf+t9XRvgAAAAJhcFVTREMAAAAAAAAAAAAAFrDEMDgfbpXVvc+LR8nmRghvoWSaAeDBtrtXUPTEcs4AAAAAAAAACwAAAAAAAAAAAAAAAA==",
        "referenceId": "3b37b58444cf4d8fbdf81437adf4d547"
    }
}
```
{% 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 | <p>Comma-separated values of token addresses, inside an array, to swap.<br>Note: For assets other than XLM (Native token), the token issuer is required.</p> |
| amountIn<mark style="color:red;">\*</mark> | String | Amount of token to be swapped.                                                                                                                               |
| slippage                                   | String | <p>Percentage of total swap value. By default, 1.</p><p>0 &#x3C;= slippage value &#x3C;= 10</p>                                                              |
| from<mark style="color:red;">\*</mark>     | String | Address of the sender of the token.                                                                                                                          |

{% tabs %}
{% tab title="Sample Request" %}
```json
{
    "dexId": "2400",
    "amountIn": [
        "1000000",
        "1000000"
    ],
    "from": "GARNHXH36IUZE4F5MON5XBQX37OGVFGCOPOPN7CPQL3TP7VX2XI35QUJ",
    "path": [
        
        "XBTC:GA7JNTXAHMMDUTLX72UM5PWHOAMJEDUQ6GREQZBLMAPVF5WM2JH4XBTC",
        "yXLM:GARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55"
    ],
    "slippage": "10"
}
```
{% endtab %}

{% tab title="Sample Response" %}
```json
{
    "status": 200,
    "msg": "success",
    "data": {
        "chainId": "1500",
        "from": "GARNHXH36IUZE4F5MON5XBQX37OGVFGCOPOPN7CPQL3TP7VX2XI35QUJ",
        "gas": "100",
        "data": "AAAAAgAAAAAi09z78imScL1jm9uGF9/capTCc9z2/E+C9zf+t9XRvgAAAZADC8UiAAAACQAAAAEAAAAAAAAAAAAAAABmxhUEAAAAAAAAAAQAAAAAAAAABgAAAAMAAAAAAAAAAVhCVEMAAAAAPpbO4DsYOk13/qjOvsdwGJIOkPGiSGQrYB9S9szST8sAAAABeVhMTQAAAAAiNtdw/g0+AVIZddXPesSEK3CV1rGp12jT6aYy6ZkGvgAAAB4AAAAAfSt1AAAAAAAAAAAGAAAAAVhCVEMAAAAAPpbO4DsYOk13/qjOvsdwGJIOkPGiSGQrYB9S9szST8sAAAAAAA9CQAAAAAAAAAAGAAAAAXlYTE0AAAAAIjbXcP4NPgFSGXXVz3rEhCtwldaxqddo0+mmMumZBr4AAAAAAA9CQAAAAAAAAAAW/StNu4D+fiqTyvj/QrHGzHTBwrnAt8xB4cIZVbAfwfUAAAAAAA9CQAAAAAAAD0JAAAAAAQAAAAoAAAATAAAACgAAAAAAAAAA",
        "referenceId": "aae58191213a4f7c89e1511487e02946"
    }
}
```
{% 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.                                                                             |
| path<mark style="color:red;">\*</mark>         | String | <p>Comma-separated values of token addresses, inside an array, to swap.<br>Note: For assets other than XLM (Native token), the token issuer is required.</p> |
| amountOutMin<mark style="color:red;">\*</mark> | String | Minimum amount to be received.                                                                                                                               |
| slippage                                       | String | <p>Percentage of total swap value. By default, 1.</p><p>0 &#x3C;= slippage value &#x3C;= 10</p>                                                              |
| 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.                                                                                                                                 |

{% tabs %}
{% tab title="Sample Request" %}
```json
{
    "dexId": "2400",
    "from": "GARNHXH36IUZE4F5MON5XBQX37OGVFGCOPOPN7CPQL3TP7VX2XI35QUJ",
    "path": [
        "XBTC:GA7JNTXAHMMDUTLX72UM5PWHOAMJEDUQ6GREQZBLMAPVF5WM2JH4XBTC",
        "yXLM:GARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55"
    ],
    "liquidity": "100000",
    "amountOutMin": [
        "32",
        "32"
    ],
    "slippage": "10"
}
```
{% endtab %}

{% tab title="Sample Response" %}
```json
{
    "status": 200,
    "msg": "success",
    "data": {
        "chainId": "1500",
        "from": "GARNHXH36IUZE4F5MON5XBQX37OGVFGCOPOPN7CPQL3TP7VX2XI35QUJ",
        "gas": "100",
        "data": "AAAAAgAAAAAi09z78imScL1jm9uGF9/capTCc9z2/E+C9zf+t9XRvgAAAGQDC8UiAAAACQAAAAEAAAAAAAAAAAAAAABmxhUUAAAAAAAAAAEAAAAAAAAAF/0rTbuA/n4qk8r4/0Kxxsx0wcK5wLfMQeHCGVWwH8H1AAAAAAABhqAAAAAAAAAAHQAAAAAAAAAdAAAAAAAAAAA=",
        "referenceId": "83a42ff85f7045829ec2f8809102caa6"
    }
}
```
{% endtab %}
{% endtabs %}
