liquidity provision tracking

This commit is contained in:
mantikoros 2022-03-14 22:26:04 -05:00
parent 0a28ea52b6
commit f8db70f89b
8 changed files with 20 additions and 11 deletions

View File

@ -1,6 +1,5 @@
import { Bet } from './bet'
import { getDpmProbability } from './calculate-dpm'
import { getCpmmProbability } from './calculate-cpmm'
import { Binary, CPMM, DPM, FreeResponse, FullContract } from './contract'
import { User } from './user'
import { LiquidityProvision } from './liquidity-provision'
@ -15,7 +14,7 @@ export function getCpmmInitialLiquidity(
anteId: string,
amount: number
) {
const { createdTime, pool, p } = contract
const { createdTime, p } = contract
const lp: LiquidityProvision = {
id: anteId,
@ -26,7 +25,8 @@ export function getCpmmInitialLiquidity(
amount: amount,
liquidity: amount,
probability: getCpmmProbability(pool, p),
p: p,
pool: { YES: 0, NO: 0 },
}
return lp

View File

@ -110,7 +110,6 @@ export function calculateCpmmPurchase(
const postBetPool = { YES: newY, NO: newN }
const { newPool, newP } = addCpmmLiquidity(postBetPool, p, fee)
// console.log(fee, getCpmmLiquidity(pool, p), getCpmmLiquidity(newPool, newP))
return { shares, newPool, newP, fees }
}

View File

@ -49,8 +49,9 @@ export type DPM = {
export type CPMM = {
mechanism: 'cpmm-1'
p: number // probability constant in y^(1-p) * n^p = k
pool: { [outcome: string]: number }
p: number // probability constant in y^p * n^(1-p) = k
totalLiquidity: number // in M$
}
export type FixedPayouts = CPMM

View File

@ -2,11 +2,12 @@ export type LiquidityProvision = {
id: string
userId: string
contractId: string
createdTime: number
isAnte?: boolean
amount: number // M$ quantity
liquidity: number // sqrt(k)
probability: number
pool: { [outcome: string]: number } // pool shares before provision
liquidity: number // change in constant k after provision
p: number // p constant after provision
}

View File

@ -34,7 +34,7 @@ export const getNewBinaryCpmmBetInfo = (
const newBalance = user.balance - (amount - loanAmount)
const { pool, p } = contract
const { pool, p, totalLiquidity } = contract
const probBefore = getCpmmProbability(pool, p)
const probAfter = getCpmmProbability(newPool, newP)
@ -52,7 +52,10 @@ export const getNewBinaryCpmmBetInfo = (
createdTime: Date.now(),
}
return { newBet, newPool, newP, newBalance, fees }
const { liquidityFee } = fees
const newTotalLiquidity = (totalLiquidity ?? 0) + liquidityFee
return { newBet, newPool, newP, newBalance, newTotalLiquidity, fees }
}
export const getNewBinaryDpmBetInfo = (

View File

@ -91,6 +91,7 @@ const getBinaryCpmmProps = (initialProb: number, ante: number) => {
const system: CPMM & Binary = {
mechanism: 'cpmm-1',
outcomeType: 'BINARY',
totalLiquidity: ante,
initialProbability: p,
p,
pool: pool,

View File

@ -80,6 +80,7 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall(
newTotalShares,
newTotalBets,
newBalance,
newTotalLiquidity,
fees,
newP,
} =
@ -126,6 +127,7 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall(
p: newP,
totalShares: newTotalShares,
totalBets: newTotalBets,
totalLiquidity: newTotalLiquidity,
collectedFees: addObjects<Fees>(fees ?? {}, collectedFees ?? {}),
})
)

View File

@ -43,7 +43,9 @@ export function contractMetrics(contract: Contract) {
const liquidityLabel =
contract.mechanism === 'dpm-2'
? `${formatMoney(truePool)} pool`
: `${formatMoney(getCpmmLiquidity(pool, contract.p))} liquidity`
: `${formatMoney(
contract.totalLiquidity ?? getCpmmLiquidity(pool, contract.p)
)} liquidity`
return { truePool, liquidityLabel, createdDate, resolvedDate }
}