Overview

All operations use a unified Yield Aggregator Service API, accessible via REST API.

Key features of Yield Aggregator:

  1. Upon request, the swap.coffee backend provides information about liquidity pools and DeFi protocols on the TON network.
  2. If the user provides their wallet, the swap.coffee backend retrieves data about the user’s pools.
  3. Users can interact with pools via the API: retrieve pool details, gather information about their position, and perform actions (e.g., adding liquidity).
  4. Users can track the status of their transactions by querying the swap.coffee backend.

List of Pools

To retrieve the list of all pools in Yield Aggregator, use the GET /v1/yield/pools method. This method allows filtering and sorting pools by various parameters, including blockchains, liquidity providers, and more.

Request Parameters

ParameterTypeDescriptionDefault Value
blockchainsarrayFilter by available blockchains (e.g., ton).If not specified, all supported blockchains are used.
providersarrayFilter by pool providers (e.g., stonfi).If not specified, all providers are used.
trustedbooleanReturns only trusted pools (verified by DEXes or the community).True by default.
with_active_boostsbooleanReturns pools with active incentives.False by default.
with_liquidity_fromstringFilter by pools where the user has provided liquidity.Null by default.
search_textstringSearch by pool address, token tickers, or token addresses.Null by default.
orderstringField to sort by.TVL by default.
descending_orderbooleanSort in descending (true) or ascending (false) order.True by default.
in_groupsbooleanGroups pools by liquidity providers.False by default.
sizeintegerNumber of pools per page (maximum 100).10
pageintegerPage number for pagination.1

The in_groups Flag

You can retrieve a preview for the specified parameters for each liquidity provider (or all providers if the providers parameter is null). To do this, set in_groups=true in the request. In this case, the response will contain a set of pool lists for each required liquidity provider (up to 10 entries per provider).

If in_groups=true, the size and page parameters must be null.

Response Structure

The response structure contains an array of entries with the following fields:

FieldTypeDescription
total_countint32Total number of pools found for the specified provider.
poolsarrayList of pools.

Each element in pools consists of:

FieldTypeDescription
pool_statisticsobjectTrading statistics of the pool.
poolobjectPool data parameterized by the "@type" key.

Possible values for pool["@type"]:

  • dex_pool, the object is a DEX pool and contains the following fields:
FieldTypeDescription
dexstringName of the DEX (e.g., stonfi).
addressstringPool address.
typeobjectPool type (e.g., public, private).
amm_typeobjectAMM type (e.g., constant_product).
amm_settingsobjectAMM parameters.
tokensarrayList of tokens in the pool.
reservesdoublePool reserves.
restrictionsarrayToken restrictions (minimum and maximum token amounts for swaps).
feesobjectPool fees.
unavailable_untilintegerTime (in seconds, UTC Unix timestamp) until the pool becomes unavailable.

The pool_statistics object includes the following fields:

FieldTypeDescription
tvl_usdnumberTotal value locked in USD.
volume_usdnumberTrading volume in USD.
fee_usdnumberPool fees in USD.
aprnumberTotal Annual Percentage Rate (APR).
lp_aprnumberAPR for liquidity providers.
boost_aprnumberAPR from boosts.

Example Request

    curl -X GET "https://backend.swap.coffee/v1/yield/pools?blockchains=ton&trusted=true&search_text=CES&order=apr&descending_order=true&size=50&page=1"

Retrieving Pool Information

To retrieve detailed information about a pool, use the GET /v1/yield/pool/{pool_address} method.

Response Structure

The method returns an object with fields:

FieldTypeDescription
pool_statisticsobjectTrading statistics of the pool.
poolobjectPool data parameterized by the "@type" key.

Possible values for pool["@type"]:

  • dex_pool, the object is a DEX pool and has the following fields:
FieldTypeDescription
poolobjectCore pool data.
boostsarrayList of active boosts.
total_supplystringTotal amount of minted LP tokens.

