# Welcome to Plenty's Unified API

Documentation of the endpoints provided by the API.

Plenty's Unified API offers a comprehensive resource for accessing extensive information about all aspects of the Plenty ecosystem, encompassing both the v2 and v3 decentralized exchanges (DEX) as well as the vote escrow system. This unified API simplifies the process for developers to retrieve specific data related to Plenty's applications, facilitating the creation of a wide range of services and applications on top of the Plenty network.

{% hint style="info" %}
You can access Plenty's Unified API through <mark style="color:purple;">**`api.plenty.network`**</mark>
{% endhint %}

| Application                | Available data                                                                                                                                                          |
| -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| V2 volatile and stable DEX | <ul><li>Liquidity positions of users</li><li>Dollar-based historical analytics</li><li>Special routes for integration with aggregators</li></ul>                        |
| V3 segmented CFMM          | <ul><li>Liquidity positions of users</li><li>CFMM Tick data</li><li>Dollar-based historical analytics</li><li>Special routes for integration with aggregators</li></ul> |
| Vote Escrow                | <ul><li>Locked positions of users</li><li>Historical data for voting and user rewards</li><li>Historical data for bribes</li></ul>                                      |
| Miscelleneous              | <ul><li>All pools and tokens contracts associated with Plenty.</li><li>System-wide historical analytics </li></ul>                                                      |


# Cost

Plenty's Unified API is accessible to all users, without any associated costs, and is suitable for both commercial and non-commercial purposes.

If your application or service makes use of Plenty's Unified API, whether directly on the frontend or indirectly on the backend, it is a requirement to acknowledge this on your website or within your application. This acknowledgement should include a label such as **"Powered by Plenty's Unified API"** or **"Built with Plenty's Unified API",** accompanied by a direct link to the relevant resource.


# Rate Limit

Plenty's Unified API enforces a rate limit of **50 requests per second** on the public link <mark style="color:purple;">**api.plenty.network**</mark>. This means that any application or service utilizing the API is allowed to make up to 50 API requests in a single second.

This rate limit is put in place to ensure fair and efficient usage of the API, preventing any single user or application from overloading the system with an excessive number of requests. Adhering to this rate limit is essential for maintaining the stability and reliability of Plenty's Unified API for all users and applications.

Developers should be mindful of this rate limit when designing their applications and implement proper rate-limiting mechanisms to ensure they do not exceed the allowed request rate. **Additionally, it's essential to monitor and adjust your application's usage of the API to stay within these limits and avoid disruptions in service.**


# Contracts

API endpoints for Token and Pool contracts on Plenty

### Tokens

## Get the details of all the tokens listed on Plentyswap

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/config/tokens`

This endpoints returns an array of objects where each contains information about a token, like its symbol, name, contract address, FA standard, decimals, icon and chain of origin.

{% tabs %}
{% tab title="200: OK Successfully return list of tokens" %}

```typescript
[
  {
    id: number; // Internal database id of the token
    name: string; 
    symbol: string; // Metadata symbol
    decimals: number; 
    standard: string; // FA Standard
    address: string | null; // Tezos address of the token contract
    thumbnailUri: string | null; // TZIP-12 specified format
    originChain: string; // TEZOS, ETHEREUM or POLYGON
  }
]
```

{% endtab %}
{% endtabs %}

### Pools

## Get the details of all the v2 pools on Plentyswap

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/config/pools/v2`

This endpoint returns an array of objects where each object contains information about a v2 pool on Plenty, like its Tezos contract address, both the tokens in the pool, its trading fee value and associated VE bribe and gauge contract addresses.

{% tabs %}
{% tab title="200: OK Successfully returned list of v2 pools" %}

```typescript
[
 // key represents the pool contract address
 [key: string]: {
    address: string;
    token1: {
      id: number;
      name: string;
      symbol: string;
      decimals: number;
      standard: string;
      address: string | null;
      tokenId: number | null;
      thumbnailUri: string | null;
      originChain: string;
    };
    token2: {
      id: number;
      name: string;
      symbol: string;
      decimals: number;
      standard: string;
      address: string | null;
      tokenId: number | null;
      thumbnailUri: string | null;
      originChain: string;
    };
    lpToken: {
      address: string;
      decimals: string;
    }
    fees: string; // To get the fee percentage, divide 100 by this value
    type: string;
    gauge: string | null; // Tezos contract address
    bribe: string | null; // Tezos contract address
  }
]
```

