import { parseUnits } from '@ethersproject/units' ; import { BigNumber } from '@ethersproject/bignumber' ; import { Provider } from '@ethersproject/providers' ; export const GRAPH_NETWORK_SUBGRAPH_URL = { '1' : 'https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet' , '4' : 'https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-testnet' } ; export const bnWEI = BigNumber . from ( '1000000000000000000' ) ; export interface GraphAccountScores { [ key ] : number ; } export type GraphStrategyOptions = { symbol : string ; strategyType : string ; pageSize ? : number ; skip ? : number ; expectedResults ? : Record < string , any > ; } ; export type StrategyFunction = ( space : string , network : string , provider : Provider , addresses : string [ ] , options : GraphStrategyOptions , snapshot : string | number ) => Promise < Record < string , number > > ; /**
 * Pass in a BigDecimal and BigNumber from a subgraph query, and return the multiplication of
 * them as a BigNumber
 * */ export function bdMulBn ( bd , bn ) { const splitDecimal = bd . split ( '.' ) ; let split ; if ( splitDecimal . length > 1 ) { split = `${ splitDecimal [ 0 ] }.${ splitDecimal [ 1 ] . slice ( 0 , 18 ) }` ; } else { return BigNumber . from ( bn ) . mul ( BigNumber . from ( bd ) ) ; } const bdWithWEI = parseUnits ( split , 18 ) ; return BigNumber . from ( bn ) . mul ( bdWithWEI ) . div ( bnWEI ) ; } export function calcNonStakedTokens ( totalSupply , totalTokensStaked , totalDelegatedTokens ) { return BigNumber . from ( totalSupply ) . sub ( BigNumber . from ( totalTokensStaked ) ) . sub ( BigNumber . from ( totalDelegatedTokens ) ) . div ( bnWEI ) . toNumber ( ) ; } export function verifyResults ( result , expectedResults , type ) { const diff = `expected:\n ${ expectedResults }\ngot:\n ${ result }` ; result === expectedResults ? console . log ( `>>> SUCCESS: ${ type } match expected results` ) : console . error ( `>>> ERROR: ${ type } do not match expected results\n${ diff }` ) ; } export param { string [ ] } _array param { number } pageSize return { string [ ] [ ] } export function splitArray ( _array , pageSize ) { const chunks = [ ] ; for ( let i = 0 ; i < _array . length ; i += pageSize ) { chunks . push ( _array . slice ( i , i + pageSize ) ) ; } return chunks ; }