Each element in the boosts list has the following fields:

FieldTypeDescriptionRequired
pool_addressstringAddress of the pool associated with the boost.Yes
boost_factorystringAddress of the boost factory.No
boost_idintegerBoost identifier.No
reward_tokenobjectReward token.Yes
reward_rate_per_secondstringReward rate per second.Yes
start_seconds_unixintegerBoost start time (Unix timestamp, seconds).No
finish_seconds_unixintegerBoost end time (Unix timestamp, seconds).Yes
rewards_per_day_usdnumberDaily rewards in USD.Yes
aprnumberAnnual Percentage Rate (APR) in percentage.Yes
lock_duration_secondsintegerLock duration for participating in the boost (seconds).No

Example Request

    curl -X GET "https://backend.swap.coffee/v1/yield/pool/EQBqg596nW5TA9cfUePEFGnyw1V0F560v7Qg3KYku5iXU217"

Retrieving User Position Information

To retrieve detailed information about a user’s position in a pool, use the GET /v1/yield/pool/{pool_address}/{user_address} method.

Response Structure

The method returns an object with fields:

FieldTypeDescription
poolobjectPool data parameterized by the "@type" key.

Possible values for pool["@type"]:

  • dex_pool, the object is a DEX pool and has the following fields:
FieldTypeDescription
user_lp_amountstringAmount of the user’s LP tokens.
user_lp_walletstringAddress of the user’s wallet where LP tokens are stored.
boostsarrayBoosts available for claiming.

Each element in the boosts list has the following fields:

FieldTypeDescription
tokenobjectToken associated with the reward.
walletstringAddress where rewards are stored.
typeobjectType of reward (e.g., rewards_stonfi).
claimedstringAmount of tokens already claimed.
lockedstringAmount of locked tokens.
availablestringAmount of tokens available for claiming.
available_usdnumberValue of available tokens in USD.

Example Request

    curl -X GET "https://backend.swap.coffee/v1/yield/pool/EQBqg596nW5TA9cfUePEFGnyw1V0F560v7Qg3KYku5iXU217/UQAj-RQTlNNwjkuRVYWdfamU0jjvQbH31lkxTw-osulj4tdj"

User Interaction with a Pool

To add liquidity or withdraw funds, use the POST /v1/yield/pool/{pool_address}/{user_address} method.

Interaction Types

The method supports the following operations, parameterized by the "@type" field in the request body:

  • dex_provide_liquidity: Add liquidity to the pool.
  • dex_withdraw_liquidity: Withdraw liquidity from the pool.
  • dex_stonfi_lock_staking: Stake in Ston.fi farming service.
  • dex_stonfi_withdraw_staking: Withdraw from staking in Ston.fi.

Each request returns a list of transactions that need to be signed and sent to the blockchain:

FieldTypeDescription
query_idstringTransaction identifier for status tracking.
messageobjectTransaction to be signed and sent.

Example Request

    curl -X POST "https://backend.swap.coffee/v1/yield/pool/EQBqg596nW5TA9cfUePEFGnyw1V0F560v7Qg3KYku5iXU217/UQAj-RQTlNNwjkuRVYWdfamU0jjvQbH31lkxTw-osulj4tdj"
-H "Content-Type: application/json" \\
  -d '{
    "@type": "dex_provide_liquidity",
    "user_wallet": "UQAj-RQTlNNwjkuRVYWdfamU0jjvQbH31lkxTw-osulj4tdj",
    "asset_1_amount": "1000000000",
    "asset_2_amount": "2000000000",
    "min_lp_amount": "123456789"
  }

Checking Operation Status

After submitting a transaction, you can check its statuses using the GET /v1/yield/result method.

Response Structure

The method returns an array of transaction statuses:

  • pending;
  • success;
  • failed.

Example Request

    curl -X GET "https://backend.swap.coffee/v1/yield/resut?query_id=123456"