2022-06-10 22:48:28 +00:00
|
|
|
import * as functions from 'firebase-functions'
|
2022-08-25 11:51:56 +00:00
|
|
|
import { getContract, getUser, log } from './utils'
|
2022-10-11 16:22:38 +00:00
|
|
|
import { createFollowOrMarketSubsidizedNotification } from './create-notification'
|
2022-08-25 11:51:56 +00:00
|
|
|
import { LiquidityProvision } from '../../common/liquidity-provision'
|
2022-08-24 16:49:53 +00:00
|
|
|
import { addUserToContractFollowers } from './follow-market'
|
2022-08-25 11:51:56 +00:00
|
|
|
import { FIXED_ANTE } from '../../common/economy'
|
|
|
|
import {
|
|
|
|
DEV_HOUSE_LIQUIDITY_PROVIDER_ID,
|
|
|
|
HOUSE_LIQUIDITY_PROVIDER_ID,
|
2022-09-14 05:26:47 +00:00
|
|
|
UNIQUE_BETTOR_LIQUIDITY_AMOUNT,
|
2022-08-25 11:51:56 +00:00
|
|
|
} from '../../common/antes'
|
2022-06-10 22:48:28 +00:00
|
|
|
|
|
|
|
export const onCreateLiquidityProvision = functions.firestore
|
|
|
|
.document('contracts/{contractId}/liquidity/{liquidityId}')
|
|
|
|
.onCreate(async (change, context) => {
|
|
|
|
const liquidity = change.data() as LiquidityProvision
|
|
|
|
const { eventId } = context
|
|
|
|
|
2022-06-10 23:23:17 +00:00
|
|
|
// Ignore Manifold Markets liquidity for now - users see a notification for free market liquidity provision
|
2022-08-25 11:51:56 +00:00
|
|
|
if (
|
2022-09-14 05:26:47 +00:00
|
|
|
liquidity.isAnte ||
|
|
|
|
((liquidity.userId === HOUSE_LIQUIDITY_PROVIDER_ID ||
|
2022-08-25 11:51:56 +00:00
|
|
|
liquidity.userId === DEV_HOUSE_LIQUIDITY_PROVIDER_ID) &&
|
2022-09-14 05:26:47 +00:00
|
|
|
(liquidity.amount === FIXED_ANTE ||
|
|
|
|
liquidity.amount === UNIQUE_BETTOR_LIQUIDITY_AMOUNT))
|
2022-08-25 11:51:56 +00:00
|
|
|
)
|
|
|
|
return
|
|
|
|
|
|
|
|
log(`onCreateLiquidityProvision: ${JSON.stringify(liquidity)}`)
|
2022-06-10 23:23:17 +00:00
|
|
|
|
2022-07-24 07:45:45 +00:00
|
|
|
const contract = await getContract(liquidity.contractId)
|
|
|
|
if (!contract)
|
|
|
|
throw new Error('Could not find contract corresponding with liquidity')
|
|
|
|
|
2022-06-10 22:48:28 +00:00
|
|
|
const liquidityProvider = await getUser(liquidity.userId)
|
|
|
|
if (!liquidityProvider) throw new Error('Could not find liquidity provider')
|
2022-08-24 16:49:53 +00:00
|
|
|
await addUserToContractFollowers(contract.id, liquidityProvider.id)
|
2022-06-10 22:48:28 +00:00
|
|
|
|
2022-10-11 16:22:38 +00:00
|
|
|
await createFollowOrMarketSubsidizedNotification(
|
2022-06-10 22:48:28 +00:00
|
|
|
contract.id,
|
|
|
|
'liquidity',
|
|
|
|
'created',
|
|
|
|
liquidityProvider,
|
|
|
|
eventId,
|
|
|
|
liquidity.amount.toString(),
|
2022-07-22 00:08:09 +00:00
|
|
|
{ contract }
|
2022-06-10 22:48:28 +00:00
|
|
|
)
|
|
|
|
})
|