Revert "Fix free response MKT calculation to use probs from resolutions field, client-side."
This reverts commit c12063799f.
			
			
This commit is contained in:
		
							parent
							
								
									c12063799f
								
							
						
					
					
						commit
						11730e48a2
					
				|  | @ -1,6 +1,6 @@ | |||
| import * as _ from 'lodash' | ||||
| import { Bet } from './bet' | ||||
| import { Binary, DPM, FreeResponse, FullContract } from './contract' | ||||
| import { Binary, DPM, FullContract } from './contract' | ||||
| import { DPM_FEES } from './fees' | ||||
| 
 | ||||
| export function getDpmProbability(totalShares: { [outcome: string]: number }) { | ||||
|  | @ -213,27 +213,24 @@ function calculateMktDpmPayout(contract: FullContract<DPM, any>, bet: Bet) { | |||
|   if (contract.outcomeType === 'BINARY') | ||||
|     return calculateBinaryMktDpmPayout(contract, bet) | ||||
| 
 | ||||
|   const { totalShares, pool, resolutions } = contract as FullContract< | ||||
|     DPM, | ||||
|     FreeResponse | ||||
|   > | ||||
| 
 | ||||
|   if (!resolutions) | ||||
|     throw new Error( | ||||
|       'resolutions required for MKT payout of free response market' | ||||
|     ) | ||||
|   const { totalShares, pool } = contract | ||||
| 
 | ||||
|   const totalPool = _.sum(Object.values(pool)) | ||||
|   const probTotal = _.sum(Object.values(resolutions)) | ||||
|   const sharesSquareSum = _.sumBy( | ||||
|     Object.values(totalShares) as number[], | ||||
|     (shares) => shares ** 2 | ||||
|   ) | ||||
| 
 | ||||
|   const weightedShareTotal = _.sumBy(Object.keys(resolutions), (outcome) => { | ||||
|     const prob = resolutions[outcome] / probTotal | ||||
|     return prob * totalShares[outcome] | ||||
|   const weightedShareTotal = _.sumBy(Object.keys(totalShares), (outcome) => { | ||||
|     // Avoid O(n^2) by reusing sharesSquareSum for prob.
 | ||||
|     const shares = totalShares[outcome] | ||||
|     const prob = shares ** 2 / sharesSquareSum | ||||
|     return prob * shares | ||||
|   }) | ||||
| 
 | ||||
|   const { outcome, amount, shares } = bet | ||||
| 
 | ||||
|   const betP = (resolutions[outcome] ?? 0) / probTotal | ||||
|   const betP = getDpmOutcomeProbability(totalShares, outcome) | ||||
|   const winnings = ((betP * shares) / weightedShareTotal) * totalPool | ||||
| 
 | ||||
|   return deductDpmFees(amount, winnings) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user