Switch to pool size instead of volume for creator leaderboard.

This commit is contained in:
James Grugett 2022-02-19 12:14:45 -06:00
parent 0641db1f2d
commit 693652935d

View File

@ -22,20 +22,22 @@ export const updateUserMetrics = functions.pubsub
contracts.map((contract) => [contract.id, contract])
)
for (const user of users) {
const [investmentValue, creatorVolume] = await Promise.all([
computeInvestmentValue(user, contractsDict),
computeTotalVolume(user, contractsDict),
])
await Promise.all(
users.map(async (user) => {
const [investmentValue, creatorVolume] = await Promise.all([
computeInvestmentValue(user, contractsDict),
computeTotalPool(user, contractsDict),
])
const totalValue = user.balance + investmentValue
const totalPnL = totalValue - user.totalDeposits
const totalValue = user.balance + investmentValue
const totalPnL = totalValue - user.totalDeposits
await firestore.collection('users').doc(user.id).update({
totalPnLCached: totalPnL,
creatorVolumeCached: creatorVolume,
await firestore.collection('users').doc(user.id).update({
totalPnLCached: totalPnL,
creatorVolumeCached: creatorVolume,
})
})
}
)
})
const computeInvestmentValue = async (
@ -54,15 +56,17 @@ const computeInvestmentValue = async (
})
}
const computeTotalVolume = async (
const computeTotalPool = async (
user: User,
contractsDict: _.Dictionary<Contract>
) => {
const creatorContracts = Object.values(contractsDict).filter(
(contract) => contract.creatorId === user.id
)
const volumes = await Promise.all(creatorContracts.map(computeVolume))
return _.sum(volumes)
const pools = creatorContracts.map((contract) =>
_.sum(Object.values(contract.pool))
)
return _.sum(pools)
}
const computeVolume = async (contract: Contract) => {