From fc06b03af8cd50cee8f3cd672333343faac2e7ff Mon Sep 17 00:00:00 2001 From: mantikoros Date: Sat, 9 Jul 2022 22:39:26 -0400 Subject: [PATCH] fix getCpmmLiquidityPoolWeights --- common/calculate-cpmm.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/calculate-cpmm.ts b/common/calculate-cpmm.ts index 8a609970..66162132 100644 --- a/common/calculate-cpmm.ts +++ b/common/calculate-cpmm.ts @@ -1,4 +1,4 @@ -import { sum, groupBy, mapValues, sumBy } from 'lodash' +import { sum, groupBy, mapValues, sumBy, zip } from 'lodash' import { CPMMContract } from './contract' import { CREATOR_FEE, Fees, LIQUIDITY_FEE, PLATFORM_FEE } from './fees' @@ -275,16 +275,16 @@ export function getCpmmLiquidityPoolWeights( const liquidityShares = liquidities.map(calcLiqudity) const shareSum = sum(liquidityShares) - const includedLiquidities = excludeAntes - ? liquidityShares.filter((_, i) => !liquidities[i].isAnte) - : liquidityShares - - const weights = includedLiquidities.map((s, i) => ({ - weight: s / shareSum, + const weights = liquidityShares.map((shares, i) => ({ + weight: shares / shareSum, providerId: liquidities[i].userId, })) - const userWeights = groupBy(weights, (w) => w.providerId) + const includedWeights = excludeAntes + ? weights.filter((_, i) => !liquidities[i].isAnte) + : weights + + const userWeights = groupBy(includedWeights, (w) => w.providerId) const totalUserWeights = mapValues(userWeights, (userWeight) => sumBy(userWeight, (w) => w.weight) )