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
This commit is contained in:
		
							parent
							
								
									067fb34973
								
							
						
					
					
						commit
						264e5058ea
					
				| 
						 | 
				
			
			@ -29,7 +29,5 @@ export const getNewLiquidityProvision = (
 | 
			
		|||
 | 
			
		||||
  const newTotalLiquidity = (totalLiquidity ?? 0) + amount
 | 
			
		||||
 | 
			
		||||
  const newBalance = user.balance - amount
 | 
			
		||||
 | 
			
		||||
  return { newLiquidityProvision, newPool, newP, newBalance, newTotalLiquidity }
 | 
			
		||||
  return { newLiquidityProvision, newPool, newP, newTotalLiquidity }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -54,13 +54,8 @@ export const addLiquidity = functions.runWith({ minInstances: 1 }).https.onCall(
 | 
			
		|||
          .collection(`contracts/${contractId}/liquidity`)
 | 
			
		||||
          .doc()
 | 
			
		||||
 | 
			
		||||
        const {
 | 
			
		||||
          newLiquidityProvision,
 | 
			
		||||
          newPool,
 | 
			
		||||
          newP,
 | 
			
		||||
          newBalance,
 | 
			
		||||
          newTotalLiquidity,
 | 
			
		||||
        } = getNewLiquidityProvision(
 | 
			
		||||
        const { newLiquidityProvision, newPool, newP, newTotalLiquidity } =
 | 
			
		||||
          getNewLiquidityProvision(
 | 
			
		||||
            user,
 | 
			
		||||
            amount,
 | 
			
		||||
            contract,
 | 
			
		||||
| 
						 | 
				
			
			@ -83,11 +78,17 @@ export const addLiquidity = functions.runWith({ minInstances: 1 }).https.onCall(
 | 
			
		|||
          })
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        const newBalance = user.balance - amount
 | 
			
		||||
        const newTotalDeposits = user.totalDeposits - amount
 | 
			
		||||
 | 
			
		||||
        if (!isFinite(newBalance)) {
 | 
			
		||||
          throw new Error('Invalid user balance for ' + user.username)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        transaction.update(userDoc, { balance: newBalance })
 | 
			
		||||
        transaction.update(userDoc, {
 | 
			
		||||
          balance: newBalance,
 | 
			
		||||
          totalDeposits: newTotalDeposits,
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        transaction.create(newLiquidityProvisionDoc, newLiquidityProvision)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@ export const sendMarketResolutionEmail = async (
 | 
			
		|||
  investment: number,
 | 
			
		||||
  payout: number,
 | 
			
		||||
  creator: User,
 | 
			
		||||
  creatorPayout: number,
 | 
			
		||||
  contract: Contract,
 | 
			
		||||
  resolution: string,
 | 
			
		||||
  resolutionProbability?: number,
 | 
			
		||||
| 
						 | 
				
			
			@ -42,6 +43,11 @@ export const sendMarketResolutionEmail = async (
 | 
			
		|||
 | 
			
		||||
  const subject = `Resolved ${outcome}: ${contract.question}`
 | 
			
		||||
 | 
			
		||||
  const creatorPayoutText =
 | 
			
		||||
    userId === creator.id
 | 
			
		||||
      ? ` (plus ${formatMoney(creatorPayout)} in commissions)`
 | 
			
		||||
      : ''
 | 
			
		||||
 | 
			
		||||
  const templateData: market_resolved_template = {
 | 
			
		||||
    userId: user.id,
 | 
			
		||||
    name: user.name,
 | 
			
		||||
| 
						 | 
				
			
			@ -49,7 +55,7 @@ export const sendMarketResolutionEmail = async (
 | 
			
		|||
    question: contract.question,
 | 
			
		||||
    outcome,
 | 
			
		||||
    investment: `${Math.floor(investment)}`,
 | 
			
		||||
    payout: `${Math.floor(payout)}`,
 | 
			
		||||
    payout: `${Math.floor(payout)}${creatorPayoutText}`,
 | 
			
		||||
    url: `https://${DOMAIN}/${creator.username}/${contract.slug}`,
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -146,6 +146,7 @@ export const resolveMarket = functions
 | 
			
		|||
        openBets,
 | 
			
		||||
        userPayoutsWithoutLoans,
 | 
			
		||||
        creator,
 | 
			
		||||
        creatorPayout,
 | 
			
		||||
        contract,
 | 
			
		||||
        outcome,
 | 
			
		||||
        resolutionProbability,
 | 
			
		||||
| 
						 | 
				
			
			@ -172,6 +173,7 @@ const sendResolutionEmails = async (
 | 
			
		|||
  openBets: Bet[],
 | 
			
		||||
  userPayouts: { [userId: string]: number },
 | 
			
		||||
  creator: User,
 | 
			
		||||
  creatorPayout: number,
 | 
			
		||||
  contract: Contract,
 | 
			
		||||
  outcome: string,
 | 
			
		||||
  resolutionProbability?: number,
 | 
			
		||||
| 
						 | 
				
			
			@ -201,6 +203,7 @@ const sendResolutionEmails = async (
 | 
			
		|||
        investment,
 | 
			
		||||
        payout,
 | 
			
		||||
        creator,
 | 
			
		||||
        creatorPayout,
 | 
			
		||||
        contract,
 | 
			
		||||
        outcome,
 | 
			
		||||
        resolutionProbability,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -241,9 +241,11 @@ export function NewContract(props: { question: string; tag?: string }) {
 | 
			
		|||
      <div className="form-control mb-1 items-start">
 | 
			
		||||
        <label className="label mb-1 gap-2">
 | 
			
		||||
          <span>Cost</span>
 | 
			
		||||
          {!deservesDailyFreeMarket && (
 | 
			
		||||
            <InfoTooltip
 | 
			
		||||
              text={`Cost to create your market. This amount is used to subsidize trading.`}
 | 
			
		||||
            />
 | 
			
		||||
          )}
 | 
			
		||||
        </label>
 | 
			
		||||
        {deservesDailyFreeMarket ? (
 | 
			
		||||
          <div className="label-text text-primary pl-1">FREE</div>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user