import axios from "axios" ; import { BN , simpleToExactAmount } from "@utils/math" ; import { PMTA } from "./tokens" ; import { logger } from "./deploy-utils" ; const log = logger ( "emission" , "disperse-bal" ) ; const REPORT_URL = "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports" ; interface DisperseDetails { total : BN ; recipients : Array < string > ; values : Array < BN > ; } interface BalancerReward { address : string ; amount : string ; } interface BalancerDetails { total : BN ; rewards : Array < BalancerReward > ; } interface BalancerPolygonReport { disperser : DisperseDetails ; balancer : BalancerDetails ; } param { number } report return { Promise } export const fetchBalancerReport = async ( report ) : Promise < Array < { address : string ; amount : string ; } > > => { const url = `${ REPORT_URL }/${ report }/__polygon_${ PMTA . address }.json` ; log ( `fetches balancer-labs report ${ report }` ) ; log ( `downloads report from url :${ url }` ) ; const response = await axios . get ( url ) ; return Object . entries ( response . data ) . map ( ( [ address , amount ] ) => { const amountStr = typeof amount === "string" ? amount : ( amount as string ) ; return { address , amount : amountStr } ; } ) ; } ; dev param { number } report param { BN } mtaBalance return { Promise } export const getBalancerPolygonReport = async ( report , mtaBalance ) : Promise < BalancerPolygonReport > => { const disperseRecipients = [ ] ; const disperseValues = [ ] ; const balancerRewards = await fetchBalancerReport ( report ) ; let disperseTotal = BN . from ( 0 ) ; const balancerTotal = balancerRewards . reduce ( ( sum , reward ) => sum . add ( simpleToExactAmount ( reward . amount , 18 ) ) , BN . from ( 0 ) ) ; balancerRewards . forEach ( ( reward ) => { const disperseRewardAmount = simpleToExactAmount ( reward . amount , 18 ) . mul ( mtaBalance ) . div ( balancerTotal ) ; disperseRecipients . push ( reward . address ) ; disperseValues . push ( disperseRewardAmount ) ; disperseTotal = disperseTotal . add ( disperseRewardAmount ) ; } ) ; log ( `total mta token amount to disperser[${ disperseTotal . toString ( ) }], total recipients count [${ disperseRecipients . length }]` ) ; return { disperser : { total : disperseTotal , recipients : disperseRecipients , values : disperseValues } , balancer : { total : balancerTotal , rewards : balancerRewards } , } ; } ;