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