src/static/js/avax_tundra.js
// use a customized loader to show APRs and details before emissions start
use a customized loader to show APRs and details before emissions start
use a customized loader to show APRs and details before emissions start
async function loadCustomAvaxChefContract(App, tokens, prices, chef, chefAddress, chefAbi, rewardTokenTicker,
    rewardTokenFunction, rewardsPerBlockFunction, rewardsPerWeekFixed, pendingRewardsFunction,
    deathPoolIndices, ignoredPools) {
      const chefContract = chef ?? new ethers.Contract(chefAddress, chefAbi, App.provider);
      const poolCount = parseInt(await chefContract.poolLength(), 10);
      const totalAllocPoints = await chefContract.totalAllocPoint();
      _print(`Found ${poolCount} pools.\n`)
      _print(`Showing incentivized pools only.\n`);
      var tokens = {};
      const rewardTokenAddress = await chefContract.callStatic[rewardTokenFunction]();
      const rewardToken = await getAvaxToken(App, rewardTokenAddress, chefAddress);
      const rewardsPerWeek = rewardsPerWeekFixed ?? 
        await chefContract.callStatic[rewardsPerBlockFunction]() 
        / 10 ** rewardToken.decimals * 604800;
      const poolInfos = await Promise.all([...Array(poolCount).keys()].map(async (x) =>
        ignoredPools?.includes(x) ? null :
        await getAvaxPoolInfo(App, chefContract, chefAddress, x, pendingRewardsFunction)));
      var tokenAddresses = [].concat.apply([], poolInfos.filter(x => x?.poolToken).map(x => x.poolToken.tokens));
      await Promise.all(tokenAddresses.map(async (address) => {
          tokens[address] = await getAvaxToken(App, address, chefAddress);
      }));
      if (deathPoolIndices) {   
        deathPoolIndices.map(i => poolInfos[i])
                          .map(poolInfo => 
          poolInfo?.poolToken ? getPoolPrices(tokens, prices, poolInfo.poolToken, "avax") : undefined);
      }
      const poolPrices = poolInfos.map(poolInfo => poolInfo?.poolToken ? getPoolPrices(tokens, prices, poolInfo.poolToken, "avax") : undefined);
      _print("Finished reading smart contracts.\n");
      let aprs = []
      for (let i = 0; i < poolCount; i++) {
        let foundTokenData;
        const _tokenKeys = LOOKUP_TOKENS && Object.keys(LOOKUP_TOKENS)
        for (let j = 0; _tokenKeys && j < _tokenKeys.length; j++) {
          const _key = _tokenKeys[j]
          if (i.toString() === _key)
            foundTokenData = await getCustomQuote(App, LOOKUP_TOKENS[_key].lpAddr, LOOKUP_TOKENS[_key].abi, LOOKUP_TOKENS[_key].mc);
        }
        if (poolPrices[i]) {
          const apr = printCustomChefPool(App, chefAbi, chefAddress, prices, tokens, poolInfos[i], i, poolPrices[i],
            totalAllocPoints, rewardsPerWeek, rewardTokenTicker, rewardTokenAddress, pendingRewardsFunction,
            8, null, "avax", poolInfos[i].depositFee, poolInfos[i].withdrawFee, foundTokenData)
          aprs.push(apr);
        }
      }
      let totalUserStaked=0, totalStaked=0, averageApr=0;
      for (const a of aprs) {
        if (!isNaN(a.totalStakedUsd)) {
          totalStaked += a.totalStakedUsd;
        }
        if (a.userStakedUsd > 0) {
          totalUserStaked += a.userStakedUsd;
          averageApr += a.userStakedUsd * a.yearlyAPR / 100;
        }
      }
      averageApr = averageApr / totalUserStaked;
      _print_bold(`Total Staked: $${formatMoney(totalStaked)}`);
      if (totalUserStaked > 0) {
        _print_bold(`\nYou are staking a total of $${formatMoney(totalUserStaked)} at an average APR of ${(averageApr * 100).toFixed(2)}%`)
        _print(`Estimated earnings:`
            + ` Day $${formatMoney(totalUserStaked*averageApr/365)}`
            + ` Week $${formatMoney(totalUserStaked*averageApr/52)}`
            + ` Year $${formatMoney(totalUserStaked*averageApr)}\n`);
      }
      return { prices, totalUserStaked, totalStaked, averageApr }
  }
