2022-04-21 17:58:12 +00:00
|
|
|
import { addCpmmLiquidity, getCpmmLiquidity } from './calculate-cpmm'
|
2022-06-01 02:42:35 +00:00
|
|
|
import { CPMMContract } from './contract'
|
2022-04-21 17:58:12 +00:00
|
|
|
import { LiquidityProvision } from './liquidity-provision'
|
|
|
|
|
|
|
|
export const getNewLiquidityProvision = (
|
2022-09-14 05:26:47 +00:00
|
|
|
userId: string,
|
2022-04-21 17:58:12 +00:00
|
|
|
amount: number,
|
2022-06-01 02:42:35 +00:00
|
|
|
contract: CPMMContract,
|
2022-04-21 17:58:12 +00:00
|
|
|
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,
|
2022-09-14 05:26:47 +00:00
|
|
|
userId: userId,
|
2022-04-21 17:58:12 +00:00
|
|
|
contractId: contract.id,
|
|
|
|
amount,
|
|
|
|
pool: newPool,
|
|
|
|
p: newP,
|
|
|
|
liquidity,
|
|
|
|
createdTime: Date.now(),
|
|
|
|
}
|
|
|
|
|
|
|
|
const newTotalLiquidity = (totalLiquidity ?? 0) + amount
|
|
|
|
|
2022-05-10 13:49:14 +00:00
|
|
|
return { newLiquidityProvision, newPool, newP, newTotalLiquidity }
|
2022-04-21 17:58:12 +00:00
|
|
|
}
|