2022-10-11 02:56:16 +00:00
|
|
|
import { 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
|
|
|
|
) => {
|
2022-10-11 02:56:16 +00:00
|
|
|
const { pool, p, totalLiquidity, subsidyPool } = contract
|
2022-04-21 17:58:12 +00:00
|
|
|
|
2022-10-11 02:56:16 +00:00
|
|
|
const liquidity = getCpmmLiquidity(pool, p)
|
2022-04-21 17:58:12 +00:00
|
|
|
|
|
|
|
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,
|
2022-10-11 02:56:16 +00:00
|
|
|
pool,
|
|
|
|
p,
|
2022-04-21 17:58:12 +00:00
|
|
|
liquidity,
|
|
|
|
createdTime: Date.now(),
|
|
|
|
}
|
|
|
|
|
|
|
|
const newTotalLiquidity = (totalLiquidity ?? 0) + amount
|
2022-10-11 02:56:16 +00:00
|
|
|
const newSubsidyPool = (subsidyPool ?? 0) + amount
|
2022-04-21 17:58:12 +00:00
|
|
|
|
2022-10-11 02:56:16 +00:00
|
|
|
return { newLiquidityProvision, newTotalLiquidity, newSubsidyPool }
|
2022-04-21 17:58:12 +00:00
|
|
|
}
|