import { multicall } from '../../utils' ; import { formatUnits } from '@ethersproject/units' ; import { BigNumber } from '@ethersproject/bignumber' ; export const author = 'dapplion' ; export const version = '0.1.0' ; const contractAbi = [ 'function balanceOf(address account) view returns (uint256)' , 'function earned(address account) view returns (uint256)' , 'function totalSupply() public view returns (uint256)' ] ; function bn ( num ) { return BigNumber . from ( num . toString ( ) ) ; } export async function strategy ( _space , network , provider , addresses , options , snapshot ) { const blockTag = typeof snapshot === 'number' ? snapshot : 'latest' ; let res = await multicall ( network , provider , contractAbi , [ [ options . lpTokenAddress , 'totalSupply' , [ ] ] , [ options . tokenAddress , 'balanceOf' , [ options . lpTokenAddress ] ] , ... addresses . map ( ( address ) => [ options . unipoolAddress , 'balanceOf' , [ address ] ] ) , ... addresses . map ( ( address ) => [ options . unipoolAddress , 'earned' , [ address ] ] ) ] , { blockTag } ) ; const lpTokenTotalSupply = bn ( res [ 0 ] ) ; const totalTokensInPool = bn ( res [ 1 ] ) ; res = res . slice ( 2 ) ; const usersTokensFromLp = res . slice ( 0 , addresses . length ) . map ( ( num ) => { const stakedLpTokens = bn ( num ) ; return stakedLpTokens . mul ( totalTokensInPool ) . div ( lpTokenTotalSupply ) ; } ) ; const usersEarnedTokensList = res . slice ( addresses . length ) . map ( ( num ) => { return bn ( num ) ; } ) ; const sumList = usersTokensFromLp . map ( ( userTokensFromLp , i ) => { return userTokensFromLp . add ( usersEarnedTokensList [ i ] ) ; } ) ; return Object . fromEntries ( sumList . map ( ( sum , i ) => { const parsedSum = parseFloat ( formatUnits ( sum , options . decimal ) ) ; return [ addresses [ i ] , parsedSum ] ; } ) ) ; }