async function loadCustomAvaxChefContract ( App , tokens , prices , chef , chefAddress , chefAbi , rewardTokenTicker , rewardTokenFunction , rewardsPerBlockFunction , rewardsPerWeekFixed , pendingRewardsFunction , deathPoolIndices , ignoredPools ) { const chefContract = chef ?? new ethers . Contract ( chefAddress , chefAbi , App . provider ) ; const poolCount = parseInt ( await chefContract . poolLength ( ) , 10 ) ; const totalAllocPoints = await chefContract . totalAllocPoint ( ) ; _print ( ` ${ poolCount } \n ` ) _print ( ` \n ` ) ; var tokens = { } ; const rewardTokenAddress = await chefContract . callStatic [ rewardTokenFunction ] ( ) ; const rewardToken = await getAvaxToken ( App , rewardTokenAddress , chefAddress ) ; const rewardsPerWeek = rewardsPerWeekFixed ?? await chefContract . callStatic [ rewardsPerBlockFunction ] ( ) / 10 ** rewardToken . decimals * 604800 ; const poolInfos = await Promise . all ( [ ... Array ( poolCount ) . keys ( ) ] . map ( async ( x ) => ignoredPools ?. includes ( x ) ? null : await getAvaxPoolInfo ( App , chefContract , chefAddress , x , pendingRewardsFunction ) ) ) ; var tokenAddresses = [ ] . concat . apply ( [ ] , poolInfos . filter ( x => x ?. poolToken ) . map ( x => x . poolToken . tokens ) ) ; await Promise . all ( tokenAddresses . map ( async ( address ) => { tokens [ address ] = await getAvaxToken ( App , address , chefAddress ) ; } ) ) ; if ( deathPoolIndices ) { deathPoolIndices . map ( i => poolInfos [ i ] ) . map ( poolInfo => poolInfo ?. poolToken ? getPoolPrices ( tokens , prices , poolInfo . poolToken , "avax" ) : undefined ) ; } const poolPrices = poolInfos . map ( poolInfo => poolInfo ?. poolToken ? getPoolPrices ( tokens , prices , poolInfo . poolToken , "avax" ) : undefined ) ; _print ( "Finished reading smart contracts.\n" ) ; let aprs = [ ] for ( let i = 0 ; i < poolCount ; i ++ ) { let foundTokenData ; const _tokenKeys = LOOKUP_TOKENS && Object . keys ( LOOKUP_TOKENS ) for ( let j = 0 ; _tokenKeys && j < _tokenKeys . length ; j ++ ) { const _key = _tokenKeys [ j ] if ( i . toString ( ) === _key ) foundTokenData = await getCustomQuote ( App , LOOKUP_TOKENS [ _key ] . lpAddr , LOOKUP_TOKENS [ _key ] . abi , LOOKUP_TOKENS [ _key ] . mc ) ; } if ( poolPrices [ i ] ) { const apr = printCustomChefPool ( App , chefAbi , chefAddress , prices , tokens , poolInfos [ i ] , i , poolPrices [ i ] , totalAllocPoints , rewardsPerWeek , rewardTokenTicker , rewardTokenAddress , pendingRewardsFunction , 8 , null , "avax" , poolInfos [ i ] . depositFee , poolInfos [ i ] . withdrawFee , foundTokenData ) aprs . push ( apr ) ; } } let totalUserStaked = 0 , totalStaked = 0 , averageApr = 0 ; for ( const a of aprs ) { if ( ! isNaN ( a . totalStakedUsd ) ) { totalStaked += a . totalStakedUsd ; } if ( a . userStakedUsd > 0 ) { totalUserStaked += a . userStakedUsd ; averageApr += a . userStakedUsd * a . yearlyAPR / 100 ; } } averageApr = averageApr / totalUserStaked ; _print_bold ( ` ${ formatMoney ( totalStaked ) } ` ) ; if ( totalUserStaked > 0 ) { _print_bold ( ` \n ${ formatMoney ( totalUserStaked ) } ${ ( averageApr * 100 ) . toFixed ( 2 ) } ` ) _print ( ` ` + ` ${ formatMoney ( totalUserStaked * averageApr / 365 ) } ` + ` ${ formatMoney ( totalUserStaked * averageApr / 52 ) } ` + ` ${ formatMoney ( totalUserStaked * averageApr ) } \n ` ) ; } return { prices , totalUserStaked , totalStaked , averageApr } }
use a customized loader to show APRs and details before emissions start
use a customized loader to show APRs and details before emissions start
//load prices for the deathpool assets