Fix sell to pay back loans
This commit is contained in:
parent
75e48204ef
commit
ce76a9754b
|
@ -88,6 +88,7 @@ export const getCpmmSellBetInfo = (
|
|||
shares: number,
|
||||
outcome: 'YES' | 'NO',
|
||||
contract: FullContract<CPMM, Binary>,
|
||||
prevLoanAmount: number,
|
||||
newBetId: string
|
||||
) => {
|
||||
const { pool, p } = contract
|
||||
|
@ -98,6 +99,9 @@ export const getCpmmSellBetInfo = (
|
|||
outcome
|
||||
)
|
||||
|
||||
const loanPaid = Math.min(prevLoanAmount, saleValue)
|
||||
const netAmount = saleValue - loanPaid
|
||||
|
||||
const probBefore = getCpmmProbability(pool, p)
|
||||
const probAfter = getCpmmProbability(newPool, p)
|
||||
|
||||
|
@ -121,10 +125,11 @@ export const getCpmmSellBetInfo = (
|
|||
probBefore,
|
||||
probAfter,
|
||||
createdTime: Date.now(),
|
||||
loanAmount: -loanPaid,
|
||||
fees,
|
||||
}
|
||||
|
||||
const newBalance = user.balance + saleValue
|
||||
const newBalance = user.balance + netAmount
|
||||
|
||||
return {
|
||||
newBet,
|
||||
|
|
|
@ -51,6 +51,8 @@ export const sellShares = functions.runWith({ minInstances: 1 }).https.onCall(
|
|||
contractDoc.collection('bets').where('userId', '==', userId)
|
||||
)
|
||||
|
||||
const prevLoanAmount = _.sumBy(userBets, (bet) => bet.loanAmount ?? 0)
|
||||
|
||||
const [yesBets, noBets] = _.partition(
|
||||
userBets ?? [],
|
||||
(bet) => bet.outcome === 'YES'
|
||||
|
@ -77,6 +79,7 @@ export const sellShares = functions.runWith({ minInstances: 1 }).https.onCall(
|
|||
shares,
|
||||
outcome,
|
||||
contract,
|
||||
prevLoanAmount,
|
||||
newBetDoc.id
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user