Skip to content

Commit

Permalink
Revert "Revert limit again"
Browse files Browse the repository at this point in the history
This reverts commit c466a6b.
  • Loading branch information
IanPhilips committed Jul 9, 2024
1 parent c466a6b commit 5dbc839
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
9 changes: 8 additions & 1 deletion common/src/calculate-cpmm-arbitrage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { computeFills } from './new-bet'
import { floatingEqual } from './util/math'
import { Fees, getFeesSplit, getTakerFee, noFees, sumAllFees } from './fees'
import { addObjects } from './util/object'
import { MAX_CPMM_PROB, MIN_CPMM_PROB } from 'common/contract'

const DEBUG = false
export type ArbitrageBetArray = ReturnType<typeof combineBetsOnSameAnswers>
Expand All @@ -18,11 +19,17 @@ export function calculateCpmmMultiArbitrageBet(
answerToBuy: Answer,
outcome: 'YES' | 'NO',
betAmount: number,
limitProb: number | undefined,
initialLimitProb: number | undefined,
unfilledBets: LimitBet[],
balanceByUserId: { [userId: string]: number },
collectedFees: Fees
) {
const limitProb =
initialLimitProb !== undefined
? initialLimitProb
: outcome === 'YES'
? MAX_CPMM_PROB
: MIN_CPMM_PROB
const result =
outcome === 'YES'
? calculateCpmmMultiArbitrageBetYes(
Expand Down
36 changes: 22 additions & 14 deletions common/src/new-bet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ const getNewMultiCpmmBetsInfoSumsToOne = (
answers: Answer[],
answersToBuy: Answer[],
outcome: 'YES' | 'NO',
betAmount: number,
initialBetAmount: number,
limitProb: number | undefined,
unfilledBets: LimitBet[],
balanceByUserId: { [userId: string]: number },
Expand All @@ -512,21 +512,24 @@ const getNewMultiCpmmBetsInfoSumsToOne = (
answers,
answersToBuy[0],
outcome,
betAmount,
initialBetAmount,
limitProb,
unfilledBets,
balanceByUserId,
contract.collectedFees
)
if (newBetResult.takers.length === 0 && !limitProb) {
throw new APIError(400, 'Betting allowed only between 1-99%.')
}
newBetResults.push(...([newBetResult] as ArbitrageBetArray))
if (otherBetResults.length > 0)
otherBetsResults.push(...(otherBetResults as ArbitrageBetArray))
} else {
// TODO: only accepts YES bets atm
// NOTE: only accepts YES bets atm
const multiRes = calculateCpmmMultiArbitrageYesBets(
answers,
answersToBuy,
betAmount,
initialBetAmount,
limitProb,
unfilledBets,
balanceByUserId,
Expand All @@ -539,28 +542,33 @@ const getNewMultiCpmmBetsInfoSumsToOne = (
return newBetResults.map((newBetResult, i) => {
const { takers, cpmmState, answer: updatedAnswer, totalFees } = newBetResult
const probAfter = getCpmmProbability(cpmmState.pool, cpmmState.p)
const amount = sumBy(takers, 'amount')
const shares = sumBy(takers, 'shares')
const takerAmount = sumBy(takers, 'amount')
const takerShares = sumBy(takers, 'shares')
const answer = answers.find((a) => a.id === updatedAnswer.id) as Answer
const multiBuyAmount = sumBy(
const multiBuyTakerAmount = sumBy(
newBetResults.flatMap((r) => r.takers),
'amount'
)
const betAmount = limitProb
? initialBetAmount
: isMultiBuy
? multiBuyTakerAmount
: takerAmount

const newBet: CandidateBet = removeUndefinedProps({
orderAmount: betAmount,
amount: takerAmount,
shares: takerShares,
isFilled: isMultiBuy
? floatingEqual(multiBuyTakerAmount, betAmount)
: floatingEqual(takerAmount, betAmount),
fills: takers,
contractId: contract.id,
outcome,
orderAmount: betAmount,
limitProb,
isCancelled: false,
amount,
loanAmount: 0,
shares,
answerId: answer.id,
fills: takers,
isFilled: isMultiBuy
? floatingEqual(multiBuyAmount, betAmount)
: floatingEqual(amount, betAmount),
probBefore: answer.prob,
probAfter,
createdTime: now,
Expand Down

0 comments on commit 5dbc839

Please sign in to comment.