new bet: use calculateCpmmPurchase
This commit is contained in:
parent
f06ec7a170
commit
f40a65cc88
|
@ -1,11 +1,12 @@
|
||||||
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 {
|
||||||
calculateDpmShares,
|
calculateDpmShares,
|
||||||
getDpmProbability,
|
getDpmProbability,
|
||||||
getDpmOutcomeProbability,
|
getDpmOutcomeProbability,
|
||||||
} from './calculate-dpm'
|
} from './calculate-dpm'
|
||||||
import { calculateCpmmShares, getCpmmProbability } from './calculate-cpmm'
|
import { calculateCpmmPurchase, getCpmmProbability } from './calculate-cpmm'
|
||||||
import {
|
import {
|
||||||
Binary,
|
Binary,
|
||||||
CPMM,
|
CPMM,
|
||||||
|
@ -24,20 +25,11 @@ export const getNewBinaryCpmmBetInfo = (
|
||||||
loanAmount: number,
|
loanAmount: number,
|
||||||
newBetId: string
|
newBetId: string
|
||||||
) => {
|
) => {
|
||||||
const { pool, k } = contract
|
const { shares, newPool } = calculateCpmmPurchase(contract, amount, outcome)
|
||||||
|
|
||||||
const shares = calculateCpmmShares(pool, k, amount, outcome)
|
|
||||||
const { YES: y, NO: n } = pool
|
|
||||||
|
|
||||||
const [newY, newN] =
|
|
||||||
outcome === 'YES'
|
|
||||||
? [y - shares + amount, amount]
|
|
||||||
: [amount, n - shares + amount]
|
|
||||||
|
|
||||||
const newBalance = user.balance - (amount - loanAmount)
|
const newBalance = user.balance - (amount - loanAmount)
|
||||||
|
|
||||||
const probBefore = getCpmmProbability(pool)
|
const probBefore = getCpmmProbability(contract.pool)
|
||||||
const newPool = { YES: newY, NO: newN }
|
|
||||||
const probAfter = getCpmmProbability(newPool)
|
const probAfter = getCpmmProbability(newPool)
|
||||||
|
|
||||||
const newBet: Bet = {
|
const newBet: Bet = {
|
||||||
|
|
|
@ -11,7 +11,6 @@ import {
|
||||||
} from '../../common/new-bet'
|
} from '../../common/new-bet'
|
||||||
import { removeUndefinedProps } from '../../common/util/object'
|
import { removeUndefinedProps } from '../../common/util/object'
|
||||||
import { Bet } from '../../common/bet'
|
import { Bet } from '../../common/bet'
|
||||||
import { getValues } from './utils'
|
|
||||||
|
|
||||||
export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall(
|
export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
async (
|
async (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user