import { subgraphRequest } from '../../utils' ; import { Multicaller , getProvider } from '../../utils' ; import { formatUnits } from '@ethersproject/units' ; export const author = 'drgorillamd' ; export const version = '1.0.0' ; const abi = [ 'function balanceOf(address account) external view returns (uint256)' , 'function totalSupply() external view returns (uint256)' ] ; const BUSD = '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56' ; const WAVAX = '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7' ; const USDC = '0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664' ; const WAVAXUSDC = '0xA389f9430876455C36478DeEa9769B7Ca4E3DDB1' ; export async function strategy ( space , network , provider , addresses , options , snapshot ) { const blockTag = typeof snapshot === 'number' ? snapshot : 'latest' ; const block = await provider . getBlock ( blockTag ) ; const timestamp = block . timestamp ; const avaxBlockTag = await getAvaxBlockTag ( timestamp , options ) ; const multiBsc = new Multicaller ( network , provider , abi , { blockTag } ) ; addresses . forEach ( ( address ) => { multiBsc . call ( address + '-jade' , options . JADE . address , 'balanceOf' , [ address ] ) ; multiBsc . call ( address + '-sjade' , options . SJADE . address , 'balanceOf' , [ address ] ) ; } ) ; multiBsc . call ( 'jadeLPBalance' , options . JADE . address , 'balanceOf' , [ options . JADELP . address ] ) ; multiBsc . call ( 'busdLPBalance' , BUSD , 'balanceOf' , [ options . JADELP . address ] ) ; const multiAvax = new Multicaller ( '43114' , getProvider ( '43114' ) , abi , { blockTag : avaxBlockTag } ) ; addresses . forEach ( ( address ) => { multiAvax . call ( address + '-smrt' , options . SMRT . address , 'balanceOf' , [ address ] ) ; multiAvax . call ( address + '-smrtR' , options . SMRTR . address , 'balanceOf' , [ address ] ) ; multiAvax . call ( address + '-smrtRLp' , options . SMRTRLP . address , 'balanceOf' , [ address ] ) ; } ) ; multiAvax . call ( 'smrtLPBalance' , options . SMRT . address , 'balanceOf' , [ options . SMRTLP . address ] ) ; multiAvax . call ( 'wavaxSmrtLPBalance' , WAVAX , 'balanceOf' , [ options . SMRTLP . address ] ) ; multiAvax . call ( 'smrtRLPBalance' , options . SMRTR . address , 'balanceOf' , [ options . SMRTRLP . address ] ) ; multiAvax . call ( 'wavaxSmrtRLPBalance' , WAVAX , 'balanceOf' , [ options . SMRTRLP . address ] ) ; multiAvax . call ( 'UsdLPBalance' , USDC , 'balanceOf' , [ WAVAXUSDC ] ) ; multiAvax . call ( 'wavaxUsdLPBalance' , WAVAX , 'balanceOf' , [ WAVAXUSDC ] ) ; multiAvax . call ( 'smrtRLPSupply' , options . SMRTRLP . address , 'totalSupply' , [ ] ) ; let resBsc = { 0 : 0 } , resAvax = [ 0 , 0 , 0 , { 0 : 0 } , { 0 : 0 } ] ; [ resBsc , resAvax ] = await Promise . all ( [ multiBsc . execute ( ) , multiAvax . execute ( ) ] ) ; const jadePrice = parseFloat ( formatUnits ( resBsc [ 'busdLPBalance' ] , 18 ) ) / parseFloat ( formatUnits ( resBsc [ 'jadeLPBalance' ] , 9 ) ) ; const wavaxPrice = parseFloat ( formatUnits ( resAvax [ 'UsdLPBalance' ] , 6 ) ) / parseFloat ( formatUnits ( resAvax [ 'wavaxUsdLPBalance' ] , 18 ) ) ; const smrtPrice = wavaxPrice / ( parseFloat ( formatUnits ( resAvax [ 'smrtLPBalance' ] , 18 ) ) / parseFloat ( formatUnits ( resAvax [ 'wavaxSmrtLPBalance' ] , 18 ) ) ) ; const smrtRPrice = wavaxPrice / ( parseFloat ( formatUnits ( resAvax [ 'smrtRLPBalance' ] , 18 ) ) / parseFloat ( formatUnits ( resAvax [ 'wavaxSmrtRLPBalance' ] , 18 ) ) ) ; const smrtRLPBalance = parseFloat ( formatUnits ( resAvax [ 'smrtRLPBalance' ] , 18 ) ) ; const smrtRLPSupply = parseFloat ( formatUnits ( resAvax [ 'smrtRLPSupply' ] , 18 ) ) ; return Object . fromEntries ( addresses . map ( ( adr ) => { let bal = parseFloat ( formatUnits ( resBsc [ adr + '-jade' ] , options . JADE . decimals ) ) ; bal += parseFloat ( formatUnits ( resBsc [ adr + '-sjade' ] , options . SJADE . decimals ) ) ; const parsedSmrt = parseFloat ( formatUnits ( resAvax [ adr + '-smrt' ] , options . SMRT . decimals ) ) ; bal += ( parsedSmrt * smrtPrice ) / jadePrice ; const parsedSrmtr = parseFloat ( formatUnits ( resAvax [ adr + '-smrtR' ] , options . SMRTR . decimals ) ) ; bal += ( parsedSrmtr * smrtRPrice ) / jadePrice ; const LPHeld = ( parseFloat ( formatUnits ( resAvax [ adr + '-smrtRLp' ] , 18 ) ) * smrtRLPBalance ) / smrtRLPSupply ; bal += ( LPHeld * smrtRPrice ) / jadePrice ; return [ adr , bal ] ; } ) ) ; } async function getAvaxBlockTag ( timestamp , options ) { const query = { blocks : { __args : { first : 1 , orderBy : 'number' , orderDirection : 'desc' , where : { timestamp_lte : timestamp } } , number : true , timestamp : true } } ; const data = await subgraphRequest ( options . avaxGraph , query ) ; return Number ( data . blocks [ 0 ] . number ) ; }