manifold/common/add-liquidity.ts
mantikoros 264e5058ea
Separate out fees (#169)
* deduct market ante from profits

* display creator fees in stats

* show creator earnings in stats

* separate out creator, liquidity fees in payouts and deduct from profits

* include creator payout in resolution emails

* deduct liquidity from profits

* hide cost tooltip if daily free market
2022-05-10 08:49:14 -05:00

34 lines
931 B
TypeScript

import { addCpmmLiquidity, getCpmmLiquidity } from './calculate-cpmm'
import { Binary, CPMM, FullContract } from './contract'
import { LiquidityProvision } from './liquidity-provision'
import { User } from './user'
export const getNewLiquidityProvision = (
user: User,
amount: number,
contract: FullContract<CPMM, Binary>,
newLiquidityProvisionId: string
) => {
const { pool, p, totalLiquidity } = contract
const { newPool, newP } = addCpmmLiquidity(pool, p, amount)
const liquidity =
getCpmmLiquidity(newPool, newP) - getCpmmLiquidity(pool, newP)
const newLiquidityProvision: LiquidityProvision = {
id: newLiquidityProvisionId,
userId: user.id,
contractId: contract.id,
amount,
pool: newPool,
p: newP,
liquidity,
createdTime: Date.now(),
}
const newTotalLiquidity = (totalLiquidity ?? 0) + amount
return { newLiquidityProvision, newPool, newP, newTotalLiquidity }
}