Skip to content

Commit 4e9f73f

Browse files
authored
Staking V3 Indexer and API endpoints (#579)
* Staking V3 Indexer and API endpoints * index tables and links * more endpoints and replit * replace replit with CodeSandBox * new field and url for codesandbox * update links * adding install tutorial * one link is good
1 parent a4559c3 commit 4e9f73f

File tree

3 files changed

+215
-1
lines changed

3 files changed

+215
-1
lines changed

docs/build/dapp-staking/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ If you are interested in developing on top of dApp Staking and integrating dApp
1616

1717
Learn how to integrate dApp staking into your EVM dApp in the precompiles chapter:
1818

19-
[EVM Precompiled Contracts](/docs/build/evm/precompiles/staking/)
19+
- [EVM Precompiled Contracts](/docs/build/evm/precompiles/staking/)
2020

2121
### Other page may be of interest:
2222

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# The API and the Indexer
2+
3+
The API is accessible from a [Swagger User Interface](https://api.astar.network/) to test the endpoints out.
4+
5+
:::info
6+
The API is available as a complimentary endpoint for developers with restricted usage and may not be appropriate for high-demand scenarios and continuous fetching of data. Users should note that excessive use could lead to instability of the free Token API. For those requiring high data availability, it is advisable to host their own API.
7+
:::
8+
9+
| | |
10+
| ------ | -------------------------------------------------------------- |
11+
| UI | https://api.astar.network/ |
12+
| API | https://api.astar.network/api/v3/{network}/dapps-staking/{...} |
13+
| Github | https://github.com/AstarNetwork/astar-token-api |
14+
15+
## Available endpoints
16+
17+
| Data | Endpoint, start with `/api/v3/{network}/dapps-staking` |
18+
| ------------------------------------------------------ | ------------------------------------------------------ |
19+
| List of dapps registed for staking | `/chaindapps` |
20+
| TVL for a given network and period | `/tvl/{period}` |
21+
| List of stakers per dapp with total stake | `/stakerslist/{contractAddress}` |
22+
| Stakers count for a given network for a dapp by period | `/stakerscount/{contractAddress}/{period}` |
23+
| Total stakers count for a given network and period | `/stakerscount-total/{period}` |
24+
| All reward events by type (optional) and network | `/rewards/{period}/?transaction=BonusReward,Reward` |
25+
| Aggregated daily rewards by staker or dapp by period | `/rewards-aggregated/{address}/{period}` |
26+
| Stake amount for one participant | `/stake-info/{address}` |
27+
28+
## The Indexer
29+
30+
The indexer is accessible from a [GraphQL Explorer UI](https://squid.subsquid.io/dapps-staking-indexer-shibuya/graphql).
31+
32+
| | |
33+
| ------ | -------------------------------------------------------------------- |
34+
| UI | https://squid.subsquid.io/dapps-staking-indexer-shibuya/graphql |
35+
| API | https://squid.subsquid.io/dapps-staking-indexer-shibuya/graphql |
36+
| Github | https://github.com/AstarNetwork/dapps-staking-indexer-v3 |
37+
38+
### Available indexes
39+
40+
| Table | Fields |
41+
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
42+
| dapps | beneficiary, dappId, id, owner, registeredAt, registrationBlockNumber, stakersCount, state, unregisteredAt, unregistrationBlockNumber |
43+
| dappAggregatedDailies | timestamp, stakersCount, id, dappAddress |
44+
| rewardEvents | amount, blockNumber, contractAddress, era, id, period, tierId, timestamp, transaction, userAddress |
45+
| rewardAggregatedDailies | amount, beneficiary, id, timestamp |
46+
| stakes | amount, dappAddress, stakerAddress, blockNumber, expiredAt, expiredBlockNumber, id, timestamp |
47+
| stakers | amount, dappAddress, stakerAddress, id |
48+
| stakersCount | total |
49+
| stakersCountAggregatedDailies | blockNumber, id, stakersCount, stakersAmount |
50+
| subperiods | blockNumber, id, timestamp, type |
51+
| tvlAggregatedDailies | blockNumber, id, tvl |
52+
| uniqueStakerAddresses | id |
53+
54+
## Coding Examples
55+
56+
To obtain data from the API, you can use a GET request like this:
57+
58+
```js
59+
async function getData() {
60+
try {
61+
const response = await fetch('https://api.astar.network/api/v3/shibuya/dapps-staking/chaindapps');
62+
if (!response.ok) {
63+
throw new Error(`HTTP error! status: ${response.status}`);
64+
}
65+
const data = await response.json();
66+
return data;
67+
} catch (error) {
68+
console.error('There was a problem fetching the data: ', error);
69+
}
70+
}
71+
```
72+
73+
To get data from the indexer directly in case the enpoint you want to use does not include the data you're looking for, uses a POST request like so:
74+
75+
```js
76+
async function tvlDaily() {
77+
const response = await fetch(
78+
"https://squid.subsquid.io/dapps-staking-indexer-shibuya/graphql", {
79+
method: "POST",
80+
headers: { "Content-Type": "application/json" },
81+
body: JSON.stringify({
82+
query: `
83+
query MyQuery {
84+
tvlAggregatedDailies(orderBy: id_ASC) {
85+
blockNumber
86+
id
87+
tvl
88+
}
89+
}
90+
`,
91+
}),
92+
next: { revalidate: 10 }
93+
}
94+
);
95+
const { data } = await response.json();
96+
return data?.tvlAggregatedDailies;
97+
}
98+
```
99+
100+
## Examples on CodeSandBox
101+
102+
```mdx-code-block
103+
import Iframe from 'react-iframe';
104+
105+
<iframe src="https://codesandbox.io/p/github/AstarNetwork/dapps-staking-v3-indexer-and-api-demo-ui/main?embed=1&file=%2Fpages%2Findex.tsx"
106+
width="100%"
107+
height="1000px"
108+
display="initial"
109+
position="relative"
110+
allowFullScreen
111+
title="gluneau/Graph-the-Astar-Staking-V3-GraphQL-Indexer-and-API/main"
112+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
113+
/>
114+
```
115+
116+
You can also look into [this repo](https://github.com/AstarNetwork/dapps-staking-v3-indexer-and-api-demo-ui) and clone and run it:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# How to Install and Run
2+
3+
## Indexder Installation
4+
5+
### 1. Prerequisites
6+
7+
- npm, node ≥ v16
8+
- git
9+
- docker
10+
- docker-compose with docker user & group
11+
12+
This is the list of install commands of the prerequisites for Ubuntu 22.04 for the program list above.
13+
14+
```bash
15+
# For node and npm
16+
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
17+
NODE_MAJOR=18
18+
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
19+
sudo apt update
20+
sudo apt install nodejs
21+
22+
# For docker
23+
sudo install -m 0755 -d /etc/apt/keyrings
24+
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
25+
sudo chmod a+r /etc/apt/keyrings/docker.asc
26+
echo \
27+
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
28+
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
29+
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
30+
sudo apt-get update
31+
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-compose
32+
sudo gpasswd -a $USER docker
33+
newgrp docker
34+
```
35+
36+
### 2. sqd CLI installation
37+
38+
Start by installing the @subsquid/cli command line interface globally with:
39+
40+
```bash
41+
sudo npm i -g @subsquid/cli
42+
43+
```
44+
45+
### 3. Cloning the repo
46+
47+
```jsx
48+
git clone [https://github.com/AstarNetwork/dapps-staking-indexer-v3](https://github.com/AstarNetwork/dapps-staking-indexer-v3)
49+
cd dapps-staking-indexer-v3
50+
```
51+
52+
## Run
53+
54+
Use the following commands to start the ingestion process:
55+
56+
```bash
57+
npm ci
58+
sqd up
59+
sqd process
60+
```
61+
62+
Next, start the GraphQL server in a separate terminal with:
63+
64+
```bash
65+
sqd serve
66+
```
67+
68+
## Develop
69+
70+
### Types
71+
72+
When changes are made to the rpc types, use the following commands:
73+
74+
```bash
75+
npm generate-metadata # for local node development
76+
sqd typegen # operates on metadata or rpc and modifies types
77+
```
78+
79+
### Schema
80+
81+
When you make changes to the schema, use the following commands:
82+
83+
```bash
84+
sqd codegen
85+
sqd build # modify your squid to use the new schema until it builds
86+
sqd down; sqd up
87+
sqd migration:generate # rerun everytime there is a change to the schema
88+
```
89+
90+
This drops then re-creates the database and regenerates any migrations.
91+
92+
## Deploy to the aquarium
93+
94+
There are 3 manifests, one for each network: astar, shiden and shibuya.
95+
96+
```bash
97+
sqd deploy . -r --org astar-network -m manifests/astar.yaml
98+
```

0 commit comments

Comments
 (0)