Skip to content

LuckyDapp/subquery-lucky-old

Repository files navigation

SubQuery - Index stakers for the dApp Lucky in Shibuya/Shiden/Astar Networks

This project index:

  • all accounts staking in the dApp 'Lucky' in the context of dAppStaking module
  • all developer rewards received by the dApp 'Lucky' in the context of dAppStaking module
  • all pending rewards distributed by the dApp 'Lucky'
  • all claimed rewards distributed by the dApp 'Lucky'

Preparation

Environment

  • Typescript are required to compile project and define types.

  • Both SubQuery CLI and generated Project have dependencies and require Node.

Install the SubQuery CLI

Install SubQuery CLI globally on your terminal by using NPM:

npm install -g @subql/cli

Run help to see available commands and usage provide by CLI

subql help

Clone the project

Inside the directory in which you want to create the SubQuery project, clone the project.

git clone https://github.com/LuckyDapp/subquery-lucky.git

Then you should see a folder with your project name has been created inside the directory, you can use this as the start point of your project. And the files should be identical as in the Directory Structure.

Install the dependencies

yarn install

Configure your project

In this package, an simple example of a project configuration has been provided. You will be mainly working on the following files:

  • The Manifest in project.yaml
  • The GraphQL Schema in schema.graphql
  • The Mapping functions in src/mappings/ directory

For more information on how to write the SubQuery, check out our doc section on Define the SubQuery

Code generation

In order to index your SubQuery project, it is mandatory to build your project first. Run this command under the project directory.

yarn codegen --file ./project-astar.yaml

Build the project

In order to deploy your SubQuery project to our hosted service, it is mandatory to pack your configuration before upload. Run pack command from root directory of your project will automatically generate a your-project-name.tgz file.

yarn build

Indexing and Query

Run required systems in docker

Under the project directory run following command:

yarn start:docker

Query the project

Open your browser and head to http://localhost:3000.

Finally, you should see a GraphQL playground is showing in the explorer and the schemas that ready to query.

Query data comming from dAppStaking module

Query amount staked by account via the dAppStaking

query {
  stakes{
    groupedAggregates(
      groupBy: [ACCOUNT_ID], 
      having: { sum: {amount: { notEqualTo: "0" }}}
    ) {
      sum{amount}, keys
    }
  }
}

Query amount staked by account for a given era

query {
  stakes(filter: { era: { lessThanOrEqualTo: "2100" }}) {
    groupedAggregates(
      groupBy: [ACCOUNT_ID], 
      having: { sum: { amount: { notEqualTo: "0" }}}
    ) {
      sum{amount}, keys
    }
  }
}

or

query {
    accounts {
        nodes {
            id
            stakes {        
                groupedAggregates(
                    groupBy: [ACCOUNT_ID], 
                    having: { sum: { amount: { notEqualTo: "0" }}}
                ) {     
      		        sum{amount}
      	        }
            }
  	    }
    }   
}

Query the dApp's rewards

query {
  developerRewards {
    aggregates {sum{amount}}
    nodes {amount, era}
  }
}

Query the dApp's rewards for a given era

query {
  developerRewards(filter: { era: { equalTo: "2100" } }) {
    nodes {amount, era}
  }
}

Query the last dApp's rewards

query {
  developerRewards(orderBy: ERA_DESC, first:1) {
    nodes {amount, era}
  }
}

Current era for the dApp Staking pallet

query {
  palletInfos {
    nodes {
      currentEra
    }
  }
}

Query data comming from the dApp 'Lucky'

Query the total stake and the rewards distributed by account

query {  
  accounts{
    nodes{
      id, 
      totalStake, 
      totalRewards, 
      totalPending, 
      totalClaimed,
      rewards{nodes{era, amount}},
      rewardsClaimed{nodes{amount}}
    }    
  }
}

Query a specific account

query {  
  accounts(filter : {id: {equalTo: "5C...hM"}}){
    nodes{
      id,
      totalStake, 
      totalRewards, 
      totalPending, 
      totalClaimed,
      rewards{nodes{era, amount}},
      rewardsClaimed{nodes{amount}}
    }  
  } 
}