{% endtab %}
{% endtabs %}

## Get the details of all the v3 pools on Plentyswap

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/config/pools/v3`

This endpoint returns an array of objects where each object contains information about a v3 pool on Plenty, like its Tezos contract address, both the tokens in the pool, its trading fee value and associated VE bribe and gauge contract addresses.

{% tabs %}
{% tab title="200: OK Successfully returned list of v3 pools" %}

```typescript
[
 // key represents the pool contract address
 [key: string]: {
    address: string;
    token1: {
      id: number;
      name: string;
      symbol: string;
      decimals: number;
      standard: string;
      address: string | null;
      tokenId: number | null;
      thumbnailUri: string | null;
      originChain: string;
    };
    token2: {
      id: number;
      name: string;
      symbol: string;
      decimals: number;
      standard: string;
      address: string | null;
      tokenId: number | null;
      thumbnailUri: string | null;
      originChain: string;
    };
    feeBps: string; // Basis points
    type: string;
    gauge: string | null; // Tezos contract address
    bribe: string | null; // Tezos contract address
  }
]
```

{% endtab %}
{% endtabs %}


# Analytics

API endpoints for Plenty's DEX analytics

The endpoints below provide all the data visually available at [analytics.plenty.network](https://analytics.plenty.network).

### Tokens

## Get latest analytics for all tokens listed on Plentyswap

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/analytics/tokens`

This endpoint returns an array of objects, where each object contains information about a token, including its symbol, name, contract address, FA standard, decimals, current price data, volume data, fees data, and total value locked (TVL) data.

{% tabs %}
{% tab title="200: OK Successfully returned token analytics data" %}

```typescript
[
  {
    token: string; // Token symbol
    name: string;
    contract: string | null; // Tezos contract address
    standard: string; // FA standard
    tokenId?: number;
    decimals: number;
    price: {
      value: string; // Dollar value
      change24H: string; // Percentage change
      change7D: string; 
      change30D: string;
    };
    volume: {
      value24H: string; // Aggregated Dollar value in the last 24 hours
      change24H: string;
      value7D: string; // Aggregated Dollar value in the last 7 days
    };
    fees: {
      value24H: string;
      change24H: string;
      value7D: string;
    };
    tvl: {
      value: string;
      change24H: string;
    };
  }
]

```

{% endtab %}
{% endtabs %}

