import { BigNumber } from '@ethersproject/bignumber' ; import { FundingCycle } from 'models/funding-cycle' ; import { fromWad , parsePerbicent } from './formatNumber' ; import { decodeFundingCycleMetadata } from './fundingCycle' ; export const weightedRate = ( fc , wad , output ) => { if ( ! fc || ! wad ) return ; const reserved = decodeFundingCycleMetadata ( fc . metadata ) ?. reservedRate ; if ( reserved === undefined ) return ; return fromWad ( fc . weight . mul ( wad ) . mul ( output === 'reserved' ? reserved : parsePerbicent ( 100 ) . sub ( reserved ) ) . div ( 200 ) ) ; } ; export const feeForAmount = ( amount , feePercent ) => { if ( ! feePercent || ! amount ) return ; return amount . sub ( amount . mul ( 200 ) . div ( feePercent . add ( 200 ) ) ) ; } ; export const amountSubFee = ( amount ? , feePercent ? ) => { if ( ! feePercent || ! amount ) return ; return amount . sub ( feeForAmount ( amount , feePercent ) ?? 0 ) ; } ; export const amountAddFee = ( amount ? , feePercent ? ) => { if ( ! feePercent || ! amount ) return ; return amount . add ( amount . mul ( 100 ) . div ( feePercent . mul ( 200 ) ) ) ; } ;