soroswap / backend

Soroswap Backend: Provides Endpoints for info and to calculate optimal routing.
https://backend.soroswap.finance
0 stars 2 forks source link

Backend: Stellar AMM: Study and POC #8

Closed joaquinsoza closed 3 months ago

joaquinsoza commented 10 months ago

Index Stellar AMM

study:

MattPoblete commented 9 months ago

Where is located the info for Stellar's liquidity pools?

You can access the liquidity pool data through the Horizon server or by using the Stellar SDK.

https://developers.stellar.org/api/horizon/resources/list-liquidity-pools

Request:

You can customize the request by setting the following queries:

However, for this example, we will keep it simple.

Http request:

curl -L -X GET '<https://horizon.stellar.org/liquidity_pools>' \\\\\\\\
-H 'Accept: application/json'

Stellar SDK request:

As previously mentioned, you can access the Stellar liquidity pools data using the Stellar SDK.

import * as sdk from 'stellar-sdk'
const server = new sdk.Horizon.Server('<https://horizon-testnet.stellar.org>');

// Get liquidity pools (by default returns 10)
server.liquidityPools().call().then((response) => {
    console.log(response);
    });

// Get liquidity pools with queries
server.liquidityPools().limit(10).call().then((response) => {
    console.log(response);
    });

// Get changes of liquidity pools on stream
server.liquidityPools().stream({
    onmessage: (response) => {
        console.log(response);
    }
});

For more information about the liquidityPools method, visit the following link: https://stellar.github.io/js-stellar-sdk/LiquidityPoolCallBuilder.html

Response:

{
  "_links": {
    "self": {
      "href": "<https://horizon.stellar.org/liquidity_pools?cursor=\\\\\\\\u0026limit=10\\\\\\\\u0026order=asc>"
    },
    "next": {
      "href": "<https://horizon.stellar.org/liquidity_pools?cursor=0027db149e56e0f68faf2711cccae613c26addb799dbe25af37c5ab1aeb4fa22\\\\\\\\u0026limit=10\\\\\\\\u0026order=asc>"
    },
    "prev": {
      "href": "<https://horizon.stellar.org/liquidity_pools?cursor=0000a8198b5e25994c1ca5b0556faeb27325ac746296944144e0a7406d501e8a\\\\\\\\u0026limit=10\\\\\\\\u0026order=desc>"
    }
  },
  "_embedded": {
    "records": [
      {
        "_links": {
          "self": {
            "href": "<https://horizon.stellar.org/liquidity_pools/0000a8198b5e25994c1ca5b0556faeb27325ac746296944144e0a7406d501e8a>"
          },
          "transactions": {
            "href": "<https://horizon.stellar.org/liquidity_pools/0000a8198b5e25994c1ca5b0556faeb27325ac746296944144e0a7406d501e8a/transactions{?cursor,limit,order}>",
            "templated": true
          },
          "operations": {
            "href": "<https://horizon.stellar.org/liquidity_pools/0000a8198b5e25994c1ca5b0556faeb27325ac746296944144e0a7406d501e8a/operations{?cursor,limit,order}>",
            "templated": true
          }
        },
        "id": "0000a8198b5e25994c1ca5b0556faeb27325ac746296944144e0a7406d501e8a",
        "paging_token": "0000a8198b5e25994c1ca5b0556faeb27325ac746296944144e0a7406d501e8a",
        "fee_bp": 30,
        "type": "constant_product",
        "total_trustlines": "1",
        "total_shares": "5494.2144063",
        "reserves": [
          {
            "asset": "native",
            "amount": "6.6856700"
          },
          {
            "asset": "GOLDBANK001:GDEUQ2MX3YXMITFOTC3CO3GW5V3XE3IVG7JKLZZAOZ7WFYIN256INDUS",
            "amount": "6047277.1455088"
          }
        ],
        "last_modified_ledger": 50193936,
        "last_modified_time": "2024-02-02T13:17:46Z"
      },
      ...
    ]
  }
}

In the response, you'll find detailed information about each liquidity pool. This includes its ID, the fee in basis points, the type of pool, the total number of trustlines and shares, the assets and amounts in the pool's reserves, and the last time the pool was modified.

esteblock commented 9 months ago
chopan123 commented 8 months ago

The main objective of this Study is to know how to index the information from the Stellar AMM on Mercury, good job while using horizon server it might useful in the future but we need to use an indexer!

Re-do this issue using mercury

MattPoblete commented 7 months ago

Mercury team are currently working on this feature

Image

chopan123 commented 6 months ago

Do it with Zephyr