# DolphinSwap LP Integration

## Contract account

DolphinSwap contract：dolphinsswap

Check details on bloks：[view](https://bloks.io/account/dolphinsswap?loadContract=true\&tab=Tables\&account=dolphinsswap\&scope=dolphinsswap\&limit=100)

## Basic Type

### pooltoken

| Parameter | Type             | Comment                                        |
| --------- | ---------------- | ---------------------------------------------- |
| weight    | uint32\_t        | Weight                                         |
| symbol    | extended\_symbol | Token, includes contract, symbol and precision |
| reserve   | asset            | Token's total amount                           |

## Liquidity Pool

### Statements

pool table is used to store all trading pairs, it is the core of the contract.

### Table Structure

Table: pools

Scope: dolphinsswap

| Parameter          | Type         | Comment                                       |
| ------------------ | ------------ | --------------------------------------------- |
| id                 | uint64\_t    | Liquidity Pool ID                             |
| code               | symbol\_code | LP token's name，for an example: DOPA          |
| swap\_fee          | uint16\_t    | trading fee rate, need to divide by 10000     |
| total\_lptoken     | uint64\_t    | total LP token amount                         |
| create\_time       | uint32\_t    | LP pool created time                          |
| last\_update\_time | uint32\_t    | last updated time                             |
| tokens             | std::vector  | trading pair list, includes 2 and more tokens |

### Request Demo：

```
curl -X POST -d '{"code":"dolphinsswap","scope":"dolphinsswap","table":"pools","json":true,"limit":10}' -H 'Content-Type: application/json' http://eos.greymass.com/v1/chain/get_table_rows
```

## Lptoken Table

### Statements

lptoken table is used to store users' LP

### LP Naming Rules

Dolphin Swap LP Tokens all start with DOP, and then add the pool\_id of the liquidity pool to convert to a 26 hexadecimal (letter). For example, the liquidity pool ID is 1, and the converted is DOPA. If it is 27, it corresponds to DOPAA, and so on. Code method for converting pool\_id into lp code:

```
symbol_code id2lpcode(uint64_t id) {
    std::string code = "DOP";
    std::string s;
    while (id > 0) {
        uint32_t rem = id % 26;
        if (rem == 0) rem = 26;
        s += ('A' + rem - 1);
        id = (id - rem) / 26;
    }
    std::reverse(s.begin(), s.end());
    code += s;
    return symbol_code(code.c_str());
}
```

### Table Structrue

Table: lptokens

Scope: LP token's name，like DOPA

| Parameter | Type      | Comment            |
| --------- | --------- | ------------------ |
| owner     | name      | Liquidity Provider |
| token     | uint64\_t | LP token amount    |

### Request Demo：

```
curl -X POST -d '{"code":"dolphinsswap","scope":"DOPA","table":"lptokens","json":true,"limit":10}' -H 'Content-Type: application/json' http://eos.greymass.com/v1/chain/get_table_rows
```

## Deposit Table

### Statements

The deposit table is used to store temporary market-making deposits. The user needs to recharge multiple assets for market-making. This table is used to temporarily record the user's single market-making deposit. The record will be automatically cleared after successful market making.

### Table Structrue

Table: deposits

Scope: pool\_id

| Parameter  | Type        | Comment              |
| ---------- | ----------- | -------------------- |
| owner      | name        | liquidity provider   |
| quantities | std::vector | deposited token list |

### Request Demo：

```
curl -X POST -d '{"code":"dolphinsswap","scope":1,"table":"deposits","json":true,"limit":10}' -H 'Content-Type: application/json' http://eos.greymass.com/v1/chain/get_table_rows
```
