diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
new file mode 100644
index 00000000..0d4dbd32
--- /dev/null
+++ b/.github/CONTRIBUTING.md
@@ -0,0 +1,27 @@
+# Manifold CLA
+
+**Manifold Markets Contributor License Agreement**
+
+(Thanks to [Beeminder](http://bmndr.co/cla) and [Discourse.org](https://cla-assistant.io/discourse/discourse) whose CLAs we modeled this on!)
+
+## Unofficial Summary
+
+- Manifold can use your contributions
+- Manifold can sell things involving your contributions
+- You’re legally able to agree to the above
+- You’re the one who created these contributions
+- Manifold decides what gets included in Manifold
+- Manifold does not promise any support
+
+## Official Agreement
+
+The document below clarifies the terms under which You (the copyright owner or legal entity authorized by the copyright owner), may make "The Contributions" (software, bug fixes, configuration changes, documentation, or any other materials) to "The Work" (Manifold Markets). This license protects You, "The Company" (Manifold Markets, Inc.) and licensees; it does not change your rights to use your own contributions for any other purpose.
+
+You and "The Company" (Manifold Markets, Inc.) agree:
+
+- You grant to "The Company" (Manifold Markets, Inc.) a non-exclusive, irrevocable, worldwide, royalty-free, sublicenseable, relicenseable, transferable license under all of Your relevant intellectual property rights, to use, copy, prepare derivative works of, distribute and publicly perform and display "The Contributions" on any licensing terms, including without limitation: (a) open source licenses like the GNU General Public (v2.0) license; and (b) binary, proprietary, or commercial licenses. Except for the licenses granted herein, You reserve all right, title, and interest in and to "The Contributions".
+- You grant to "The Company" a non-exclusive, irrevocable (except as stated in this section), worldwide, royalty-free, sublicenseable, transferable patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer "The Work", where such license applies only to those patent claims licensable by You that are necessarily infringed by Your Contribution(s) alone or by combination of Your Contribution(s) with "The Work" to which such Contribution(s) was submitted. If any entity institutes patent litigation against You or any other entity (including a cross-claim or counterclaim in a lawsuit) alleging that your Contribution, or "The Work" to which you have contributed, constitutes direct or contributory patent infringement, then any patent licenses granted to that entity under this Agreement for that Contribution or Work shall terminate as of the date such litigation is filed.
+- You are able to grant us these rights. You represent that You are legally entitled to grant the above license(s). If Your employer has rights to intellectual property that You create, You represent that You have received permission to make "The Contributions" on behalf of that employer, or that Your employer has waived such rights for "The Contributions".
+- "The Contributions" are your original work. You represent that "The Contributions" are Your original works of authorship, and to Your knowledge, no other person claims, or has the right to claim, any right in any invention or patent related to "The Contributions". You also represent that You are not legally obligated, whether by entering into an agreement or otherwise, in any way that conflicts with the terms of this license. For example, if you have signed an agreement requiring you to assign the intellectual property rights in "The Contributions" to an employer or customer, that would conflict with the terms of this license.
+- We, as authoritative representatives of "The Company" determine the code that is in "The Work". You understand that the decision to include "The Contribution(s)" in any project or source repository is entirely that of "The Company", and this agreement does not guarantee that "The Contributions" will be included in any product.
+- No Implied Warranties. "The Company" acknowledges that, except as explicitly described in this Agreement, the Contribution is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/README.md b/README.md
index 7416d3bd..b480f60c 100644
--- a/README.md
+++ b/README.md
@@ -25,8 +25,9 @@ Operations with complicated contracts (e.g. buying shares) are provided in a sep
- `functions/`: Firebase cloud functions, for secure work (e.g. balances, Stripe payments, emails). Also contains in
`functions/src/scripts/` some Typescript scripts that do ad hoc CLI interaction with Firebase.
-- `common/`: Typescript library code shared between `web/` & `functions/`. Also contains in `common/envs` configuration for
- the different environments (i.e. prod, dev, Manifold for Teams instances.)
+- `common/`: Typescript library code shared between `web/` & `functions/`. If you want to look at how the market math
+ works, most of that's in here (it gets called from the `placeBet` and `sellBet` endpoints in `functions/`.) Also
+ contains in `common/envs` configuration for the different environments (i.e. prod, dev, Manifold for Teams instances.)
- `og-image/`: The OpenGraph image generator; creates the preview images shown on Twitter/social media.
@@ -34,7 +35,11 @@ Also: Our docs are currently in [a separate repo](https://github.com/manifoldmar
## Contributing
-Since we are just now open-sourcing things, we will see how things go. Feel free to open issues, submit PRs, and chat about the process on Discord. We would prefer [small PRs][small-prs] that we can effectively evaluate and review -- maybe check in with us first if you are thinking to work on a big change.
+Since we are just now open-sourcing things, we will see how things go. Feel free to open issues, submit PRs, and chat about the process on [Discord][discord]. We would prefer [small PRs][small-prs] that we can effectively evaluate and review -- maybe check in with us first if you are thinking to work on a big change.
+
+By contributing to this codebase, you are agreeing to the terms of the [Manifold CLA](https://github.com/manifoldmarkets/manifold/blob/main/.github/CONTRIBUTING.md).
+
+If you need additional access to any infrastructure in order to work on something (e.g. Vercel, Firebase) let us know about that on Discord as well.
[vercel]: https://vercel.com/
[jamstack]: https://jamstack.org/
@@ -45,3 +50,4 @@ Since we are just now open-sourcing things, we will see how things go. Feel free
[cloud-firestore]: https://firebase.google.com/docs/firestore
[cloud-functions]: https://firebase.google.com/docs/functions
[small-prs]: https://google.github.io/eng-practices/review/developer/small-cls.html
+[discord]: https://discord.gg/eHQBNBqXuh
diff --git a/common/antes.ts b/common/antes.ts
index 9a3f48c6..c77308f4 100644
--- a/common/antes.ts
+++ b/common/antes.ts
@@ -5,14 +5,16 @@ import { User } from './user'
import { LiquidityProvision } from './liquidity-provision'
import { noFees } from './fees'
-export const FIXED_ANTE = 50
+export const FIXED_ANTE = 100
// deprecated
export const PHANTOM_ANTE = 0.001
export const MINIMUM_ANTE = 50
+export const HOUSE_LIQUIDITY_PROVIDER_ID = 'IPTOzEqrpkWmEzh6hwvAyY9PqFb2' // @ManifoldMarkets' id
+
export function getCpmmInitialLiquidity(
- creator: User,
+ providerId: string,
contract: FullContract,
anteId: string,
amount: number
@@ -21,7 +23,7 @@ export function getCpmmInitialLiquidity(
const lp: LiquidityProvision = {
id: anteId,
- userId: creator.id,
+ userId: providerId,
contractId: contract.id,
createdTime,
isAnte: true,
diff --git a/functions/README.md b/functions/README.md
index 5f24a217..7601b7c8 100644
--- a/functions/README.md
+++ b/functions/README.md
@@ -34,9 +34,10 @@ Adapted from https://firebase.google.com/docs/functions/get-started
## Developing locally
+0. `$ firebase use dev` if you haven't already
1. `$ yarn serve` to spin up the emulators
- The Emulator UI is at http://localhost:4000; the functions are hosted on :5001.
- Note: You have to kill and restart emulators when you change code; no hot reload =(
+ 1. The Emulator UI is at http://localhost:4000; the functions are hosted on :5001.
+ Note: You have to kill and restart emulators when you change code; no hot reload =(
2. `$ yarn dev:emulate` in `/web` to connect to emulators with the frontend
1. Note: emulated database is cleared after every shutdown
diff --git a/functions/src/create-contract.ts b/functions/src/create-contract.ts
index 16a416b1..ae7b0ad8 100644
--- a/functions/src/create-contract.ts
+++ b/functions/src/create-contract.ts
@@ -1,7 +1,6 @@
import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
import * as _ from 'lodash'
-
import { chargeUser, getUser } from './utils'
import {
Binary,
@@ -23,6 +22,7 @@ import {
getAnteBets,
getCpmmInitialLiquidity,
getFreeAnswerAnte,
+ HOUSE_LIQUIDITY_PROVIDER_ID,
MINIMUM_ANTE,
} from '../../common/antes'
import { getNoneAnswer } from '../../common/answer'
@@ -73,11 +73,19 @@ export const createContract = functions
return { status: 'error', message: 'Invalid initial probability' }
const ante = FIXED_ANTE // data.ante
+ // uses utc time on server:
+ const today = new Date().setHours(0, 0, 0, 0)
+ const userContractsCreatedTodaySnapshot = await firestore
+ .collection(`contracts`)
+ .where('creatorId', '==', userId)
+ .where('createdTime', '>=', today)
+ .get()
+ const isFree = userContractsCreatedTodaySnapshot.size === 0
if (
ante === undefined ||
ante < MINIMUM_ANTE ||
- ante > creator.balance ||
+ (ante > creator.balance && !isFree) ||
isNaN(ante) ||
!isFinite(ante)
)
@@ -109,7 +117,7 @@ export const createContract = functions
tags ?? []
)
- if (ante) await chargeUser(creator.id, ante)
+ if (!isFree && ante) await chargeUser(creator.id, ante)
await contractRef.create(contract)
@@ -137,8 +145,10 @@ export const createContract = functions
.collection(`contracts/${contract.id}/liquidity`)
.doc()
+ const providerId = isFree ? HOUSE_LIQUIDITY_PROVIDER_ID : creator.id
+
const lp = getCpmmInitialLiquidity(
- creator,
+ providerId,
contract as FullContract,
liquidityDoc.id,
ante
diff --git a/functions/src/emails.ts b/functions/src/emails.ts
index 290aaecb..c3b70734 100644
--- a/functions/src/emails.ts
+++ b/functions/src/emails.ts
@@ -48,8 +48,8 @@ export const sendMarketResolutionEmail = async (
creatorName: creator.name,
question: contract.question,
outcome,
- investment: `${Math.round(investment)}`,
- payout: `${Math.round(payout)}`,
+ investment: `${Math.floor(investment)}`,
+ payout: `${Math.floor(payout)}`,
url: `https://${DOMAIN}/${creator.username}/${contract.slug}`,
}
@@ -189,7 +189,9 @@ export const sendNewCommentEmail = async (
let betDescription = ''
if (bet) {
const { amount, sale } = bet
- betDescription = `${sale ? 'sold' : 'bought'} M$ ${Math.round(amount)}`
+ betDescription = `${sale || amount < 0 ? 'sold' : 'bought'} ${formatMoney(
+ Math.abs(amount)
+ )}`
}
const subject = `Comment on ${question}`
diff --git a/functions/src/scripts/migrate-to-cfmm.ts b/functions/src/scripts/migrate-to-cfmm.ts
index cd9177a3..874011ca 100644
--- a/functions/src/scripts/migrate-to-cfmm.ts
+++ b/functions/src/scripts/migrate-to-cfmm.ts
@@ -106,7 +106,7 @@ async function recalculateContract(contractRef: DocRef, isCommit = false) {
const liquidityDocRef = contractRef.collection('liquidity').doc()
const lp = getCpmmInitialLiquidity(
- { id: 'IPTOzEqrpkWmEzh6hwvAyY9PqFb2' } as User, // use @ManifoldMarkets' id
+ 'IPTOzEqrpkWmEzh6hwvAyY9PqFb2', // use @ManifoldMarkets' id
{
...contract,
...contractUpdate,
diff --git a/web/README.md b/web/README.md
index 8b3e65db..2bfd5056 100644
--- a/web/README.md
+++ b/web/README.md
@@ -2,13 +2,15 @@
## Getting started
-To run the development server, install [Yarn][yarn], and then in this directory:
+To run the development server, install [Yarn 1.x][yarn], and then in this directory:
1. `yarn` to install all dependencies
2. `yarn dev:dev` starts a development web server, pointing at the development database
3. Your site will be available on http://localhost:3000
-Check package.json for other command-line tasks. (e.g. `yarn dev` will point the development server at the prod database. `yarn emulate` will run against a local emulated database, if you are serving it via `yarn serve` from the [`functions/` package][functions-readme].)
+Check package.json for other command-line tasks. (e.g. `yarn dev` will point the development server at the prod
+database. `yarn emulate` will run against a local emulated database, if you are serving it via `yarn serve` from the
+[`functions/` package][functions-readme].)
## Tech stack
@@ -24,16 +26,17 @@ branch (to production) and PR branches (to ephemeral staging servers that can be
Parts of the file structure that directly map to HTTP endpoints are organized specially per Next.js's prescriptions:
-### /public
+### public/
These are static files that will be [served by Next verbatim][next-static-files].
-### /pages
+### pages/
These are components that [Next's router][next-pages] is aware of and interprets as page roots per their filename,
-e.g. the React component in pages/portfolio.tsx is rendered on the user portfolio page at /portfolio.
+e.g. the React component in pages/portfolio.tsx is rendered on the user portfolio page at /portfolio. You should
+look in here or in `components/` to find any specific piece of UI you are interested in working on.
-### /pages/api
+### pages/api/
Modules under this route are specially interpreted by Next/Vercel as [functions that will be hosted by
Vercel][vercel-functions]. This is where the public Manifold HTTP API lives.
@@ -52,7 +55,7 @@ integration][prettier-integrations] to format it in your editor.
[nextjs]: https://nextjs.org
[vercel]: https://vercel.com
[tailwind]: https://tailwindcss.com
-[yarn]: https://yarnpkg.com
+[yarn]: https://classic.yarnpkg.com/lang/en/docs/install/
[prettier]: https://prettier.io
[prettier-integrations]: https://prettier.io/docs/en/editors.html
[next-static-files]: https://nextjs.org/docs/basic-features/static-file-serving
diff --git a/web/components/contract/contracts-list.tsx b/web/components/contract/contracts-list.tsx
index 1850cf0b..dab8613d 100644
--- a/web/components/contract/contracts-list.tsx
+++ b/web/components/contract/contracts-list.tsx
@@ -18,6 +18,7 @@ import {
useQueryAndSortParams,
} from '../../hooks/use-sort-and-query-params'
import { Answer } from '../../../common/answer'
+import { LoadingIndicator } from '../loading-indicator'
export function ContractsGrid(props: {
contracts: Contract[]
@@ -25,15 +26,16 @@ export function ContractsGrid(props: {
showCloseTime?: boolean
}) {
const { showCloseTime } = props
+ const PAGE_SIZE = 100
+ const [page, setPage] = useState(1)
const [resolvedContracts, activeContracts] = _.partition(
props.contracts,
(c) => c.isResolved
)
- const contracts = [...activeContracts, ...resolvedContracts].slice(
- 0,
- MAX_CONTRACTS_DISPLAYED
- )
+ const allContracts = [...activeContracts, ...resolvedContracts]
+ const showMore = allContracts.length > PAGE_SIZE * page
+ const contracts = allContracts.slice(0, PAGE_SIZE * page)
if (contracts.length === 0) {
return (
@@ -47,16 +49,27 @@ export function ContractsGrid(props: {
}
return (
-
- {contracts.map((contract) => (
-
- ))}
-
+ <>
+
+ {contracts.map((contract) => (
+
+ ))}
+
+ {/* Show a link that increases the page num when clicked */}
+ {showMore && (
+
+ )}
+ >
)
}
@@ -201,7 +214,7 @@ function TagContractsGrid(props: { contracts: Contract[] }) {
const MAX_CONTRACTS_DISPLAYED = 99
export function SearchableGrid(props: {
- contracts: Contract[]
+ contracts: Contract[] | undefined
byOneCreator?: boolean
querySortOptions?: {
defaultSort: Sort
@@ -218,7 +231,7 @@ export function SearchableGrid(props: {
return queryWords.every((word) => corpus.toLowerCase().includes(word))
}
- let matches = contracts.filter(
+ let matches = (contracts ?? []).filter(
(c) =>
check(c.question) ||
check(c.description) ||
@@ -312,7 +325,9 @@ export function SearchableGrid(props: {
- {sort === 'tag' ? (
+ {contracts === undefined ? (
+
+ ) : sort === 'tag' ? (
) : !byOneCreator && sort === 'creator' ? (
diff --git a/web/components/feed-create.tsx b/web/components/feed-create.tsx
index d184e035..0a0c6902 100644
--- a/web/components/feed-create.tsx
+++ b/web/components/feed-create.tsx
@@ -141,7 +141,7 @@ export default function FeedCreate(props: {
{/* Show a fake "Create Market" button, which gets replaced with the NewContract one*/}
{!isExpanded && (