Integration FAQ
Questions
Indexer and SDK
SDK
Github - https://github.com/cryptoalgebra/tonco-sdk/
Examples and references
Github - https://github.com/cryptoalgebra/tonco-demo
Mainnet
Explorer page: https://indexer.tonco.io
GraphQL endpoint: https://indexer.tonco.io
Farming Backend: https://api-farming.tonco.io
Router Contract - EQC_-t0nCnOFMdp7E7qPxAOCbCWGFz-e3pwxb6tTvFmshjt5
Testnet
Explorer page: https://testnet-indexer.tonco.io
GraphQL endpoint: https://testnet-indexer.tonco.io
Router Contract - EQDnfag9lHlc0rS6YeI7WwRq-3ltcKSsYxLiXmveB7gNUzNO
Retrieve pool data
The best way to get all the pools and general information about them is to use our indexer.
Indexer is critical for our system, and we keep it highly available, however, we encourage caching the pool list.
Alternatively, if you don’t want to depend on our infrastructure, you can rescan the blockchain in search of messages POOL_INIT sent by the router
Getting pool APR
For information about the APR of the pool in farming, you need to refer to the URL:
GET api-farming.tonco.io/apr?pool=<pool address>
The answer has “apr” as the base apr and an array of farmings. Farming is considered active if rewardsLeft is not equal to zero. Farming has a property - multiplier, it is a coefficient that denotes how many times farming increases the base apr.
In most cases, a pool has only one active farming, but it is possible that it will have several in the future.
Example
Request:
Response:
Retrieving positions
There are several ways to get all positions and positions per person.
Getting positions by index
If you want to manually scan and enumerate all the positions for a particular pool you can first use the method getPoolStateAndConfiguration and get "Number of active NFT positions" from it. Then iterate from 0 as the index of NFT and call get_nft_address_by_index()
Getting positions with NFT API's
Position NFT is a real NFT so you can use TonConsole Api and TonCenter API to get NFT address info and metadata. For position parameters, however, you would need to call the NFT get-method - GetPositionInfo()
Getting positions from TONCO indexer
Please address the GraphQL schema documents for more details - GraphQL Schema Getting collected fees - https://docs.tonco.io/technical-reference/indexer#position-data Here is a small snippet that uses our indexer\
Forming messages for the swap
Sending swap can be done with our SDK - https://github.com/cryptoalgebra/tonco-sdk
An example of swap preparation can be found here - https://github.com/cryptoalgebra/tonco-sdk/blob/36eb0d7feadfcdcd60583ebe4098eb25fcc02591/src/classes/PoolMessageManager.ts#L649
A swap request is created as a payload in the jetton transfer and is sent to the router. The general logic of the input parameters can be derived from the SDK example above and the doc of the pool swap message POOLV3_SWAP
Swap estimate
This question depends on your requirements, limitations, and infrastructure of choice. Here are 5 options
The simplest and most precise way is to call the pool contract get method - https://docs.tonco.io/technical-reference/contracts/pool#getswapestimategas
Download the pool contract code (code is immutable) and data and run this method in sandbox/blueprint. This would be the simplest and fastest way to make many calls. The general example you can find here - tonco-demo example of shard account
If you have ever implemented integration with other Algebra EVM projects written in your language of choice - then the output simulation can be bit-precise
You can use our Typescript implementation of user-side swap simulation using TONCO DEX SDK. It includes 2 ways to estimate a swap: on-chain and off-chain. Before actual blockchain execution please check that the estimates you made with TS match the contract call.
a) Estimate Swap 1 TON -> USDT Example (on-chain)
b) Estimate Swap 1 TON -> USDT Example (off-chain)
You can use our Kotlin implementation of user-side swap simulation.
Marking transactions for referral tracing
With TONCO v1 It is possible to mark transactions to be able to index them for needs of referral tracking
You have 64 bits of query_id at your disposal. We don't alter it and copy it in the outgoing messages
A swap request is created as a payload for TRANSFER_NOTIFICATION. The current version of the swap request - Swap Cell Building uses at most 850bits and 1ref. In the current version, all remaining cell part is ignored. However, to be future-proof proof we recommend to occupy second maybe_ref (1 ref and 1 bit). This cell starts with 4 byte of your service id and any content you need as remaining data.
Last updated