rename dpm calculations
This commit is contained in:
parent
e80926d201
commit
42577b20a9
|
@ -1,5 +1,5 @@
|
||||||
import { Bet } from './bet'
|
import { Bet } from './bet'
|
||||||
import { getProbability } from './calculate-dpm'
|
import { getDpmProbability } from './calculate-dpm'
|
||||||
import { getCpmmProbability } from './calculate-cpmm'
|
import { getCpmmProbability } from './calculate-cpmm'
|
||||||
import { Binary, CPMM, DPM, FreeResponse, FullContract } from './contract'
|
import { Binary, CPMM, DPM, FreeResponse, FullContract } from './contract'
|
||||||
import { User } from './user'
|
import { User } from './user'
|
||||||
|
@ -67,7 +67,7 @@ export function getAnteBets(
|
||||||
yesAnteId: string,
|
yesAnteId: string,
|
||||||
noAnteId: string
|
noAnteId: string
|
||||||
) {
|
) {
|
||||||
const p = getProbability(contract.totalShares)
|
const p = getDpmProbability(contract.totalShares)
|
||||||
const ante = contract.totalBets.YES + contract.totalBets.NO
|
const ante = contract.totalBets.YES + contract.totalBets.NO
|
||||||
|
|
||||||
const { createdTime } = contract
|
const { createdTime } = contract
|
||||||
|
|
|
@ -3,12 +3,12 @@ import { Bet } from './bet'
|
||||||
import { Binary, DPM, FullContract } from './contract'
|
import { Binary, DPM, FullContract } from './contract'
|
||||||
import { FEES } from './fees'
|
import { FEES } from './fees'
|
||||||
|
|
||||||
export function getProbability(totalShares: { [outcome: string]: number }) {
|
export function getDpmProbability(totalShares: { [outcome: string]: number }) {
|
||||||
// For binary contracts only.
|
// For binary contracts only.
|
||||||
return getOutcomeProbability(totalShares, 'YES')
|
return getDpmOutcomeProbability(totalShares, 'YES')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getOutcomeProbability(
|
export function getDpmOutcomeProbability(
|
||||||
totalShares: {
|
totalShares: {
|
||||||
[outcome: string]: number
|
[outcome: string]: number
|
||||||
},
|
},
|
||||||
|
@ -19,22 +19,22 @@ export function getOutcomeProbability(
|
||||||
return shares ** 2 / squareSum
|
return shares ** 2 / squareSum
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getProbabilityAfterBet(
|
export function getDpmProbabilityAfterBet(
|
||||||
totalShares: {
|
totalShares: {
|
||||||
[outcome: string]: number
|
[outcome: string]: number
|
||||||
},
|
},
|
||||||
outcome: string,
|
outcome: string,
|
||||||
bet: number
|
bet: number
|
||||||
) {
|
) {
|
||||||
const shares = calculateShares(totalShares, bet, outcome)
|
const shares = calculateDpmShares(totalShares, bet, outcome)
|
||||||
|
|
||||||
const prevShares = totalShares[outcome] ?? 0
|
const prevShares = totalShares[outcome] ?? 0
|
||||||
const newTotalShares = { ...totalShares, [outcome]: prevShares + shares }
|
const newTotalShares = { ...totalShares, [outcome]: prevShares + shares }
|
||||||
|
|
||||||
return getOutcomeProbability(newTotalShares, outcome)
|
return getDpmOutcomeProbability(newTotalShares, outcome)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getProbabilityAfterSale(
|
export function getDpmProbabilityAfterSale(
|
||||||
totalShares: {
|
totalShares: {
|
||||||
[outcome: string]: number
|
[outcome: string]: number
|
||||||
},
|
},
|
||||||
|
@ -45,10 +45,10 @@ export function getProbabilityAfterSale(
|
||||||
const newTotalShares = { ...totalShares, [outcome]: prevShares - shares }
|
const newTotalShares = { ...totalShares, [outcome]: prevShares - shares }
|
||||||
|
|
||||||
const predictionOutcome = outcome === 'NO' ? 'YES' : outcome
|
const predictionOutcome = outcome === 'NO' ? 'YES' : outcome
|
||||||
return getOutcomeProbability(newTotalShares, predictionOutcome)
|
return getDpmOutcomeProbability(newTotalShares, predictionOutcome)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculateShares(
|
export function calculateDpmShares(
|
||||||
totalShares: {
|
totalShares: {
|
||||||
[outcome: string]: number
|
[outcome: string]: number
|
||||||
},
|
},
|
||||||
|
@ -63,7 +63,7 @@ export function calculateShares(
|
||||||
return Math.sqrt(bet ** 2 + shares ** 2 + c) - shares
|
return Math.sqrt(bet ** 2 + shares ** 2 + c) - shares
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculateRawShareValue(
|
export function calculateDpmRawShareValue(
|
||||||
totalShares: {
|
totalShares: {
|
||||||
[outcome: string]: number
|
[outcome: string]: number
|
||||||
},
|
},
|
||||||
|
@ -85,7 +85,7 @@ export function calculateRawShareValue(
|
||||||
return currentValue - postSaleValue
|
return currentValue - postSaleValue
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculateMoneyRatio(
|
export function calculateDpmMoneyRatio(
|
||||||
contract: FullContract<DPM, any>,
|
contract: FullContract<DPM, any>,
|
||||||
bet: Bet,
|
bet: Bet,
|
||||||
shareValue: number
|
shareValue: number
|
||||||
|
@ -93,7 +93,7 @@ export function calculateMoneyRatio(
|
||||||
const { totalShares, totalBets, pool } = contract
|
const { totalShares, totalBets, pool } = contract
|
||||||
const { outcome, amount } = bet
|
const { outcome, amount } = bet
|
||||||
|
|
||||||
const p = getOutcomeProbability(totalShares, outcome)
|
const p = getDpmOutcomeProbability(totalShares, outcome)
|
||||||
|
|
||||||
const actual = _.sum(Object.values(pool)) - shareValue
|
const actual = _.sum(Object.values(pool)) - shareValue
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ export function calculateMoneyRatio(
|
||||||
_.sumBy(
|
_.sumBy(
|
||||||
Object.keys(totalBets),
|
Object.keys(totalBets),
|
||||||
(outcome) =>
|
(outcome) =>
|
||||||
getOutcomeProbability(totalShares, outcome) *
|
getDpmOutcomeProbability(totalShares, outcome) *
|
||||||
(totalBets as { [outcome: string]: number })[outcome]
|
(totalBets as { [outcome: string]: number })[outcome]
|
||||||
) - betAmount
|
) - betAmount
|
||||||
|
|
||||||
|
@ -112,42 +112,42 @@ export function calculateMoneyRatio(
|
||||||
return actual / expected
|
return actual / expected
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculateShareValue(
|
export function calculateDpmShareValue(
|
||||||
contract: FullContract<DPM, any>,
|
contract: FullContract<DPM, any>,
|
||||||
bet: Bet
|
bet: Bet
|
||||||
) {
|
) {
|
||||||
const { pool, totalShares } = contract
|
const { pool, totalShares } = contract
|
||||||
const { shares, outcome } = bet
|
const { shares, outcome } = bet
|
||||||
|
|
||||||
const shareValue = calculateRawShareValue(totalShares, shares, outcome)
|
const shareValue = calculateDpmRawShareValue(totalShares, shares, outcome)
|
||||||
const f = calculateMoneyRatio(contract, bet, shareValue)
|
const f = calculateDpmMoneyRatio(contract, bet, shareValue)
|
||||||
|
|
||||||
const myPool = pool[outcome]
|
const myPool = pool[outcome]
|
||||||
const adjShareValue = Math.min(Math.min(1, f) * shareValue, myPool)
|
const adjShareValue = Math.min(Math.min(1, f) * shareValue, myPool)
|
||||||
return adjShareValue
|
return adjShareValue
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculateSaleAmount(
|
export function calculateDpmSaleAmount(
|
||||||
contract: FullContract<DPM, any>,
|
contract: FullContract<DPM, any>,
|
||||||
bet: Bet
|
bet: Bet
|
||||||
) {
|
) {
|
||||||
const { amount } = bet
|
const { amount } = bet
|
||||||
const winnings = calculateShareValue(contract, bet)
|
const winnings = calculateDpmShareValue(contract, bet)
|
||||||
return deductFees(amount, winnings)
|
return deductDpmFees(amount, winnings)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculatePayout(
|
export function calculateDpmPayout(
|
||||||
contract: FullContract<DPM, any>,
|
contract: FullContract<DPM, any>,
|
||||||
bet: Bet,
|
bet: Bet,
|
||||||
outcome: string
|
outcome: string
|
||||||
) {
|
) {
|
||||||
if (outcome === 'CANCEL') return calculateCancelPayout(contract, bet)
|
if (outcome === 'CANCEL') return calculateDpmCancelPayout(contract, bet)
|
||||||
if (outcome === 'MKT') return calculateMktPayout(contract, bet)
|
if (outcome === 'MKT') return calculateMktDpmPayout(contract, bet)
|
||||||
|
|
||||||
return calculateStandardPayout(contract, bet, outcome)
|
return calculateStandardDpmPayout(contract, bet, outcome)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculateCancelPayout(
|
export function calculateDpmCancelPayout(
|
||||||
contract: FullContract<DPM, any>,
|
contract: FullContract<DPM, any>,
|
||||||
bet: Bet
|
bet: Bet
|
||||||
) {
|
) {
|
||||||
|
@ -158,7 +158,7 @@ export function calculateCancelPayout(
|
||||||
return (bet.amount / betTotal) * poolTotal
|
return (bet.amount / betTotal) * poolTotal
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculateStandardPayout(
|
export function calculateStandardDpmPayout(
|
||||||
contract: FullContract<DPM, any>,
|
contract: FullContract<DPM, any>,
|
||||||
bet: Bet,
|
bet: Bet,
|
||||||
outcome: string
|
outcome: string
|
||||||
|
@ -179,7 +179,7 @@ export function calculateStandardPayout(
|
||||||
return amount + (1 - FEES) * Math.max(0, winnings - amount)
|
return amount + (1 - FEES) * Math.max(0, winnings - amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculatePayoutAfterCorrectBet(
|
export function calculateDpmPayoutAfterCorrectBet(
|
||||||
contract: FullContract<DPM, any>,
|
contract: FullContract<DPM, any>,
|
||||||
bet: Bet
|
bet: Bet
|
||||||
) {
|
) {
|
||||||
|
@ -206,12 +206,12 @@ export function calculatePayoutAfterCorrectBet(
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return calculateStandardPayout(newContract, bet, outcome)
|
return calculateStandardDpmPayout(newContract, bet, outcome)
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateMktPayout(contract: FullContract<DPM, any>, bet: Bet) {
|
function calculateMktDpmPayout(contract: FullContract<DPM, any>, bet: Bet) {
|
||||||
if (contract.outcomeType === 'BINARY')
|
if (contract.outcomeType === 'BINARY')
|
||||||
return calculateBinaryMktPayout(contract, bet)
|
return calculateBinaryMktDpmPayout(contract, bet)
|
||||||
|
|
||||||
const { totalShares, pool } = contract
|
const { totalShares, pool } = contract
|
||||||
|
|
||||||
|
@ -230,13 +230,13 @@ function calculateMktPayout(contract: FullContract<DPM, any>, bet: Bet) {
|
||||||
|
|
||||||
const { outcome, amount, shares } = bet
|
const { outcome, amount, shares } = bet
|
||||||
|
|
||||||
const betP = getOutcomeProbability(totalShares, outcome)
|
const betP = getDpmOutcomeProbability(totalShares, outcome)
|
||||||
const winnings = ((betP * shares) / weightedShareTotal) * totalPool
|
const winnings = ((betP * shares) / weightedShareTotal) * totalPool
|
||||||
|
|
||||||
return deductFees(amount, winnings)
|
return deductDpmFees(amount, winnings)
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateBinaryMktPayout(
|
function calculateBinaryMktDpmPayout(
|
||||||
contract: FullContract<DPM, Binary>,
|
contract: FullContract<DPM, Binary>,
|
||||||
bet: Bet
|
bet: Bet
|
||||||
) {
|
) {
|
||||||
|
@ -244,7 +244,7 @@ function calculateBinaryMktPayout(
|
||||||
const p =
|
const p =
|
||||||
resolutionProbability !== undefined
|
resolutionProbability !== undefined
|
||||||
? resolutionProbability
|
? resolutionProbability
|
||||||
: getProbability(totalShares)
|
: getDpmProbability(totalShares)
|
||||||
|
|
||||||
const pool = contract.pool.YES + contract.pool.NO
|
const pool = contract.pool.YES + contract.pool.NO
|
||||||
|
|
||||||
|
@ -257,16 +257,16 @@ function calculateBinaryMktPayout(
|
||||||
const betP = outcome === 'YES' ? p : 1 - p
|
const betP = outcome === 'YES' ? p : 1 - p
|
||||||
const winnings = ((betP * shares) / weightedShareTotal) * pool
|
const winnings = ((betP * shares) / weightedShareTotal) * pool
|
||||||
|
|
||||||
return deductFees(amount, winnings)
|
return deductDpmFees(amount, winnings)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolvedPayout(contract: FullContract<DPM, any>, bet: Bet) {
|
export function resolvedDpmPayout(contract: FullContract<DPM, any>, bet: Bet) {
|
||||||
if (contract.resolution)
|
if (contract.resolution)
|
||||||
return calculatePayout(contract, bet, contract.resolution)
|
return calculateDpmPayout(contract, bet, contract.resolution)
|
||||||
throw new Error('Contract was not resolved')
|
throw new Error('Contract was not resolved')
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deductFees = (betAmount: number, winnings: number) => {
|
export const deductDpmFees = (betAmount: number, winnings: number) => {
|
||||||
return winnings > betAmount
|
return winnings > betAmount
|
||||||
? betAmount + (1 - FEES) * (winnings - betAmount)
|
? betAmount + (1 - FEES) * (winnings - betAmount)
|
||||||
: winnings
|
: winnings
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import * as _ from 'lodash'
|
import * as _ from 'lodash'
|
||||||
import { Bet, MAX_LOAN_PER_CONTRACT } from './bet'
|
import { Bet, MAX_LOAN_PER_CONTRACT } from './bet'
|
||||||
import {
|
import {
|
||||||
calculateShares,
|
calculateDpmShares,
|
||||||
getProbability,
|
getDpmProbability,
|
||||||
getOutcomeProbability,
|
getDpmOutcomeProbability,
|
||||||
} from './calculate-dpm'
|
} from './calculate-dpm'
|
||||||
import { calculateCpmmShares, getCpmmProbability } from './calculate-cpmm'
|
import { calculateCpmmShares, getCpmmProbability } from './calculate-cpmm'
|
||||||
import {
|
import {
|
||||||
|
@ -71,7 +71,7 @@ export const getNewBinaryDpmBetInfo = (
|
||||||
? { YES: yesPool + amount, NO: noPool }
|
? { YES: yesPool + amount, NO: noPool }
|
||||||
: { YES: yesPool, NO: noPool + amount }
|
: { YES: yesPool, NO: noPool + amount }
|
||||||
|
|
||||||
const shares = calculateShares(contract.totalShares, amount, outcome)
|
const shares = calculateDpmShares(contract.totalShares, amount, outcome)
|
||||||
|
|
||||||
const { YES: yesShares, NO: noShares } = contract.totalShares
|
const { YES: yesShares, NO: noShares } = contract.totalShares
|
||||||
|
|
||||||
|
@ -87,8 +87,8 @@ export const getNewBinaryDpmBetInfo = (
|
||||||
? { YES: yesBets + amount, NO: noBets }
|
? { YES: yesBets + amount, NO: noBets }
|
||||||
: { YES: yesBets, NO: noBets + amount }
|
: { YES: yesBets, NO: noBets + amount }
|
||||||
|
|
||||||
const probBefore = getProbability(contract.totalShares)
|
const probBefore = getDpmProbability(contract.totalShares)
|
||||||
const probAfter = getProbability(newTotalShares)
|
const probAfter = getDpmProbability(newTotalShares)
|
||||||
|
|
||||||
const newBet: Bet = {
|
const newBet: Bet = {
|
||||||
id: newBetId,
|
id: newBetId,
|
||||||
|
@ -121,7 +121,7 @@ export const getNewMultiBetInfo = (
|
||||||
const prevOutcomePool = pool[outcome] ?? 0
|
const prevOutcomePool = pool[outcome] ?? 0
|
||||||
const newPool = { ...pool, [outcome]: prevOutcomePool + amount }
|
const newPool = { ...pool, [outcome]: prevOutcomePool + amount }
|
||||||
|
|
||||||
const shares = calculateShares(contract.totalShares, amount, outcome)
|
const shares = calculateDpmShares(contract.totalShares, amount, outcome)
|
||||||
|
|
||||||
const prevShares = totalShares[outcome] ?? 0
|
const prevShares = totalShares[outcome] ?? 0
|
||||||
const newTotalShares = { ...totalShares, [outcome]: prevShares + shares }
|
const newTotalShares = { ...totalShares, [outcome]: prevShares + shares }
|
||||||
|
@ -129,8 +129,8 @@ export const getNewMultiBetInfo = (
|
||||||
const prevTotalBets = totalBets[outcome] ?? 0
|
const prevTotalBets = totalBets[outcome] ?? 0
|
||||||
const newTotalBets = { ...totalBets, [outcome]: prevTotalBets + amount }
|
const newTotalBets = { ...totalBets, [outcome]: prevTotalBets + amount }
|
||||||
|
|
||||||
const probBefore = getOutcomeProbability(totalShares, outcome)
|
const probBefore = getDpmOutcomeProbability(totalShares, outcome)
|
||||||
const probAfter = getOutcomeProbability(newTotalShares, outcome)
|
const probAfter = getDpmOutcomeProbability(newTotalShares, outcome)
|
||||||
|
|
||||||
const newBet: Bet = {
|
const newBet: Bet = {
|
||||||
id: newBetId,
|
id: newBetId,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import * as _ from 'lodash'
|
import * as _ from 'lodash'
|
||||||
|
|
||||||
import { Bet } from './bet'
|
import { Bet } from './bet'
|
||||||
import { deductFees, getProbability } from './calculate-dpm'
|
import { deductDpmFees, getDpmProbability } from './calculate-dpm'
|
||||||
import {
|
import {
|
||||||
Binary,
|
Binary,
|
||||||
Contract,
|
Contract,
|
||||||
|
@ -124,7 +124,7 @@ export const getMktPayouts = (
|
||||||
) => {
|
) => {
|
||||||
const p =
|
const p =
|
||||||
resolutionProbability === undefined
|
resolutionProbability === undefined
|
||||||
? getProbability(contract.totalShares)
|
? getDpmProbability(contract.totalShares)
|
||||||
: resolutionProbability
|
: resolutionProbability
|
||||||
|
|
||||||
const weightedShareTotal = _.sumBy(bets, (b) =>
|
const weightedShareTotal = _.sumBy(bets, (b) =>
|
||||||
|
@ -137,7 +137,7 @@ export const getMktPayouts = (
|
||||||
const betP = outcome === 'YES' ? p : 1 - p
|
const betP = outcome === 'YES' ? p : 1 - p
|
||||||
const winnings = ((betP * shares) / weightedShareTotal) * pool
|
const winnings = ((betP * shares) / weightedShareTotal) * pool
|
||||||
const profit = winnings - amount
|
const profit = winnings - amount
|
||||||
const payout = deductFees(amount, winnings)
|
const payout = deductDpmFees(amount, winnings)
|
||||||
return { userId, profit, payout }
|
return { userId, profit, payout }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -167,14 +167,14 @@ export const getMktFixedPayouts = (
|
||||||
) => {
|
) => {
|
||||||
const p =
|
const p =
|
||||||
resolutionProbability === undefined
|
resolutionProbability === undefined
|
||||||
? getProbability(contract.pool)
|
? getDpmProbability(contract.pool)
|
||||||
: resolutionProbability
|
: resolutionProbability
|
||||||
|
|
||||||
const payouts = bets.map(({ userId, outcome, amount, shares }) => {
|
const payouts = bets.map(({ userId, outcome, amount, shares }) => {
|
||||||
const betP = outcome === 'YES' ? p : 1 - p
|
const betP = outcome === 'YES' ? p : 1 - p
|
||||||
const winnings = betP * shares
|
const winnings = betP * shares
|
||||||
const profit = winnings - amount
|
const profit = winnings - amount
|
||||||
const payout = deductFees(amount, winnings)
|
const payout = deductDpmFees(amount, winnings)
|
||||||
return { userId, profit, payout }
|
return { userId, profit, payout }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { Bet } from './bet'
|
import { Bet } from './bet'
|
||||||
import {
|
import {
|
||||||
calculateShareValue,
|
getDpmProbability,
|
||||||
deductFees,
|
calculateDpmShareValue,
|
||||||
getProbability,
|
deductDpmFees,
|
||||||
} from './calculate-dpm'
|
} from './calculate-dpm'
|
||||||
import {
|
import {
|
||||||
calculateCpmmSale,
|
calculateCpmmSale,
|
||||||
|
@ -22,7 +22,7 @@ export const getSellBetInfo = (
|
||||||
const { pool, totalShares, totalBets } = contract
|
const { pool, totalShares, totalBets } = contract
|
||||||
const { id: betId, amount, shares, outcome, loanAmount } = bet
|
const { id: betId, amount, shares, outcome, loanAmount } = bet
|
||||||
|
|
||||||
const adjShareValue = calculateShareValue(contract, bet)
|
const adjShareValue = calculateDpmShareValue(contract, bet)
|
||||||
|
|
||||||
const newPool = { ...pool, [outcome]: pool[outcome] - adjShareValue }
|
const newPool = { ...pool, [outcome]: pool[outcome] - adjShareValue }
|
||||||
|
|
||||||
|
@ -33,12 +33,12 @@ export const getSellBetInfo = (
|
||||||
|
|
||||||
const newTotalBets = { ...totalBets, [outcome]: totalBets[outcome] - amount }
|
const newTotalBets = { ...totalBets, [outcome]: totalBets[outcome] - amount }
|
||||||
|
|
||||||
const probBefore = getProbability(totalShares)
|
const probBefore = getDpmProbability(totalShares)
|
||||||
const probAfter = getProbability(newTotalShares)
|
const probAfter = getDpmProbability(newTotalShares)
|
||||||
|
|
||||||
const profit = adjShareValue - amount
|
const profit = adjShareValue - amount
|
||||||
const creatorFee = CREATOR_FEE * Math.max(0, profit)
|
const creatorFee = CREATOR_FEE * Math.max(0, profit)
|
||||||
const saleAmount = deductFees(amount, adjShareValue)
|
const saleAmount = deductDpmFees(amount, adjShareValue)
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
'SELL M$',
|
'SELL M$',
|
||||||
|
@ -94,7 +94,7 @@ export const getCpmmSellBetInfo = (
|
||||||
|
|
||||||
const profit = saleValue - amount
|
const profit = saleValue - amount
|
||||||
const creatorFee = CREATOR_FEE * Math.max(0, profit)
|
const creatorFee = CREATOR_FEE * Math.max(0, profit)
|
||||||
const saleAmount = deductFees(amount, profit)
|
const saleAmount = deductDpmFees(amount, profit)
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
'SELL M$',
|
'SELL M$',
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import _ = require('lodash')
|
import _ = require('lodash')
|
||||||
import { Answer } from '../../common/answer'
|
import { Answer } from '../../common/answer'
|
||||||
import { Bet } from '../../common/bet'
|
import { Bet } from '../../common/bet'
|
||||||
import { getProbability } from '../../common/calculate-dpm'
|
import { getDpmProbability } from '../../common/calculate-dpm'
|
||||||
import { Comment } from '../../common/comment'
|
import { Comment } from '../../common/comment'
|
||||||
import { Contract } from '../../common/contract'
|
import { Contract } from '../../common/contract'
|
||||||
import { CREATOR_FEE } from '../../common/fees'
|
import { CREATOR_FEE } from '../../common/fees'
|
||||||
|
@ -59,7 +59,7 @@ export const sendMarketResolutionEmail = async (
|
||||||
const user = await getUser(userId)
|
const user = await getUser(userId)
|
||||||
if (!user) return
|
if (!user) return
|
||||||
|
|
||||||
const prob = resolutionProbability ?? getProbability(contract.totalShares)
|
const prob = resolutionProbability ?? getDpmProbability(contract.totalShares)
|
||||||
|
|
||||||
const outcome = toDisplayResolution(resolution, prob, resolutions)
|
const outcome = toDisplayResolution(resolution, prob, resolutions)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import * as _ from 'lodash'
|
||||||
|
|
||||||
import { getValues } from './utils'
|
import { getValues } from './utils'
|
||||||
import { Contract } from '../../common/contract'
|
import { Contract } from '../../common/contract'
|
||||||
import { getProbability } from '../../common/calculate-dpm'
|
import { getDpmProbability } from '../../common/calculate-dpm'
|
||||||
|
|
||||||
const cache = { lastUpdated: 0, data: '' }
|
const cache = { lastUpdated: 0, data: '' }
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ const getContractInfo = ({
|
||||||
description,
|
description,
|
||||||
url: `https://manifold.markets/${creatorUsername}/${slug}`,
|
url: `https://manifold.markets/${creatorUsername}/${slug}`,
|
||||||
pool: pool.YES + pool.NO,
|
pool: pool.YES + pool.NO,
|
||||||
probability: getProbability(totalShares),
|
probability: getDpmProbability(totalShares),
|
||||||
volume7Days,
|
volume7Days,
|
||||||
volume24Hours,
|
volume24Hours,
|
||||||
isResolved,
|
isResolved,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { initAdmin } from './script-init'
|
||||||
initAdmin('stephen')
|
initAdmin('stephen')
|
||||||
|
|
||||||
import { Bet } from '../../../common/bet'
|
import { Bet } from '../../../common/bet'
|
||||||
import { getProbability } from '../../../common/calculate-dpm'
|
import { getDpmProbability } from '../../../common/calculate-dpm'
|
||||||
import { Contract } from '../../../common/contract'
|
import { Contract } from '../../../common/contract'
|
||||||
|
|
||||||
type DocRef = admin.firestore.DocumentReference
|
type DocRef = admin.firestore.DocumentReference
|
||||||
|
@ -19,7 +19,7 @@ async function migrateContract(contractRef: DocRef, contract: Contract) {
|
||||||
|
|
||||||
const lastBet = _.sortBy(bets, (bet) => -bet.createdTime)[0]
|
const lastBet = _.sortBy(bets, (bet) => -bet.createdTime)[0]
|
||||||
if (lastBet) {
|
if (lastBet) {
|
||||||
const probAfter = getProbability(contract.totalShares)
|
const probAfter = getDpmProbability(contract.totalShares)
|
||||||
|
|
||||||
await firestore
|
await firestore
|
||||||
.doc(`contracts/${contract.id}/bets/${lastBet.id}`)
|
.doc(`contracts/${contract.id}/bets/${lastBet.id}`)
|
||||||
|
|
|
@ -6,7 +6,10 @@ initAdmin('stephenDev')
|
||||||
|
|
||||||
import { Contract } from '../../../common/contract'
|
import { Contract } from '../../../common/contract'
|
||||||
import { Bet } from '../../../common/bet'
|
import { Bet } from '../../../common/bet'
|
||||||
import { calculateShares, getProbability } from '../../../common/calculate-dpm'
|
import {
|
||||||
|
calculateDpmShares,
|
||||||
|
getDpmProbability,
|
||||||
|
} from '../../../common/calculate-dpm'
|
||||||
import { getSellBetInfo } from '../../../common/sell-bet'
|
import { getSellBetInfo } from '../../../common/sell-bet'
|
||||||
import { User } from '../../../common/user'
|
import { User } from '../../../common/user'
|
||||||
|
|
||||||
|
@ -126,7 +129,7 @@ async function recalculateContract(
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const shares = calculateShares(totalShares, bet.amount, bet.outcome)
|
const shares = calculateDpmShares(totalShares, bet.amount, bet.outcome)
|
||||||
const probBefore = p
|
const probBefore = p
|
||||||
const ind = bet.outcome === 'YES' ? 1 : 0
|
const ind = bet.outcome === 'YES' ? 1 : 0
|
||||||
|
|
||||||
|
@ -145,7 +148,7 @@ async function recalculateContract(
|
||||||
NO: totalBets.NO + (1 - ind) * bet.amount,
|
NO: totalBets.NO + (1 - ind) * bet.amount,
|
||||||
}
|
}
|
||||||
|
|
||||||
p = getProbability(totalShares)
|
p = getDpmProbability(totalShares)
|
||||||
|
|
||||||
const probAfter = p
|
const probAfter = p
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { getValues } from './utils'
|
||||||
import { Contract } from '../../common/contract'
|
import { Contract } from '../../common/contract'
|
||||||
import { Bet } from '../../common/bet'
|
import { Bet } from '../../common/bet'
|
||||||
import { User } from '../../common/user'
|
import { User } from '../../common/user'
|
||||||
import { calculatePayout } from '../../common/calculate-dpm'
|
import { calculateDpmPayout } from '../../common/calculate-dpm'
|
||||||
|
|
||||||
const firestore = admin.firestore()
|
const firestore = admin.firestore()
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ const computeInvestmentValue = async (
|
||||||
if (!contract || contract.isResolved) return 0
|
if (!contract || contract.isResolved) return 0
|
||||||
if (bet.sale || bet.isSold) return 0
|
if (bet.sale || bet.isSold) return 0
|
||||||
|
|
||||||
const payout = calculatePayout(contract, bet, 'MKT')
|
const payout = calculateDpmPayout(contract, bet, 'MKT')
|
||||||
return payout - (bet.loanAmount ?? 0)
|
return payout - (bet.loanAmount ?? 0)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,10 @@ import {
|
||||||
import { InfoTooltip } from '../info-tooltip'
|
import { InfoTooltip } from '../info-tooltip'
|
||||||
import { useUser } from '../../hooks/use-user'
|
import { useUser } from '../../hooks/use-user'
|
||||||
import {
|
import {
|
||||||
getProbabilityAfterBet,
|
getDpmProbabilityAfterBet,
|
||||||
getOutcomeProbability,
|
getDpmOutcomeProbability,
|
||||||
calculateShares,
|
calculateDpmShares,
|
||||||
calculatePayoutAfterCorrectBet,
|
calculateDpmPayoutAfterCorrectBet,
|
||||||
} from '../../../common/calculate-dpm'
|
} from '../../../common/calculate-dpm'
|
||||||
import { firebaseLogin } from '../../lib/firebase/users'
|
import { firebaseLogin } from '../../lib/firebase/users'
|
||||||
import { Bet } from '../../../common/bet'
|
import { Bet } from '../../../common/bet'
|
||||||
|
@ -76,18 +76,22 @@ export function AnswerBetPanel(props: {
|
||||||
|
|
||||||
const betDisabled = isSubmitting || !betAmount || error
|
const betDisabled = isSubmitting || !betAmount || error
|
||||||
|
|
||||||
const initialProb = getOutcomeProbability(contract.totalShares, answer.id)
|
const initialProb = getDpmOutcomeProbability(contract.totalShares, answer.id)
|
||||||
|
|
||||||
const resultProb = getProbabilityAfterBet(
|
const resultProb = getDpmProbabilityAfterBet(
|
||||||
contract.totalShares,
|
contract.totalShares,
|
||||||
answerId,
|
answerId,
|
||||||
betAmount ?? 0
|
betAmount ?? 0
|
||||||
)
|
)
|
||||||
|
|
||||||
const shares = calculateShares(contract.totalShares, betAmount ?? 0, answerId)
|
const shares = calculateDpmShares(
|
||||||
|
contract.totalShares,
|
||||||
|
betAmount ?? 0,
|
||||||
|
answerId
|
||||||
|
)
|
||||||
|
|
||||||
const currentPayout = betAmount
|
const currentPayout = betAmount
|
||||||
? calculatePayoutAfterCorrectBet(contract, {
|
? calculateDpmPayoutAfterCorrectBet(contract, {
|
||||||
outcome: answerId,
|
outcome: answerId,
|
||||||
amount: betAmount,
|
amount: betAmount,
|
||||||
shares,
|
shares,
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { Avatar } from '../avatar'
|
||||||
import { SiteLink } from '../site-link'
|
import { SiteLink } from '../site-link'
|
||||||
import { BuyButton } from '../yes-no-selector'
|
import { BuyButton } from '../yes-no-selector'
|
||||||
import { formatPercent } from '../../../common/util/format'
|
import { formatPercent } from '../../../common/util/format'
|
||||||
import { getOutcomeProbability } from '../../../common/calculate-dpm'
|
import { getDpmOutcomeProbability } from '../../../common/calculate-dpm'
|
||||||
import { tradingAllowed } from '../../lib/firebase/contracts'
|
import { tradingAllowed } from '../../lib/firebase/contracts'
|
||||||
import { AnswerBetPanel } from './answer-bet-panel'
|
import { AnswerBetPanel } from './answer-bet-panel'
|
||||||
import { ContractFeed } from '../contract-feed'
|
import { ContractFeed } from '../contract-feed'
|
||||||
|
@ -38,7 +38,7 @@ export function AnswerItem(props: {
|
||||||
const { username, avatarUrl, name, number, text } = answer
|
const { username, avatarUrl, name, number, text } = answer
|
||||||
const isChosen = chosenProb !== undefined
|
const isChosen = chosenProb !== undefined
|
||||||
|
|
||||||
const prob = getOutcomeProbability(totalShares, answer.id)
|
const prob = getDpmOutcomeProbability(totalShares, answer.id)
|
||||||
const roundedProb = Math.round(prob * 100)
|
const roundedProb = Math.round(prob * 100)
|
||||||
const probPercent = formatPercent(prob)
|
const probPercent = formatPercent(prob)
|
||||||
const wasResolvedTo =
|
const wasResolvedTo =
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { DPM, FreeResponse, FullContract } from '../../../common/contract'
|
||||||
import { Col } from '../layout/col'
|
import { Col } from '../layout/col'
|
||||||
import { formatPercent } from '../../../common/util/format'
|
import { formatPercent } from '../../../common/util/format'
|
||||||
import { useUser } from '../../hooks/use-user'
|
import { useUser } from '../../hooks/use-user'
|
||||||
import { getOutcomeProbability } from '../../../common/calculate-dpm'
|
import { getDpmOutcomeProbability } from '../../../common/calculate-dpm'
|
||||||
import { useAnswers } from '../../hooks/use-answers'
|
import { useAnswers } from '../../hooks/use-answers'
|
||||||
import { tradingAllowed } from '../../lib/firebase/contracts'
|
import { tradingAllowed } from '../../lib/firebase/contracts'
|
||||||
import { AnswerItem } from './answer-item'
|
import { AnswerItem } from './answer-item'
|
||||||
|
@ -34,7 +34,7 @@ export function AnswersPanel(props: {
|
||||||
),
|
),
|
||||||
..._.sortBy(
|
..._.sortBy(
|
||||||
otherAnswers,
|
otherAnswers,
|
||||||
(answer) => -1 * getOutcomeProbability(contract.totalShares, answer.id)
|
(answer) => -1 * getDpmOutcomeProbability(contract.totalShares, answer.id)
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ export function AnswersPanel(props: {
|
||||||
) : (
|
) : (
|
||||||
<div className="text-gray-500 self-end p-4">
|
<div className="text-gray-500 self-end p-4">
|
||||||
None of the above:{' '}
|
None of the above:{' '}
|
||||||
{formatPercent(getOutcomeProbability(contract.totalShares, '0'))}
|
{formatPercent(getDpmOutcomeProbability(contract.totalShares, '0'))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,9 @@ import {
|
||||||
import { InfoTooltip } from '../info-tooltip'
|
import { InfoTooltip } from '../info-tooltip'
|
||||||
import { useUser } from '../../hooks/use-user'
|
import { useUser } from '../../hooks/use-user'
|
||||||
import {
|
import {
|
||||||
getProbabilityAfterBet,
|
getDpmProbabilityAfterBet,
|
||||||
calculateShares,
|
calculateDpmShares,
|
||||||
calculatePayoutAfterCorrectBet,
|
calculateDpmPayoutAfterCorrectBet,
|
||||||
} from '../../../common/calculate-dpm'
|
} from '../../../common/calculate-dpm'
|
||||||
import { firebaseLogin } from '../../lib/firebase/users'
|
import { firebaseLogin } from '../../lib/firebase/users'
|
||||||
import { Bet } from '../../../common/bet'
|
import { Bet } from '../../../common/bet'
|
||||||
|
@ -59,16 +59,16 @@ export function CreateAnswerPanel(props: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const resultProb = getProbabilityAfterBet(
|
const resultProb = getDpmProbabilityAfterBet(
|
||||||
contract.totalShares,
|
contract.totalShares,
|
||||||
'new',
|
'new',
|
||||||
betAmount ?? 0
|
betAmount ?? 0
|
||||||
)
|
)
|
||||||
|
|
||||||
const shares = calculateShares(contract.totalShares, betAmount ?? 0, 'new')
|
const shares = calculateDpmShares(contract.totalShares, betAmount ?? 0, 'new')
|
||||||
|
|
||||||
const currentPayout = betAmount
|
const currentPayout = betAmount
|
||||||
? calculatePayoutAfterCorrectBet(contract, {
|
? calculateDpmPayoutAfterCorrectBet(contract, {
|
||||||
outcome: 'new',
|
outcome: 'new',
|
||||||
amount: betAmount,
|
amount: betAmount,
|
||||||
shares,
|
shares,
|
||||||
|
|
|
@ -14,10 +14,10 @@ import {
|
||||||
} from '../../common/util/format'
|
} from '../../common/util/format'
|
||||||
import { Title } from './title'
|
import { Title } from './title'
|
||||||
import {
|
import {
|
||||||
getProbability,
|
getDpmProbability,
|
||||||
calculateShares,
|
calculateDpmShares,
|
||||||
getProbabilityAfterBet,
|
getDpmProbabilityAfterBet,
|
||||||
calculatePayoutAfterCorrectBet,
|
calculateDpmPayoutAfterCorrectBet,
|
||||||
} from '../../common/calculate-dpm'
|
} from '../../common/calculate-dpm'
|
||||||
import { firebaseLogin } from '../lib/firebase/users'
|
import { firebaseLogin } from '../lib/firebase/users'
|
||||||
import { Bet } from '../../common/bet'
|
import { Bet } from '../../common/bet'
|
||||||
|
@ -107,23 +107,23 @@ export function BetPanel(props: {
|
||||||
|
|
||||||
const betDisabled = isSubmitting || !betAmount || error
|
const betDisabled = isSubmitting || !betAmount || error
|
||||||
|
|
||||||
const initialProb = getProbability(contract.totalShares)
|
const initialProb = getDpmProbability(contract.totalShares)
|
||||||
|
|
||||||
const outcomeProb = getProbabilityAfterBet(
|
const outcomeProb = getDpmProbabilityAfterBet(
|
||||||
contract.totalShares,
|
contract.totalShares,
|
||||||
betChoice || 'YES',
|
betChoice || 'YES',
|
||||||
betAmount ?? 0
|
betAmount ?? 0
|
||||||
)
|
)
|
||||||
const resultProb = betChoice === 'NO' ? 1 - outcomeProb : outcomeProb
|
const resultProb = betChoice === 'NO' ? 1 - outcomeProb : outcomeProb
|
||||||
|
|
||||||
const shares = calculateShares(
|
const shares = calculateDpmShares(
|
||||||
contract.totalShares,
|
contract.totalShares,
|
||||||
betAmount ?? 0,
|
betAmount ?? 0,
|
||||||
betChoice || 'YES'
|
betChoice || 'YES'
|
||||||
)
|
)
|
||||||
|
|
||||||
const currentPayout = betAmount
|
const currentPayout = betAmount
|
||||||
? calculatePayoutAfterCorrectBet(contract, {
|
? calculateDpmPayoutAfterCorrectBet(contract, {
|
||||||
outcome: betChoice,
|
outcome: betChoice,
|
||||||
amount: betAmount,
|
amount: betAmount,
|
||||||
shares,
|
shares,
|
||||||
|
|
|
@ -23,12 +23,12 @@ import {
|
||||||
import { Row } from './layout/row'
|
import { Row } from './layout/row'
|
||||||
import { UserLink } from './user-page'
|
import { UserLink } from './user-page'
|
||||||
import {
|
import {
|
||||||
calculatePayout,
|
calculateDpmPayout,
|
||||||
calculateSaleAmount,
|
calculateDpmSaleAmount,
|
||||||
getOutcomeProbability,
|
getDpmOutcomeProbability,
|
||||||
getProbability,
|
getDpmProbability,
|
||||||
getProbabilityAfterSale,
|
getDpmProbabilityAfterSale,
|
||||||
resolvedPayout,
|
resolvedDpmPayout,
|
||||||
} from '../../common/calculate-dpm'
|
} from '../../common/calculate-dpm'
|
||||||
import { sellBet } from '../lib/firebase/api-call'
|
import { sellBet } from '../lib/firebase/api-call'
|
||||||
import { ConfirmationButton } from './confirmation-button'
|
import { ConfirmationButton } from './confirmation-button'
|
||||||
|
@ -82,7 +82,7 @@ export function BetsList(props: { user: User }) {
|
||||||
if (bet.isSold || bet.sale) return 0
|
if (bet.isSold || bet.sale) return 0
|
||||||
|
|
||||||
const contract = contracts.find((c) => c.id === contractId)
|
const contract = contracts.find((c) => c.id === contractId)
|
||||||
const payout = contract ? calculatePayout(contract, bet, 'MKT') : 0
|
const payout = contract ? calculateDpmPayout(contract, bet, 'MKT') : 0
|
||||||
return payout - (bet.loanAmount ?? 0)
|
return payout - (bet.loanAmount ?? 0)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -288,21 +288,21 @@ export function MyBetsSummary(props: {
|
||||||
const betsTotal = _.sumBy(excludeSales, (bet) => bet.amount)
|
const betsTotal = _.sumBy(excludeSales, (bet) => bet.amount)
|
||||||
|
|
||||||
const betsPayout = resolution
|
const betsPayout = resolution
|
||||||
? _.sumBy(excludeSales, (bet) => resolvedPayout(contract, bet))
|
? _.sumBy(excludeSales, (bet) => resolvedDpmPayout(contract, bet))
|
||||||
: 0
|
: 0
|
||||||
|
|
||||||
const yesWinnings = _.sumBy(excludeSales, (bet) =>
|
const yesWinnings = _.sumBy(excludeSales, (bet) =>
|
||||||
calculatePayout(contract, bet, 'YES')
|
calculateDpmPayout(contract, bet, 'YES')
|
||||||
)
|
)
|
||||||
const noWinnings = _.sumBy(excludeSales, (bet) =>
|
const noWinnings = _.sumBy(excludeSales, (bet) =>
|
||||||
calculatePayout(contract, bet, 'NO')
|
calculateDpmPayout(contract, bet, 'NO')
|
||||||
)
|
)
|
||||||
|
|
||||||
// const p = getProbability(contract.totalShares)
|
// const p = getProbability(contract.totalShares)
|
||||||
// const expectation = p * yesWinnings + (1 - p) * noWinnings
|
// const expectation = p * yesWinnings + (1 - p) * noWinnings
|
||||||
|
|
||||||
const marketWinnings = _.sumBy(excludeSales, (bet) =>
|
const marketWinnings = _.sumBy(excludeSales, (bet) =>
|
||||||
calculatePayout(contract, bet, 'MKT')
|
calculateDpmPayout(contract, bet, 'MKT')
|
||||||
)
|
)
|
||||||
|
|
||||||
const currentValue = resolution ? betsPayout : marketWinnings
|
const currentValue = resolution ? betsPayout : marketWinnings
|
||||||
|
@ -385,7 +385,7 @@ export function MyBetsSummary(props: {
|
||||||
<>
|
<>
|
||||||
Payout at{' '}
|
Payout at{' '}
|
||||||
<span className="text-blue-400">
|
<span className="text-blue-400">
|
||||||
{formatPercent(getProbability(contract.totalShares))}
|
{formatPercent(getDpmProbability(contract.totalShares))}
|
||||||
</span>
|
</span>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
|
@ -473,15 +473,15 @@ function BetRow(props: { bet: Bet; contract: Contract; saleBet?: Bet }) {
|
||||||
) : (
|
) : (
|
||||||
formatMoney(
|
formatMoney(
|
||||||
isResolved
|
isResolved
|
||||||
? resolvedPayout(contract, bet)
|
? resolvedDpmPayout(contract, bet)
|
||||||
: calculateSaleAmount(contract, bet)
|
: calculateDpmSaleAmount(contract, bet)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
const payoutIfChosenDisplay =
|
const payoutIfChosenDisplay =
|
||||||
bet.outcome === '0' && bet.isAnte
|
bet.outcome === '0' && bet.isAnte
|
||||||
? 'N/A'
|
? 'N/A'
|
||||||
: formatMoney(calculatePayout(contract, bet, bet.outcome))
|
: formatMoney(calculateDpmPayout(contract, bet, bet.outcome))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -519,18 +519,18 @@ function SellButton(props: { contract: Contract; bet: Bet }) {
|
||||||
|
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||||
|
|
||||||
const initialProb = getOutcomeProbability(
|
const initialProb = getDpmOutcomeProbability(
|
||||||
contract.totalShares,
|
contract.totalShares,
|
||||||
outcome === 'NO' ? 'YES' : outcome
|
outcome === 'NO' ? 'YES' : outcome
|
||||||
)
|
)
|
||||||
|
|
||||||
const outcomeProb = getProbabilityAfterSale(
|
const outcomeProb = getDpmProbabilityAfterSale(
|
||||||
contract.totalShares,
|
contract.totalShares,
|
||||||
outcome,
|
outcome,
|
||||||
shares
|
shares
|
||||||
)
|
)
|
||||||
|
|
||||||
const saleAmount = calculateSaleAmount(contract, bet)
|
const saleAmount = calculateDpmSaleAmount(contract, bet)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConfirmationButton
|
<ConfirmationButton
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { DatumValue } from '@nivo/core'
|
||||||
import { ResponsiveLine } from '@nivo/line'
|
import { ResponsiveLine } from '@nivo/line'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { Bet } from '../../common/bet'
|
import { Bet } from '../../common/bet'
|
||||||
import { getProbability } from '../../common/calculate-dpm'
|
import { getDpmProbability } from '../../common/calculate-dpm'
|
||||||
import { useBetsWithoutAntes } from '../hooks/use-bets'
|
import { useBetsWithoutAntes } from '../hooks/use-bets'
|
||||||
import { useWindowSize } from '../hooks/use-window-size'
|
import { useWindowSize } from '../hooks/use-window-size'
|
||||||
import { Contract } from '../lib/firebase/contracts'
|
import { Contract } from '../lib/firebase/contracts'
|
||||||
|
@ -13,7 +13,7 @@ export function ContractProbGraph(props: { contract: Contract; bets: Bet[] }) {
|
||||||
|
|
||||||
const bets = useBetsWithoutAntes(contract, props.bets)
|
const bets = useBetsWithoutAntes(contract, props.bets)
|
||||||
|
|
||||||
const startProb = getProbability(
|
const startProb = getDpmProbability(
|
||||||
phantomShares as { [outcome: string]: number }
|
phantomShares as { [outcome: string]: number }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { Spacer } from './layout/spacer'
|
||||||
import { ResolveConfirmationButton } from './confirmation-button'
|
import { ResolveConfirmationButton } from './confirmation-button'
|
||||||
import { resolveMarket } from '../lib/firebase/api-call'
|
import { resolveMarket } from '../lib/firebase/api-call'
|
||||||
import { ProbabilitySelector } from './probability-selector'
|
import { ProbabilitySelector } from './probability-selector'
|
||||||
import { getProbability } from '../../common/calculate-dpm'
|
import { getDpmProbability } from '../../common/calculate-dpm'
|
||||||
import { CREATOR_FEE } from '../../common/fees'
|
import { CREATOR_FEE } from '../../common/fees'
|
||||||
|
|
||||||
export function ResolutionPanel(props: {
|
export function ResolutionPanel(props: {
|
||||||
|
@ -29,7 +29,9 @@ export function ResolutionPanel(props: {
|
||||||
'YES' | 'NO' | 'MKT' | 'CANCEL' | undefined
|
'YES' | 'NO' | 'MKT' | 'CANCEL' | undefined
|
||||||
>()
|
>()
|
||||||
|
|
||||||
const [prob, setProb] = useState(getProbability(contract.totalShares) * 100)
|
const [prob, setProb] = useState(
|
||||||
|
getDpmProbability(contract.totalShares) * 100
|
||||||
|
)
|
||||||
|
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||||
const [error, setError] = useState<string | undefined>(undefined)
|
const [error, setError] = useState<string | undefined>(undefined)
|
||||||
|
|
|
@ -18,7 +18,7 @@ import _ from 'lodash'
|
||||||
import { app } from './init'
|
import { app } from './init'
|
||||||
import { getValues, listenForValue, listenForValues } from './utils'
|
import { getValues, listenForValue, listenForValues } from './utils'
|
||||||
import { Binary, Contract, FullContract } from '../../../common/contract'
|
import { Binary, Contract, FullContract } from '../../../common/contract'
|
||||||
import { getProbability } from '../../../common/calculate-dpm'
|
import { getDpmProbability } from '../../../common/calculate-dpm'
|
||||||
import { createRNG, shuffle } from '../../../common/util/random'
|
import { createRNG, shuffle } from '../../../common/util/random'
|
||||||
import { getCpmmProbability } from '../../../common/calculate-cpmm'
|
import { getCpmmProbability } from '../../../common/calculate-cpmm'
|
||||||
export type { Contract }
|
export type { Contract }
|
||||||
|
@ -47,7 +47,7 @@ export function getBinaryProbPercent(contract: FullContract<any, Binary>) {
|
||||||
const prob =
|
const prob =
|
||||||
resolutionProbability ?? mechanism === 'cpmm-1'
|
resolutionProbability ?? mechanism === 'cpmm-1'
|
||||||
? getCpmmProbability(pool)
|
? getCpmmProbability(pool)
|
||||||
: getProbability(totalShares)
|
: getDpmProbability(totalShares)
|
||||||
|
|
||||||
const probPercent = Math.round(prob * 100) + '%'
|
const probPercent = Math.round(prob * 100) + '%'
|
||||||
return probPercent
|
return probPercent
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Bet } from '../../../../common/bet'
|
import { Bet } from '../../../../common/bet'
|
||||||
import { getProbability } from '../../../../common/calculate-dpm'
|
import { getDpmProbability } from '../../../../common/calculate-dpm'
|
||||||
import { Comment } from '../../../../common/comment'
|
import { Comment } from '../../../../common/comment'
|
||||||
import { Contract } from '../../../../common/contract'
|
import { Contract } from '../../../../common/contract'
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ export function toLiteMarket({
|
||||||
tags,
|
tags,
|
||||||
url: `https://manifold.markets/${creatorUsername}/${slug}`,
|
url: `https://manifold.markets/${creatorUsername}/${slug}`,
|
||||||
pool: pool.YES + pool.NO,
|
pool: pool.YES + pool.NO,
|
||||||
probability: getProbability(totalShares),
|
probability: getDpmProbability(totalShares),
|
||||||
volume7Days,
|
volume7Days,
|
||||||
volume24Hours,
|
volume24Hours,
|
||||||
isResolved,
|
isResolved,
|
||||||
|
|
|
@ -3,7 +3,7 @@ import dayjs from 'dayjs'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import Textarea from 'react-expanding-textarea'
|
import Textarea from 'react-expanding-textarea'
|
||||||
import { getProbability } from '../../common/calculate-dpm'
|
import { getDpmProbability } from '../../common/calculate-dpm'
|
||||||
import { parseWordsAsTags } from '../../common/util/parse'
|
import { parseWordsAsTags } from '../../common/util/parse'
|
||||||
import { AmountInput } from '../components/amount-input'
|
import { AmountInput } from '../components/amount-input'
|
||||||
import { InfoTooltip } from '../components/info-tooltip'
|
import { InfoTooltip } from '../components/info-tooltip'
|
||||||
|
@ -26,7 +26,7 @@ type Prediction = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function toPrediction(contract: Contract): Prediction {
|
function toPrediction(contract: Contract): Prediction {
|
||||||
const startProb = getProbability(contract.totalShares)
|
const startProb = getDpmProbability(contract.totalShares)
|
||||||
return {
|
return {
|
||||||
question: contract.question,
|
question: contract.question,
|
||||||
description: contract.description,
|
description: contract.description,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user