import { getDelegations } from '../../utils/delegation' ; import { getScoresDirect } from '../../utils' ; export const author = 'bonustrack' ; export const version = '0.1.0' ; export async function strategy ( space , network , provider , addresses , options , snapshot ) { const delegations = await getDelegations ( space , network , addresses , snapshot ) ; if ( Object . keys ( delegations ) . length === 0 ) return { } ; const scores = ( await getScoresDirect ( space , options . strategies , network , provider , Object . values ( delegations ) . reduce ( ( a , b ) => a . concat ( b ) ) , snapshot ) ) . filter ( ( score ) => Object . keys ( score ) . length !== 0 ) ; return Object . fromEntries ( addresses . map ( ( address ) => { const addressScore = delegations [ address ] ? delegations [ address ] . reduce ( ( a , b ) => a + scores . reduce ( ( x , y ) => ( y [ b ] ? x + y [ b ] : x ) , 0 ) , 0 ) : 0 ; return [ address , addressScore ] ; } ) ) ; }