## Get historical analytics data for a specific token listed on Plentyswap

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/analytics/tokens/{tokenSymbol}`

This endpoint returns an object that contains information about a token, including its symbol, name, contract address, FA standard, decimals, current price data, volume data, fees data, and total value locked (TVL) data.

#### Path Parameters

| Name                                          | Type   | Description                                     |
| --------------------------------------------- | ------ | ----------------------------------------------- |
| tokenSymbol<mark style="color:red;">\*</mark> | String | The symbol of the token present in its metadata |

#### Query Parameters

| Name         | Type   | Description                                                                                                                          |
| ------------ | ------ | ------------------------------------------------------------------------------------------------------------------------------------ |
| priceHistory | String | Value could be either `day` to receive day wise price history for a year, or `hour` to receive hourly price history for last 7 days. |

{% tabs %}
{% tab title="200: OK Successfully returned token analytics data" %}

```typescript
{
  token: string; // Token symbol
  name: string; 
  contract: string | null; // Tezos contract
  standard: string; // FA standard
  tokenId?: number;
  decimals: number;
  price: {
    value: string; // Dollar value
    change24H: string; // Percentage change
    change7D: string;
    change30D: string;
    // key represents the hourly/daily UTC timestamp
    history?: { [key: string]: PriceOHLC }[]; 
  volume: {
    value24H: string; // Aggregated value in the last 24 hours
    change24H: string;
    value7D: string;
    history?: { [key: string]: string }[];
  };
  fees: {
    value24H: string;
    change24H: string;
    value7D: string;
    history?: { [key: string]: string }[];
  };
  tvl: {
    value: string;
    change24H: string;
    history?: { [key: string]: string }[];
  };
}
```

{% endtab %}
{% endtabs %}

### Pools

## Get latest analytics for all pools on Plentyswap

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/analytics/pools`

This endpoint returns an array of objects, where each object contains information about a liquidity pool, including its contract address, symbol, curve type, volume data, fees data, and total value locked (TVL) data.

{% tabs %}
{% tab title="200: OK Successfully returned pool analytics data" %}

```typescript
[
  pool: string; // Tezos contract address
  symbol: string; // Ticker symbol. Eg: USDT/USDC
  type: string; // Volatile, Stable or V3 pool
  volume: {
    value24H: string; // Aggregated value over the past 24 hours
    change24H: string;
    value7D: string;
  };
  fees: {
    value24H: string;
    change24H: string;
    value7D: string;
  };
  tvl: {
    token1Amount: string; // Decimal scaled token amount
    token2Amount: string;
    value: string;
    change24H: string;
  };
]
```

{% endtab %}
{% endtabs %}

## Get historical analytics for a specific pool on Plentyswap

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/analytics/pools/{poolAddress}`

This endpoint returns an object that contains information about a liquidity pool, including its contract address, symbol, curve type, volume data, fees data, and total value locked (TVL) data.

#### Path Parameters

| Name                                          | Type   | Description                        |
| --------------------------------------------- | ------ | ---------------------------------- |
| poolAddress<mark style="color:red;">\*</mark> | String | Tezos contract address of the pool |

{% tabs %}
{% tab title="200: OK Successfully returned pool analytics data" %}

```typescript
{
  pool: string; // Tezos contract address
  symbol: string; // Ticker symbol. Eg: USDT/USDC
  type: string; // Volatile, Stable or V3 pool
  volume: {
    value24H: string; // Aggregated value of the last 24 hours
    change24H: string;
    value7D: string;
    // key represents the daily UTC timestamp
    history?: { [key: string]: string }[]; 
  };
  fees: {
    value24H: string;
    change24H: string;
    value7D: string;
    history?: { [key: string]: string }[];
  };
  tvl: {
    token1Amount: string;
    token2Amount: string;
    value: string;
    change24H: string;
    history?: { [key: string]: string }[];
  };
}
```

{% endtab %}
{% endtabs %}

### Plenty

## Get historical system wide analytics for Plentyswap

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/analytics/plenty`

{% tabs %}
{% tab title="200: OK Successfully returned analytics data" %}

```typescript
{
  volume: {
    value24H: string; // Aggregated value over the last 24 hours
    change24H: string;
    // key represents the daily UTC timestamp
    history?: { [key: string]: string }[];
  };
  fees: {
    value24H: string;
    change24H: string;
    history?: { [key: string]: string }[];
  };
  tvl: {
    value: string;
    change24H: string;
    history?: { [key: string]: string }[];
  };
}
```

{% endtab %}
{% endtabs %}


# Integrations

API endpoints to provide ticker data in the format useful for exchange aggregators

We currently have an integration active on [Coingecko](https://www.coingecko.com/en/exchanges/plenty-network).

{% hint style="info" %}
Version 1 and version 2 below do not have any connection to Plenty's v1 and v2. These represent various available schemas under integrations.
{% endhint %}

### Version 1

## Get all the token pairs on Plenty

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/integrations/v1/pairs`

This endpoint returns an array of objects where each object contains information on the available pairs, the ticker id, base and target currency and unique identifier.

{% tabs %}
{% tab title="200: OK Successfully returned list of pairs" %}

```typescript
[
  {
    tickerId: string; // Eg: USDC/USDT
    base: string; // Token symbol
    target: string; // Token symbol
    poolId: string; // Tezos contract address
  }
]
```

{% endtab %}
{% endtabs %}

## Get the market data of all pairs on Plenty

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/integrations/v1/tickers`

This endpoint returns an array of objects where each object contains information on the market data of the pair, like the last price in the target currency, base and target volume of the last 24 hours and pool identifier.

{% tabs %}
{% tab title="200: OK Successfully returned market data of all pairs" %}

```typescript
[
  {
    tickerId: string;
    baseCurrency: string; // Token symbol
    targetCurrency: string; // Token symbol
    lastPrice: string;
    baseVolume: string;
    targetVolume: string;
    poolId: string; // Tezos contract
  }
]
```

{% endtab %}
{% endtabs %}

### Version 2

## Get the market data of all pairs on Plenty

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/integrations/v2/tickers`

This endpoint returns an array of objects where each object contains information on the market data of the pair, like the last price in the quote currency, base volume of the last 24 hours and pool identifier.

{% tabs %}
{% tab title="200: OK Successfully returned market data of all pairs" %}

```typescript
[
  {
    market: string; // Ticker id. Eg: USDT-USDC
    base: string; // Token symbol
    quote: string; // Token symbol
    price_quote: string;
    volume_base: string;
  }
]
```

{% endtab %}
{% endtabs %}


# V3 CFMM

API endpoints specific to Plenty V3

### Ticks

## Get all initialised ticks for a pool

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/config/ticks`

This endpoint returns an array of objects where each object represents an initialised tick in a pool, its next and previous ticks, square root price at it, real price in both token x and y and net liquidity at it.

#### Query Parameters

| Name                                   | Type   | Description                  |
| -------------------------------------- | ------ | ---------------------------- |
| pool<mark style="color:red;">\*</mark> | String | Tezos address of the v3 pool |

{% tabs %}
{% tab title="200: OK Successfully returns all ticks" %}

```typescript
[
  {
    tick: string;
    prev: string;
    next: string;
    sqrtPrice: string;
    realPriceX: string;
    realPriceY: string;
    liquidityNet: string;
  }
]
```

{% endtab %}
{% endtabs %}

## Get the witness of a particular tick

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/config/ticks`

This endpoint returns an object with a single field i.e. the witness of the provided tick

#### Query Parameters

| Name                                        | Type     | Description                                |
| ------------------------------------------- | -------- | ------------------------------------------ |
| witnessOf<mark style="color:red;">\*</mark> | Interger | The tick for which the witness is required |

{% tabs %}
{% tab title="200: OK Successfully returned tick witness" %}

```
{
  witness: string;
}
```

{% endtab %}

{% tab title="400: Bad Request Provided tick is not a number of not in range" %}

{% endtab %}
{% endtabs %}

### Positions

## Get all v3 positions of a specific Tezos address

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/v3/positions`

This endpoint returns an array of objects where each object contains information about a position, the pool it belongs to, the tick boundaries, the liquidity and cumulative fee growth values.&#x20;

#### Query Parameters

| Name                                      | Type   | Description               |
| ----------------------------------------- | ------ | ------------------------- |
| address<mark style="color:red;">\*</mark> | String | Tezos address of the user |

{% tabs %}
{% tab title="200: OK Successfully returned list of positions" %}

```typescript
[
  {
    key_id: string; // Big_map key id
    amm: string; // Pool to which the position belongs
    owner: string;
    upper_tick_index: string;
    lower_tick_index: string;
    liquidity: string;
    fee_growth_inside_last_x: string; // Fee cumulatives
    fee_growth_inside_last_y: string;
  };
]
```

{% endtab %}
{% endtabs %}


# Vote Escrow

API endpoints specific to Plenty's vote escrow system

{% hint style="warning" %}
Vote Escrow system is only available for V2 pools
{% endhint %}

### Locks

## Get all VE locks for a Tezos address

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/ply/locks`

This endpoint returns an array of objects where each object contains information about a VE lock, its ID, base value, timestamp of expiry, attachment status, current voting power, available and used voting power for the present epoch, and voting power in the next epoch.

#### Query Parameters

| Name    | Type   | Description               |
| ------- | ------ | ------------------------- |
| address | String | Tezos address of the user |

{% tabs %}
{% tab title="200: OK Successfully returned list of locks" %}

```typescript
{
  result: {
    id: string;
    owner: string;
    baseValue: string; // Amount of PLY locked
    endTs: string; // Ending timestamp
    attached: boolean; // `true` if attached to a gauge
    epochVotingPower: string; // Current max usable voting power of the lock
    currentVotingPower: string; // Voting power at present second
    availableVotingPower: string; // Unused voting power in the present epoch
    nextEpochVotingPower: string; // Voting power for the next epoch
  }[];
}
```

{% endtab %}
{% endtabs %}

### Bribes

## Get all bribes added in a specific epoch

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/ply/bribes`

This endpoint returns an array of objects where each object contains information about the bribes added to a specific pool.

#### Query Parameters

| Name  | Type    | Description                          |
| ----- | ------- | ------------------------------------ |
| epoch | Integer | Epoch for which bribes are requested |

{% tabs %}
{% tab title="200: OK Successfully returned list of bribes for an epoch" %}

```typescript
[
  {
    pool: string; // The pool to which the bribe was added
    bribes: {
      value: string; // Amount of tokens added without decimals
      price: string; // Price of each decimal scaled token 
      name: string; // Token symbol
    }[];
  };
]
```

{% endtab %}
{% endtabs %}

## Get all bribes provided by a specific Tezos address

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/ply/bribes-provider`

This endpoint returns an array of objects where each object contains information about the bribe added by the provided Tezos address.

#### Query Parameters

| Name                                      | Type   | Description                     |
| ----------------------------------------- | ------ | ------------------------------- |
| address<mark style="color:red;">\*</mark> | String | Tezos address of bribe provider |

{% tabs %}
{% tab title="200: OK Successfully returned list of bribes added by the address" %}

```typescript
[
  {
    value: string; // Amount of tokens added with decimals
    name: string; // Token symbol
    amm: string; // Pool to which bribe was added
    epoch: string; // Epoch at which bribe was added
    price: string; // Price of each decimal scaled token
 }
]
```

{% endtab %}
{% endtabs %}

### Pools

## Get incentivisation details of all pools added to the VE system

<mark style="color:blue;">`GET`</mark> `https://api/plenty.network/ply/pools`

This endpoint returns an array of objects where each object contains information about an incentivised pool, its current and future epoch APR and all bribes of the present epoch,&#x20;

{% tabs %}
{% tab title="200: OK Successfully returned a list of incentivised pools" %}

<pre class="language-typescript"><code class="lang-typescript">[
  {
    pool: string; 
    bribes: {
      value: string; // Amount of tokens added with decimals
      price: string; // Price of one decimal scaled token
      name: string; // Token symbol
    }[];
    apr: string; // Percentage APR
    futureApr: string;
<strong>  };
</strong>]
</code></pre>

{% endtab %}
{% endtabs %}

### Voting Rewards

## Get all unclaimed voting rewards for a Tezos address

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/ply/votes`

This endpoint returns an array of objects where each object contains information about unclaimed fees and bribes for a specific epoch.&#x20;

#### Query Parameters

| Name                                      | Type   | Description          |
| ----------------------------------------- | ------ | -------------------- |
| address<mark style="color:red;">\*</mark> | String | User's Tezos address |

{% tabs %}
{% tab title="200: OK Successfully returned list of unclaimed rewards" %}

```typescript
[
  {
    votesUnclaimed: {
      epoch: string;
      amm: string; // Tezos address of the pool
      votes: string; // Votes casted for this pool
      fee: {
        token1Fee: string;
        token2Fee: string;
        token1Symbol: string;
        token2Symbol: string;
      };
      bribes: {
        amm: string;
        epoch: string;
        bribeId: string;
        provider: string;
        value: string;
        name: string;
      }[];
      unclaimedBribes: number[];
      feeClaimed: boolean;
      voteShare: string;
    }[];
    lockId: string;
  };
]
```

{% endtab %}
{% endtabs %}

### V2 Position

## Get all v2 liquidity positions of a Tezos address

<mark style="color:blue;">`GET`</mark> `https://api.plenty.network/ply/positions`

This endpoint returns an array of objects where each object contains information about a v2 liquidity position of the user, its staked gauge balance, wallet balance, boosted balance and token, and APR of the pool involved.

#### Query Parameters

| Name    | Type   | Description               |
| ------- | ------ | ------------------------- |
| address | String | Tezos address of the user |

{% tabs %}
{% tab title="200: OK Successfully returned a list of positions" %}

```typescript
[
  {
    amm: string; // Pool to which position belongs to
    lqtBalance: string; // Liquidity token balance
    stakedBalance: string; // LP tokens staked in gauge
    derivedBalance: string; // Boosted balance
    boostTokenId: string; // veNFT used for the boost
    poolAPR: {
      current: string; // Current epoch APR
      future: string; // Future epoch APR
    };
  }
]
```

{% endtab %}
{% endtabs %}


# Repositories

Links to repositories that power the unified API

Plenty's Unified API consists of four microservices, each residing in its own repository-

| Service                                                                         | Purpose                                                                                                                                  |
| ------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| [API server](https://github.com/Plenty-network/api.plenty.network)              | A REST API service that retrieves and preprocesses data from a PostgreSQL database and serves it.                                        |
| [Analytics indexer](https://github.com/Plenty-network/plenty-analytics-indexer) | An indexing service that records dollar analytics for trades across v2 and v3 exchanges.                                                 |
| [PLY system indexer](https://github.com/Plenty-network/PLY-indexer)             | An indexing service that records user-specific data across V2/V3 exchange and vote escrow contracts - Locks, rewards and user positions. |
| [Unified config indexer](https://github.com/Plenty-network/unified-config)      | An indexing service that records every new contract added to the applications suite.                                                     |


