"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TheGraph = void 0;
const axios = require('axios').default;
class TheGraph {
    async request(url, params) {
        const response = await axios.post(url, {
            query: params.query,
            variables: params.variables,
        });
        return response.data;
    }
    async requestBQTopHolders(token, blockNumber, numHolders) {
        const url = 'https://graphql.bitquery.io/';
        const query = `
    query HoldersQuery($heightMin: Int!, $heightMax: Int!, $token: String!, $top: Int!) {
      ethereum {
        transfers(
          success: true
          options: {desc: "amount", offset: 0, limit: $top}
          height: {gt: $heightMin, lt: $heightMax }
          currency: {is: $token}
        ) {
          receiver {
            uniq: address
          }
          amount
        }
      }
    }
    `;
        const response = await axios.request({
            url: url,
            method: 'post',
            data: {
                query: query,
                variables: {
                    heightMax: blockNumber,
                    heightMin: blockNumber - 1000,
                    token: token,
                    top: numHolders,
                },
            },
            headers: {
                'Content-Type': 'application/json',
                'X-API-KEY': 'BQYFdipbXpd2mR9gj3Zzujd0hKVaATij',
            },
        });
        // Strip to addresses
        const results = [];
        for (const element of response.data.data.ethereum.transfers) {
            results.push(element.receiver.uniq);
        }
        return results;
    }
}
exports.TheGraph = TheGraph;
