liquidity provision tracking
This commit is contained in:
parent
0a28ea52b6
commit
f8db70f89b
|
@ -1,6 +1,5 @@
|
||||||
import { Bet } from './bet'
|
import { Bet } from './bet'
|
||||||
import { getDpmProbability } from './calculate-dpm'
|
import { getDpmProbability } from './calculate-dpm'
|
||||||
import { getCpmmProbability } from './calculate-cpmm'
|
|
||||||
import { Binary, CPMM, DPM, FreeResponse, FullContract } from './contract'
|
import { Binary, CPMM, DPM, FreeResponse, FullContract } from './contract'
|
||||||
import { User } from './user'
|
import { User } from './user'
|
||||||
import { LiquidityProvision } from './liquidity-provision'
|
import { LiquidityProvision } from './liquidity-provision'
|
||||||
|
@ -15,7 +14,7 @@ export function getCpmmInitialLiquidity(
|
||||||
anteId: string,
|
anteId: string,
|
||||||
amount: number
|
amount: number
|
||||||
) {
|
) {
|
||||||
const { createdTime, pool, p } = contract
|
const { createdTime, p } = contract
|
||||||
|
|
||||||
const lp: LiquidityProvision = {
|
const lp: LiquidityProvision = {
|
||||||
id: anteId,
|
id: anteId,
|
||||||
|
@ -26,7 +25,8 @@ export function getCpmmInitialLiquidity(
|
||||||
|
|
||||||
amount: amount,
|
amount: amount,
|
||||||
liquidity: amount,
|
liquidity: amount,
|
||||||
probability: getCpmmProbability(pool, p),
|
p: p,
|
||||||
|
pool: { YES: 0, NO: 0 },
|
||||||
}
|
}
|
||||||
|
|
||||||
return lp
|
return lp
|
||||||
|
|
|
@ -110,7 +110,6 @@ export function calculateCpmmPurchase(
|
||||||
const postBetPool = { YES: newY, NO: newN }
|
const postBetPool = { YES: newY, NO: newN }
|
||||||
|
|
||||||
const { newPool, newP } = addCpmmLiquidity(postBetPool, p, fee)
|
const { newPool, newP } = addCpmmLiquidity(postBetPool, p, fee)
|
||||||
// console.log(fee, getCpmmLiquidity(pool, p), getCpmmLiquidity(newPool, newP))
|
|
||||||
|
|
||||||
return { shares, newPool, newP, fees }
|
return { shares, newPool, newP, fees }
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,9 @@ export type DPM = {
|
||||||
|
|
||||||
export type CPMM = {
|
export type CPMM = {
|
||||||
mechanism: 'cpmm-1'
|
mechanism: 'cpmm-1'
|
||||||
p: number // probability constant in y^(1-p) * n^p = k
|
|
||||||
pool: { [outcome: string]: number }
|
pool: { [outcome: string]: number }
|
||||||
|
p: number // probability constant in y^p * n^(1-p) = k
|
||||||
|
totalLiquidity: number // in M$
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FixedPayouts = CPMM
|
export type FixedPayouts = CPMM
|
||||||
|
|
|
@ -2,11 +2,12 @@ export type LiquidityProvision = {
|
||||||
id: string
|
id: string
|
||||||
userId: string
|
userId: string
|
||||||
contractId: string
|
contractId: string
|
||||||
|
|
||||||
createdTime: number
|
createdTime: number
|
||||||
isAnte?: boolean
|
isAnte?: boolean
|
||||||
|
|
||||||
amount: number // M$ quantity
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ export const getNewBinaryCpmmBetInfo = (
|
||||||
|
|
||||||
const newBalance = user.balance - (amount - loanAmount)
|
const newBalance = user.balance - (amount - loanAmount)
|
||||||
|
|
||||||
const { pool, p } = contract
|
const { pool, p, totalLiquidity } = contract
|
||||||
const probBefore = getCpmmProbability(pool, p)
|
const probBefore = getCpmmProbability(pool, p)
|
||||||
const probAfter = getCpmmProbability(newPool, newP)
|
const probAfter = getCpmmProbability(newPool, newP)
|
||||||
|
|
||||||
|
@ -52,7 +52,10 @@ export const getNewBinaryCpmmBetInfo = (
|
||||||
createdTime: Date.now(),
|
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 = (
|
export const getNewBinaryDpmBetInfo = (
|
||||||
|
|
|
@ -91,6 +91,7 @@ const getBinaryCpmmProps = (initialProb: number, ante: number) => {
|
||||||
const system: CPMM & Binary = {
|
const system: CPMM & Binary = {
|
||||||
mechanism: 'cpmm-1',
|
mechanism: 'cpmm-1',
|
||||||
outcomeType: 'BINARY',
|
outcomeType: 'BINARY',
|
||||||
|
totalLiquidity: ante,
|
||||||
initialProbability: p,
|
initialProbability: p,
|
||||||
p,
|
p,
|
||||||
pool: pool,
|
pool: pool,
|
||||||
|
|
|
@ -80,6 +80,7 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
newTotalShares,
|
newTotalShares,
|
||||||
newTotalBets,
|
newTotalBets,
|
||||||
newBalance,
|
newBalance,
|
||||||
|
newTotalLiquidity,
|
||||||
fees,
|
fees,
|
||||||
newP,
|
newP,
|
||||||
} =
|
} =
|
||||||
|
@ -126,6 +127,7 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
p: newP,
|
p: newP,
|
||||||
totalShares: newTotalShares,
|
totalShares: newTotalShares,
|
||||||
totalBets: newTotalBets,
|
totalBets: newTotalBets,
|
||||||
|
totalLiquidity: newTotalLiquidity,
|
||||||
collectedFees: addObjects<Fees>(fees ?? {}, collectedFees ?? {}),
|
collectedFees: addObjects<Fees>(fees ?? {}, collectedFees ?? {}),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
|
@ -43,7 +43,9 @@ export function contractMetrics(contract: Contract) {
|
||||||
const liquidityLabel =
|
const liquidityLabel =
|
||||||
contract.mechanism === 'dpm-2'
|
contract.mechanism === 'dpm-2'
|
||||||
? `${formatMoney(truePool)} pool`
|
? `${formatMoney(truePool)} pool`
|
||||||
: `${formatMoney(getCpmmLiquidity(pool, contract.p))} liquidity`
|
: `${formatMoney(
|
||||||
|
contract.totalLiquidity ?? getCpmmLiquidity(pool, contract.p)
|
||||||
|
)} liquidity`
|
||||||
|
|
||||||
return { truePool, liquidityLabel, createdDate, resolvedDate }
|
return { truePool, liquidityLabel, createdDate, resolvedDate }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user