Skip to content

Commit

Permalink
Loans: don't consider avg invested. Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jahooma committed Sep 11, 2023
1 parent 524266d commit 0c57378
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 33 deletions.
27 changes: 1 addition & 26 deletions common/src/calculate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function getDpmInvested(yourBets: Bet[]) {
})
}

function getSimpleCpmmInvested(yourBets: Bet[]) {
export function getSimpleCpmmInvested(yourBets: Bet[]) {
const total = sumBy(yourBets, (b) => b.amount)
if (total < 0) return 0
return total
Expand All @@ -274,31 +274,6 @@ export function getInvested(contract: Contract, yourBets: Bet[]) {
return getDpmInvested(yourBets)
}

/**
* Take the minimum of the average cost basis and the simple cost basis (sum of bet amounts).
*/
export function getMinimalInvested(contract: Contract, yourBets: Bet[]) {
const { mechanism } = contract
if (mechanism === 'cpmm-1') {
const costBasisAvg = getCpmmInvested(yourBets)
const simpleCostBasis = getSimpleCpmmInvested(yourBets)
return Math.min(costBasisAvg, simpleCostBasis)
}
if (mechanism === 'cpmm-multi-1') {
const betsByAnswerId = groupBy(yourBets, 'answerId')
const investedByAnswerId = mapValues(betsByAnswerId, getCpmmInvested)
const costBasisAvg = sum(Object.values(investedByAnswerId))

const simpleInvestedByAnswerId = mapValues(
betsByAnswerId,
getSimpleCpmmInvested
)
const simpleCostBasis = sum(Object.values(simpleInvestedByAnswerId))
return Math.min(costBasisAvg, simpleCostBasis)
}
return getDpmInvested(yourBets)
}

function getCpmmOrDpmProfit(contract: Contract, yourBets: Bet[]) {
const { resolution } = contract

Expand Down
6 changes: 3 additions & 3 deletions common/src/loans.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Dictionary, sumBy, minBy, groupBy } from 'lodash'
import { Bet } from './bet'
import { getMinimalInvested, getProfitMetrics } from './calculate'
import { getProfitMetrics, getSimpleCpmmInvested } from './calculate'
import {
Contract,
CPMMContract,
Expand Down Expand Up @@ -67,13 +67,13 @@ const getCpmmContractLoanUpdate = (
contract: CPMMContract | CPMMMultiContract,
bets: Bet[]
) => {
const invested = getMinimalInvested(contract, bets)
const invested = getSimpleCpmmInvested(bets)
const { payout: currentValue } = getProfitMetrics(contract, bets)
const loanAmount = sumBy(bets, (bet) => bet.loanAmount ?? 0)
const oldestBet = minBy(bets, (bet) => bet.createdTime)

const loanBasis = Math.min(invested, currentValue)
const newLoan = calculateNewLoan(loanBasis, loanAmount)
const oldestBet = minBy(bets, (bet) => bet.createdTime)
if (!isFinite(newLoan) || newLoan <= 0 || !oldestBet) return undefined

const loanTotal = (oldestBet.loanAmount ?? 0) + newLoan
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ The liquidity in a market is the amount of capital available for traders to trad

### What are loans?

Every day at midnight PT, get 2% of your total bet amount back as a loan. You can see how much your next loan is worth on the top right of your profile page.
Every day at midnight PT, get 4% of your total bet amount back as a loan. If your bet has depreciated in value, you will get 4% of the lower value. You can see how much your last loan was by navigating to your Notifications and then Balance changes tab.

- **Do I have to pay back a loan?**
Yes, but don't worry! You will automatically pay back loans when the market resolves or you sell your bet. If this causes your balance to go negative then you will have to free up some mana before you can start trading again.
Expand All @@ -291,8 +291,8 @@ Every day at midnight PT, get 2% of your total bet amount back as a loan. You ca
It's possible, but very rare.

- **What is an example?**
If you bet M1000 on "Will I become a millionaire?" today, you will get M20 back tomorrow.
Previous loans count against your total bet amount. So on the next day, you would get back 2% of M(1000 - 20) = M19.6.
If you bet M1000 on "Will I become a millionaire?" today, you will get M40 back tomorrow.
Previous loans count against your total bet amount. So on the next day, you would get back 4% of M(1000 - 40) = M38.4.

## Misc

Expand Down
3 changes: 2 additions & 1 deletion web/components/profile/loans-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export function LoansModal(props: {
<span className={'text-primary-700'}>• What are daily loans?</span>
<span className={'ml-2'}>
Every day at midnight PT, get {LOAN_DAILY_RATE * 100}% of your total
bet amount back as a loan.
bet amount back as a loan. If your bet has depreciated in value, you
will get {LOAN_DAILY_RATE * 100}% of the lower value.
</span>
<span className={'text-primary-700'}>
• Do I have to pay back a loan?
Expand Down

3 comments on commit 0c57378

@vercel
Copy link

@vercel vercel bot commented on 0c57378 Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs-mantic.vercel.app
docs-pi-teal.vercel.app
docs.manifold.markets
docs-git-main-mantic.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 0c57378 Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 0c57378 Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

dev – ./web

dev-mantic.vercel.app
dev-git-main-mantic.vercel.app
dev-manifold.vercel.app
dev.manifold.markets

Please sign in to comment.