github.com/diadata-org/diadata@v1.4.593/documentation/tutorials/exchange-scrapers/alephium/README.md (about)

     1  https://github.com/alephium/go-sdk/tree/master
     2  
     3  https://explorer.alephium.org/
     4  
     5  https://github.com/alephium/token-list
     6  
     7  ### openapi
     8  
     9  https://node.mainnet.alephium.org/docs
    10  
    11  https://backend.mainnet.alephium.org/docs/#/
    12  
    13  Each token pairs has its own contract. 
    14  
    15  You can do something like this to get all token pairs:
    16  
    17  ```
    18  curl https://backend.mainnet.alephium.org/contracts/vyrkJHG49TXss6pGAz2dVxq5o7mBXNNXAV18nAeqVT1R/sub-contracts?limit=100
    19  ```
    20  
    21  we do have endpoints for supporting fetching events. 
    22  
    23  For AYIN, each token pair emits its own swap event, 
    24  
    25  for example for ALPH <-> USDT pair (contract address: 2A5R8KZQ3rhKYrW7bAS4JTjY9FCFLJg6HjQpqSFZBqACX), 
    26  
    27  following endpoints are useful:
    28  
    29  1. 
    30  ```
    31  curl https://node.mainnet.alephium.org/events/contract/2A5R8KZQ3rhKYrW7bAS4JTjY9FCFLJg6HjQpqSFZBqACX?start=0&limit=10
    32  
    33  ```
    34  
    35  This returns the first 10 events for the ALPH <-> USDT token pair, the eventIndex of the swap events is 2. e.g.
    36  ```
    37  {
    38        "blockHash": "00000000000bd8c4cc2df9caad18afd86fa6d9b09cb9ed61ef5ff34427515080",
    39        "txId": "0cd81aec1ee6744dc119db6f86328b4c846af86ce885e02d60582121012344f0",
    40        "eventIndex": 2,
    41        "fields": [
    42          {
    43            "type": "Address",
    44            "value": "1BjwWZEFaWYD9HLyNASTiVZD1ct4Z75Fpv8oGW7C9BWjz"
    45          },
    46          {
    47            "type": "U256",
    48            "value": "500000000000000000000"
    49          },
    50          {
    51            "type": "U256",
    52            "value": "0"
    53          },
    54          {
    55            "type": "U256",
    56            "value": "0"
    57          },
    58          {
    59            "type": "U256",
    60            "value": "117658826"
    61          },
    62          {
    63            "type": "Address",
    64            "value": "1BjwWZEFaWYD9HLyNASTiVZD1ct4Z75Fpv8oGW7C9BWjz"
    65          }
    66        ]
    67      }
    68  ```    
    69  
    70  The schema of the events is event
    71  
    72  ```
    73      Swap(sender: Address, amount0In: U256, amount1In: U256, amount0Out: U256, amount1Out: U256, to: Address)
    74  ```
    75  
    76  The response of this endpoint also contains a field nextStart, 
    77  which is useful to continue fetching the next batch of events until it reaches to the end.
    78  
    79  2.
    80  ```curl https://node.mainnet.alephium.org/events/contract/2A5R8KZQ3rhKYrW7bAS4JTjY9FCFLJg6HjQpqSFZBqACX/current-count```
    81  
    82  This endpoint returns the current event count for this contract, 
    83  we can use this number of as the value to fetch events from now going forward
    84  
    85  The SDK has more dev friendly support for event subscription but it requires having the artifacts of the contracts, 
    86  otherwise we can use the above endpoints to poll the events. 
    87  We have written a general description of the event here (https://docs.alephium.org/dapps/events/), 
    88  which might be helpful as well.
    89  
    90  each token pairs has its own contract. You can do something like this to get all token pairs:
    91  ```
    92  curl https://backend.mainnet.alephium.org/contracts/vyrkJHG49TXss6pGAz2dVxq5o7mBXNNXAV18nAeqVT1R/sub-contracts?limit=100
    93  ```
    94  
    95  ## way to get token info
    96  
    97  Other than the token list, Fungible token contracts also implement a sets of standard interfaces to get name, symbol, decimals, etc. We can call these functions separately or in a single HTTP multi-call, e.g.
    98  
    99  ```
   100  
   101  > curl https://node.mainnet.alephium.org/contracts/multicall-contract -d '{"calls": [{"group":0, "address": "zSRgc7goAYUgYsEBYdAzogyyeKv3ne3uvWb3VDtxnaEK", "methodIndex": 0}, {"group":0, "address": "zSRgc7goAYUgYsEBYdAzogyyeKv3ne3uvWb3VDtxnaEK", "methodIndex": 1}, {"group":0, "address": "zSRgc7goAYUgYsEBYdAzogyyeKv3ne3uvWb3VDtxnaEK", "methodIndex": 2}, {"group":0, "address": "zSRgc7goAYUgYsEBYdAzogyyeKv3ne3uvWb3VDtxnaEK", "methodIndex": 3}]}'  | jq '.results | .[] | .returns'
   102  
   103  [
   104    {
   105      "type": "ByteVec",
   106      "value": "55534454"
   107    }
   108  ]
   109  [
   110    {
   111      "type": "ByteVec",
   112      "value": "546574686572205553442028416c706842726964676529"
   113    }
   114  ]
   115  [
   116    {
   117      "type": "U256",
   118      "value": "6"
   119    }
   120  ]
   121  [
   122    {
   123      "type": "U256",
   124      "value": "1786596516040"
   125    }
   126  ]
   127  ```
   128  
   129  Where zSRgc7goAYUgYsEBYdAzogyyeKv3ne3uvWb3VDtxnaEK is the USDT contract on Alephium, 
   130  
   131  55534454 is the hex reprentation of symbol (USDT), 
   132  
   133  546574686572205553442028416c706842726964676529 is the hex represenation of name (Tether USD (AlphBridge)), 
   134  
   135  6 is decimal, 
   136  
   137  1786596516040 is total supply
   138  
   139  This doc about fungible tokens might be helpful as well (https://docs.alephium.org/tokens/fungible-tokens)
   140  
   141  ## how to interpret swap event
   142  
   143  Given the token pair address 2A5R8KZQ3rhKYrW7bAS4JTjY9FCFLJg6HjQpqSFZBqACX, we can do 
   144  
   145  ```
   146  ➜  Blockchain curl https://node.mainnet.alephium.org/contracts/call-contract -d '{"address": "2A5R8KZQ3rhKYrW7bAS4JTjY9FCFLJg6HjQpqSFZBqACX", "methodIndex": 7, "group": 0}' jq .returns
   147  [
   148    {
   149      "type": "ByteVec",
   150      "value": "0000000000000000000000000000000000000000000000000000000000000000"
   151    },
   152    {
   153      "type": "ByteVec",
   154      "value": "556d9582463fe44fbd108aedc9f409f69086dc78d994b88ea6c9e65f8bf98e00"
   155    }
   156  ]
   157  ```
   158  to understand that in this token pair, the 1st token is ALPH (0000000000000000000000000000000000000000000000000000000000000000 is ALPH's special token id), and 2nd token is USDT. 
   159  
   160  In the swap event (which is mapped to fields in the response)
   161  ```
   162  event Swap(sender: Address, amount0In: U256, amount1In: U256, amount0Out: U256, amount1Out: U256, to: Address)
   163  ```
   164  
   165  if we are swapping from ALPH to USDT, then amount0In ((fields[1]) will be the amount for ALPH and amount1Out (fields[4]) will be the amount for USDT. 
   166  
   167  If we are swapping from USDT to ALPH, then amount1In ((fields[2]) will be the amount for USDT and amount0Out (fields[3]) will be the amount for ALPH.