import { formatUnits } from '@ethersproject/units' ; import { getBlockNumber } from '../../utils' ; import { multicall } from '../../utils' ; export const author = 'franckc' ; export const version = '0.1.0' ; const abi = [ 'function balanceOf(address account) external view returns (uint256)' , 'function totalStaked(address account) external view returns (uint256)' ] ; const numBlock30Days = ( 30 * 24 * 60 * 60 ) / 15 ; export async function strategy ( space , network , provider , addresses , options , snapshot ) { const blockTag1 = typeof snapshot === 'number' ? snapshot : await getBlockNumber ( provider ) ; const blockTag2 = blockTag1 - numBlock30Days ; const ognCalls = addresses . map ( ( address ) => [ options . ognAddress , 'balanceOf' , [ address ] ] ) ; const stakingCalls = addresses . map ( ( address ) => [ options . stakingAddress , 'totalStaked' , [ address ] ] ) ; const multicalls = [ multicall ( network , provider , abi , ognCalls , { blockTag : blockTag1 } ) , multicall ( network , provider , abi , ognCalls , { blockTag : blockTag2 } ) , multicall ( network , provider , abi , stakingCalls , { blockTag : blockTag1 } ) , multicall ( network , provider , abi , stakingCalls , { blockTag : blockTag2 } ) ] ; const responses = await Promise . all ( multicalls ) ; const scores = { } ; addresses . forEach ( ( address , i ) => { const balance = responses [ 0 ] [ i ] [ 0 ] . add ( responses [ 1 ] [ i ] [ 0 ] ) . add ( responses [ 2 ] [ i ] [ 0 ] ) . add ( responses [ 3 ] [ i ] [ 0 ] ) . div ( 2 ) ; scores [ address ] = parseFloat ( formatUnits ( balance . toString ( ) , options . decimals ) ) ; } ) ; return scores ; }