import { BigNumber , BigNumberish , formatFixed , parseFixed , } from '@ethersproject/bignumber' ; import { Zero } from '@ethersproject/constants' ; import { bnum , ZERO } from '../utils/bignumber' ; import * as weightedMath from '../pools/weightedPool/weightedMath' ; import { WeightedPoolPairData } from '../pools/weightedPool/weightedPool' ; export function BPTForTokensZeroPriceImpact ( balances , decimals , normalizedWeights , amounts , bptTotalSupply ) { const amountBPTOut = amounts . reduce ( ( totalBptOut , amountIn , i ) => { const poolPairData = { balanceIn : balances [ i ] , decimalsIn : decimals [ i ] , balanceOut : bptTotalSupply , weightIn : normalizedWeights [ i ] , swapFee : Zero , } as WeightedPoolPairData ; const BPTPrice = weightedMath . _spotPriceAfterSwapTokenInForExactBPTOut ( ZERO , poolPairData ) ; const downscaledAmountIn = formatFixed ( amountIn , decimals [ i ] ) ; const downscaledBptOut = bnum ( downscaledAmountIn ) . div ( BPTPrice ) . toString ( ) ; return BigNumber . from ( totalBptOut ) . add ( parseFixed ( downscaledBptOut , 18 ) ) ; } , Zero ) ; return BigNumber . from ( amountBPTOut ) ; }