Skip to content

Commit

Permalink
Revert limit again
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Jul 9, 2024
1 parent e82c1ef commit c466a6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
9 changes: 1 addition & 8 deletions common/src/calculate-cpmm-arbitrage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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 @@ -19,17 +18,11 @@ export function calculateCpmmMultiArbitrageBet(
answerToBuy: Answer,
outcome: 'YES' | 'NO',
betAmount: number,
initialLimitProb: number | undefined,
limitProb: 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: 14 additions & 22 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',
initialBetAmount: number,
betAmount: number,
limitProb: number | undefined,
unfilledBets: LimitBet[],
balanceByUserId: { [userId: string]: number },
Expand All @@ -512,24 +512,21 @@ const getNewMultiCpmmBetsInfoSumsToOne = (
answers,
answersToBuy[0],
outcome,
initialBetAmount,
betAmount,
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 {
// NOTE: only accepts YES bets atm
// TODO: only accepts YES bets atm
const multiRes = calculateCpmmMultiArbitrageYesBets(
answers,
answersToBuy,
initialBetAmount,
betAmount,
limitProb,
unfilledBets,
balanceByUserId,
Expand All @@ -542,33 +539,28 @@ const getNewMultiCpmmBetsInfoSumsToOne = (
return newBetResults.map((newBetResult, i) => {
const { takers, cpmmState, answer: updatedAnswer, totalFees } = newBetResult
const probAfter = getCpmmProbability(cpmmState.pool, cpmmState.p)
const takerAmount = sumBy(takers, 'amount')
const takerShares = sumBy(takers, 'shares')
const amount = sumBy(takers, 'amount')
const shares = sumBy(takers, 'shares')
const answer = answers.find((a) => a.id === updatedAnswer.id) as Answer
const multiBuyTakerAmount = sumBy(
const multiBuyAmount = 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 c466a6b

Please sign in to comment.